当前位置: 首页>>代码示例>>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;未经允许,请勿转载。