当前位置: 首页>>代码示例>>Python>>正文


Python Server.view方法代码示例

本文整理汇总了Python中couchdbkit.Server.view方法的典型用法代码示例。如果您正苦于以下问题:Python Server.view方法的具体用法?Python Server.view怎么用?Python Server.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchdbkit.Server的用法示例。


在下文中一共展示了Server.view方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: removeProc

# 需要导入模块: from couchdbkit import Server [as 别名]
# 或者: from couchdbkit.Server import view [as 别名]
def removeProc(server, databaseName, procname, **kwargs):
  '''
    This script will remove a "procname" key from database run document 
    and set the doc['status'] = 'good'. If "procname" == "proc0", then 
    doc['status'] will be set to 'closed' 


    You need to set the following arguments: 
    procname = the name of the "procname" object that will be removed  
    from the database documents (proc0, proc1, etc...) 

    server = the full URL to the main database server 
          (https://<username>:<password>@edelweiss.cloudant.com)
    databaseName = the name of the database (datadb) 


    This script will remove the "procname" object from a subset of the  
    database documents. To specify the particular subset of documents, 
    you MUST specify the following kwargs: 
    
    startkey = first run name (ex. "ma22a003_003")
    endkey = final run name (ex. "mb24b001_010")
    viewname = the DB View function that you use to get the list 
      of documents. 
      The most general view is "proc/daqdoc". You can use any of the 
      "Views" that return the run_name + file_name as a key. These are 
      "proc/bad", "proc/daqdoc", "proc/failed", "proc/inprogress", 
      "proc/inqueue", "proc/procX",  "proc/procXinprogress" (X = 1,2,3), 
      and "proc/raw"

    All documents that are returned by the viewname within the given 
    startkey/endkey range will be affected.

    Optional kwargs:

    status = if you set kwargs['status'] then only database documents 
    with this status will be affected
    
    test = if this is set to True, then no documents will be saved 
      back to the database. All other operations will be performed so that
      you may test the use of this function before affecting docs in 
      the database. 


    example: 
    
    import removeProc
    
    options = {};
    options['startkey'] = 'mj00a000_000'
    options['endkey'] = 'zz99z999';
    options['test'] = True;  #this will just be a test
    options['viewname'] = 'proc/failed'
    
    removeProc.removeProc('https://edelweissuser:[email protected]', 
      'datadb', 'proc1', options)

   '''

  db = Server(server)[databaseName]
  
  if kwargs['startkey'] == None or kwargs['endkey'] == None:
    print 'you must supply a range of runs to use. Set **kwargs["startkey"] and kwargs["endkey"]'
    return
  print 'using view', kwargs['viewname']

  new_status = 'good'
  if procname == 'proc0':
    new_status = 'closed'

    
  vr = db.view(kwargs['viewname'],  reduce = False, startkey=kwargs['startkey'], endkey=kwargs['endkey'])
  print len(vr), 'rows returned by the view'

  for row in vr:
    print 'checking', row['id']

    reqCom = '%s/%s/_design/proc/_update/removeproc/%s' % (server, databaseName, row['id'] )

    reqComDic = {'procname':procname, 'new_status':new_status}
    
    if kwargs.has_key('status') and kwargs['status'] != '':
      reqComDic['old_status'] = kwargs['status']

    if kwargs.has_key('test') and kwargs['test'] != '' and  kwargs['test'] is not False:
      reqComDic['test'] = kwargs['test']

    reqCom += '?' + urllib.urlencode(reqComDic)

    print 'HTTP PUT', reqCom
    resp = request(reqCom, method='PUT')
    respj = json.loads(resp.body_string())
    print json.dumps(respj, indent=1)
    print ''
开发者ID:gadamc,项目名称:kdata,代码行数:96,代码来源:removeProc.py

示例2: resetStatus

# 需要导入模块: from couchdbkit import Server [as 别名]
# 或者: from couchdbkit.Server import view [as 别名]
def resetStatus(server, databaseName, newstatus, **kwargs):
  '''
    This script will reset the "status" key from a database run document.  You must give a range of runs numbers
    by using the kwargs['startkey'] and kwargs['endkey']. You can change the status of a single run by specifing that
    run name for both 'startkey' and 'endkey'
    It will set the 'status' keyword for all documents unless you specify 'status'=='oldvalue' in the kwargs. If kwargs['status']
    is given, then only documents with 'status' = 'oldvalue' will be updated to the new status.
    (For now, it will change the status key of ALL partition files within a single run.)

    This script will reset the "status" key from a run document in the database.

    There are three options explicitly specified by this function. They are:
    
    newstatus = the value of doc['status']
    server = the full URL to the main database server (https://<username>:<password>@edelweiss.cloudant.com)
    databaseName = the name of the database (datadb)


    This script will affect only a subset of the database documents. 
    To specify this particular subset of documents, you MUST specify the following kwargs:
    
    startkey = first run name (ex. "ma22a003_003")
    endkey = final run name (ex. "mb24b001_010")
    viewname = the DB View function that you use to get the list of documents. The most general view is "proc/daqdoc". 
      You can use any of the "Views" that return the run_name_file_name as a key (i.e. ma22a003_003). 
      These are "proc/bad", "proc/daqdoc", "proc/failed", "proc/inprogress", "proc/inqueue", "proc/procX", 
      "proc/procXinprogress" (X = 1,2,3), and "proc/raw"

    All documents that are returned by the viewname within the given startkey/endkey range will be affected.

    Optional kwargs:

    status = if you set kwargs['status'] then only database documents with this status will have their status changed.

    test = if this is set to True, then no documents will be saved back to the database. All other operations will
      be performed so that you may test the use of this function before affecting docs in the database. 


    example: 
    
    import resetStatus
    
    options = {};
    options['startkey'] = 'mj00a000_000'
    options['endkey'] = 'zz99z999';
    options['test'] = True;  #this will just be a test
    options['viewname'] = 'proc/inqueue'
    options['status'] = 'proc1 queued'

    #reset these status values to 'good'
    resetStatus.resetStatus('https://edelweissuser:[email protected]', 'datadb', 'good', options)

  '''

  db = Server(server)[databaseName]

  print 'kwargs:' , kwargs

  if kwargs['startkey'] == None or kwargs['endkey'] == None:
    print 'you should supply a range of runs to use with **kwargs["startkey"] and kwargs["endkey"]'
    return

  vr = db.view(kwargs['viewname'],  reduce = False, startkey=kwargs['startkey'], endkey=kwargs['endkey'])

  for row in vr:
    print 'checking', row['id']

    reqCom = '%s/%s/_design/proc/_update/resetstatus/%s' % (server, databaseName, row['id'] )

    reqComDic = {'new_status':newstatus}

    if kwargs.has_key('status') and kwargs['status'] != '':
      reqComDic['old_status'] = kwargs['status']

    if kwargs.has_key('test') and kwargs['test'] != '' and  kwargs['test'] is not False:
      reqComDic['test'] = kwargs['test']

    reqCom += '?' + urllib.urlencode(reqComDic)

    print 'HTTP PUT', reqCom
    resp = request(reqCom, method='PUT')
    respj = json.loads(resp.body_string())
    print json.dumps(respj, indent=1)
    print ''
开发者ID:gadamc,项目名称:kdata,代码行数:86,代码来源:resetStatus.py


注:本文中的couchdbkit.Server.view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。