當前位置: 首頁>>代碼示例>>Python>>正文


Python Rule.getPRlist方法代碼示例

本文整理匯總了Python中rule.Rule.getPRlist方法的典型用法代碼示例。如果您正苦於以下問題:Python Rule.getPRlist方法的具體用法?Python Rule.getPRlist怎麽用?Python Rule.getPRlist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rule.Rule的用法示例。


在下文中一共展示了Rule.getPRlist方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Verify

# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import getPRlist [as 別名]
class Verify(object):
    
    # Initialize the logpath and server name obtained from the config file
    def __init__(self, logpath, server):
        self.logpath = logpath
        self.timestamp = ''    # Time stamp will be updated when the file is created
        self.scrape = Scrape(server)
        self.rule = Rule()
    
    # Send an email by refering to the dictionary that includes list of users for which discrepancy was found for particular rule type
    def sendEmail(self, UserRuleDict):
        # Send an email if at least one discrepancy was found
        msgbody = ''
        if len(UserRuleDict) > 0:
            for rule, userlist in UserRuleDict.items():
                msgbody += ' \n\n*** Dashboard data does not match GNATS for rule type %(1)s for following users: *** \n%(2)s' \
                % {"1": rule, "2": ', '.join(user for user in userlist)} 
                
            msgbody += '\n\nRefer to the following log file for details: \n%s/DAM_%s.log' % (self.logpath, self.timestamp) 
            EmailAlert().send('[email protected]', 
                              ['[email protected]'], 
                              'DAM Alert', msgbody)
    
    '''
    Run the logic to compare the list of PRs found in Dashboard and the one generated from Gnats
    Log all the details and if discrepancy is found, send and email alert to concerned users
    '''    
    def run(self, usernamelist, rulelist):
        self.timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        logfile = '%s/DAM_%s.log' % (self.logpath, self.timestamp)
        logging.basicConfig(filename=logfile, filemode='w', format='%(message)s' ,level=logging.WARNING)
        hdlr = logging.FileHandler(logfile)
        try:
            discrepancyUserdict = {}
            for ruletype in rulelist:
                for user in usernamelist:
                    logline = '-----------------------------------------------------------------------------------'
                    print logline
                    logging.critical(logline)
                    
                    logline = 'Verifying for user ||%(1)s|| for ||%(2)s|| type of PRs: ' % {"1": user, "2": ruletype}
                    print logline
                    logging.critical(logline)
                    
                    gnatsPRlist = self.rule.getPRlist(user, ruletype)
                    dashPRlist = self.scrape.getPRList(user, ruletype)
                    
                    discrepancylist1 = list(set(gnatsPRlist) - set(dashPRlist))
                    discrepancylist2 = list(set(dashPRlist) - set(gnatsPRlist))
                    
                    logging.critical('%s:' % datetime.datetime.now().strftime("%A, %d - %B %Y %I:%M%p"))
                    logline = 'Count of PRs from GNATS: %d' % len(gnatsPRlist)
                    print logline
                    logging.critical(logline)
                    
                    logline = 'Count of PRs from Dashboard: %d' % len(dashPRlist)
                    print logline
                    logging.critical(logline)
                    
                    logline = 'List of PRs missing in dashboard: [%s] ' % ','.join(d for d in discrepancylist1)
                    print logline
                    logging.critical(logline)
                    
                    logline = 'List of PRs additionally found in dashboard: [%s]' % ','.join(d for d in discrepancylist2)
                    print logline
                    logging.critical(logline)
                    
                    if len(discrepancylist1 + discrepancylist2) > 0:
                        print 'Checking for recently updated PRs and discarding false negatives from the list...'
                        finalDescList = self.removeRecentPRs(discrepancylist1 + discrepancylist2)
                        if len(finalDescList) > 0:
                            logline = '\nDiscrepancies found after removing recently updated PRs: [%s] ' % ','.join(f for f in finalDescList)
                            discrepancyUserdict.setdefault(ruletype, []).append(user)
                        else:
                            logline = '\nDiscrepancies found after removing recently updated PRs: None'
                        print logline
                        logging.critical(logline)
                    else:
                        logline = '\nNo discrepancies found at all'
                        print logline
                        logging.critical(logline)
            
            
            # alert admin by sending an autogenerated email:
            if len(discrepancyUserdict) > 0:
                self.sendEmail(discrepancyUserdict)
            
            # close the log file
            hdlr.close()
        except Exception, e:
            logging.exception(e)
開發者ID:richil-bhalerao,項目名稱:DAM,代碼行數:93,代碼來源:verify.py


注:本文中的rule.Rule.getPRlist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。