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


Python Document.has_key方法代码示例

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


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

示例1: testB

# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import has_key [as 别名]
    def testB(self):
        """test owning some sample documents"""

        u1 = User(name = "evansde77")
        g1 = Group(name = "DMWM", administrators = ["evansde77", "drsm79"])
        g1.setCouch(self.url, self.database)
        g1.connect()
        u1.setGroup(g1)
        u1.create()

        doc1 = Document()
        doc1['test-data'] = {"key1" : "value1"}
        doc2 = Document()
        doc2['test-data'] = {"key2" : "value2"}
        id1 = g1.couch.commitOne(doc1)[0]
        id2 = g1.couch.commitOne(doc2)[0]
        doc1['_id'] = id1[u'id']
        doc1['_rev'] = id1[u'rev']
        doc2['_id'] = id2[u'id']
        doc2['_rev'] = id2[u'rev']

        u1.ownThis(doc1)
        u1.ownThis(doc2)

        self.failUnless(doc1.has_key("owner"))
        self.failUnless(doc2.has_key("owner"))
        self.failUnless(doc1['owner'].has_key('user'))
        self.failUnless(doc1['owner'].has_key('group'))
        self.failUnless(doc1['owner']['user'] == u1['name'])
        self.failUnless(doc1['owner']['group'] == u1['group'])
        self.failUnless(doc2['owner'].has_key('user'))
        self.failUnless(doc2['owner'].has_key('group'))
        self.failUnless(doc2['owner']['user'] == u1['name'])
        self.failUnless(doc2['owner']['group'] == u1['group'])


        g1.couch.delete_doc(id1[u'id'])
        g1.couch.delete_doc(id2[u'id'])
        u1.drop()
        g1.drop()
开发者ID:AndrewLevin,项目名称:WMCore,代码行数:42,代码来源:User_t.py

示例2: gatherWMDataMiningStats

# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import has_key [as 别名]
def gatherWMDataMiningStats(wmstatsUrl, reqmgrUrl, wmminigUrl, archived = False, log = logging.info):
    
    server, database = splitCouchServiceURL(wmminigUrl)
    analyticsServer = CouchServer(server)
    couchdb = analyticsServer.connectDatabase(database)

    WMStats = WMStatsReader(wmstatsUrl)
    
    reqMgrServer, reqMgrDB = splitCouchServiceURL(reqmgrUrl)
    
    reqMgr = CouchServer(reqMgrServer).connectDatabase(reqMgrDB, False)
    
    if archived:
        funcName = "Archived Requests"
    else:
        funcName = "Active Requests"
    
    log("INFO: %s: Getting job information from %s and %s. Please wait." % (
                  funcName, wmstatsUrl, reqmgrUrl))

    if archived:
        checkStates = ['normal-archived', 'rejected-archived', 'aborted-archived']
        jobInfoFlag = False
    else:
        checkStates = WMStatsReader.ACTIVE_STATUS
        jobInfoFlag = True
    requests = WMStats.getRequestByStatus(checkStates, jobInfoFlag = jobInfoFlag)

    requestCollection = RequestInfoCollection(requests)
    result = requestCollection.getJSONData()
    requestsDict = requestCollection.getData()
    log("INFO: %s: Total %s requests retrieved\n" % (funcName, len(result)))

    report = {}
    for wf in result.keys():

        # Store a copy of the CouchDB document so we can compare later before updating
        if couchdb.documentExists(wf):
            oldCouchDoc = couchdb.document(wf)
            wfExists = True
        else:
            oldCouchDoc = CouchDoc(id=wf)
            wfExists = False

        newCouchDoc = copy.deepcopy(oldCouchDoc)
        ancientCouchDoc = copy.deepcopy(oldCouchDoc)
        report[wf] = oldCouchDoc
        # FIXME: remove report, only have two instances of couchDoc

        if not oldCouchDoc.has_key('filterEfficiency') or not oldCouchDoc.has_key('runWhiteList'):
            runWhiteList = []
            filterEfficiency = None
            try:
                #log("DEBUG: Looking up %s in ReqMgr" % wf)
                rmDoc = reqMgr.document(wf)
                runWhiteList = rmDoc.get('RunWhiteList', [])
                filterEfficiency = rmDoc.get('FilterEfficiency', None)
            except:
                pass # ReqMgr no longer has the workflow
            report[wf].update({'filterEfficiency':filterEfficiency, 'runWhiteList':runWhiteList})

        # Basic parameters of the workflow
        priority = requests[wf]['priority']
        requestType = requests[wf]['request_type']
        targetLumis = requests[wf].get('input_lumis', 0)
        targetEvents = requests[wf].get('input_events', 0)
        campaign = requests[wf]['campaign']
        prep_id = requests[wf].get('prep_id', None)
        outputdatasets = requests[wf].get('outputdatasets', [])

        # Can be an empty list, full list, empty string, or non-empty string!
        inputdataset = requests[wf]['inputdataset']
        if isinstance(inputdataset, (list,)):
            if inputdataset:
                inputdataset = inputdataset[0]
            else:
                inputdataset = ''

        outputTier = 'Unknown'
        try:
            outputTiers = []
            for ds in outputdatasets:
                if type(ds) == list:
                    outputTiers.append(ds[0].split('/')[-1])
                else:
                    outputTiers.append(ds.split('/')[-1])
        except:
            log("ERROR: Could not decode outputdatasets: %s" % outputdatasets) # Sometimes is a list of lists, not just a list. Bail
        if inputdataset:
            inputTier = inputdataset.split('/')[-1]
            if inputTier in ['GEN']:
                outputTier = 'LHE'
            elif inputTier in ['RAW', 'RECO']:
                outputTier = 'AOD'
            elif inputTier in ['GEN-SIM']:
                outputTier = 'AODSIM'
            elif 'AODSIM' in outputTiers:
                outputTier = 'AODSIM'

        else:
#.........这里部分代码省略.........
开发者ID:annawoodard,项目名称:WMCore,代码行数:103,代码来源:Utils.py

示例3: CouchDoc

# 需要导入模块: from WMCore.Database.CMSCouch import Document [as 别名]
# 或者: from WMCore.Database.CMSCouch.Document import has_key [as 别名]
    for wf in result.keys():

        # Store a copy of the CouchDB document so we can compare later before updating
        if couchdb.documentExists(wf):
            oldCouchDoc = couchdb.document(wf)
            wfExists = True
        else:
            oldCouchDoc = CouchDoc(id=wf)
            wfExists = False

        newCouchDoc = copy.deepcopy(oldCouchDoc)
        ancientCouchDoc = copy.deepcopy(oldCouchDoc)
        report[wf] = oldCouchDoc
        # FIXME: remove report, only have two instances of couchDoc

        if not oldCouchDoc.has_key('filterEfficiency') or not oldCouchDoc.has_key('runWhiteList'):
            runWhiteList = []
            filterEfficiency = None
            try:
                print "Looking up %s in ReqMgr" % wf
                rmDoc = reqMgr.document(wf)
                runWhiteList = rmDoc.get('RunWhiteList', [])
                filterEfficiency = rmDoc.get('FilterEfficiency', None)
            except:
                pass # ReqMgr no longer has the workflow
            report[wf].update({'filterEfficiency':filterEfficiency, 'runWhiteList':runWhiteList})

        # Basic parameters of the workflow
        priority = requests[wf]['priority']
        requestType = requests[wf]['request_type']
        targetLumis = requests[wf].get('input_lumis', 0)
开发者ID:samircury,项目名称:WMCore,代码行数:33,代码来源:GatherStats.py


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