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


Python Category.listCategoriesForUser方法代码示例

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


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

示例1: Rule

# 需要导入模块: from category import Category [as 别名]
# 或者: from category.Category import listCategoriesForUser [as 别名]
class Rule(object):
    
    # Initialize the connection string required to connect to GNATS database
    def __init__(self):
        self.hier = Hier()
        self.category = Category()
        self.dashuser = Dashuser()
        
        host = 'gnats.juniper.net'
        db = 'default'
        
        # username = os.getusername()  ... for Linux
        
        username = getpass.getuser()        #... for Windows and linux
        
        # Get a database object, which holds the metadata (field names, etc.)
        self.db_obj = gnats.get_database(host, db)
        # Get a db handle, a connection to the server
        self.db_handle = self.db_obj.get_handle(username, passwd='*')

    
    # build an OR query e.g.: (responsible == "user1" | responsible == "user2"...)
    def getORquery(self, field, userlist, op = '=='):
        
        query = ''
        concat = ''
        for user in userlist:
            query += concat
            query += ''.join('(%(1)s %(2)s "%(3)s")' % {"1": field, "2": op, "3": user})
            concat = ' | '
            
        return '(%s)' % query
    
    # Using employee hierarchy build a list of all reports of a particular manager
    def buildUserList(self, responsible):
        userlist = self.hier.reports(responsible, 0)
        # we should also consider count of that user if he/she is a manager 
        userlist.append(responsible)
        return userlist
    
    # Filter out user list to remove users which are not under JUNOS system
    def buildJunosUserList(self, responsible):
        userlist = self.hier.reports(responsible, 0)
        # we should also consider count of that user if he/she is a manager 
        userlist.append(responsible)
        # remove those users which are not junos dashboard users
        userlistcopy = copy.copy(userlist)
        for user in userlistcopy:
            if user not in self.dashuser.dashuserlist:
                userlist.remove(user)
        
        return userlist
        
        
    '''
    Build list of all reports for category or category alias:
    if islias = 1 -> generate alias list
    if isalias = 0 -> generate catgeory list
    '''
    def buildCatAliasList(self, responsible, isAlias=1):
        aliaslist = []
        userlist = self.buildUserList(responsible)
        for user in userlist:
            if isAlias == 1:
                alist = self.category.listAliasForUser(user)
            else:
                alist = self.category.listCategoriesForUser(user) 
            if alist != None:
                for a in alist:
                    aliaslist.append(a)
        
        # remove duplicates
        aliaslist = list(set(aliaslist))
        return aliaslist
    
    '''
    Build query as:
    responsible == Aliaslist & (dev-owner == "" | dev-owner == Aliaslist) & Category == Categorylist
    '''
    def getCategoryOwnerQuery(self, responsible):
        aliaslist = self.buildCatAliasList(responsible)
        catlist = self.buildCatAliasList(responsible, 0)
        
        if len(aliaslist) > 0:
            return '| (%(1)s & (dev-owner == "" | %(2)s) & %(3)s)' % {"1": self.getORquery('responsible', aliaslist), \
                                                                      "2": self.getORquery('dev-owner', aliaslist, '~'), \
                                                                      "3": self.getORquery('category', catlist)}
        else:
            return ''
            
    
    # generate rule specific query e.g.: blocker == "test"
    def getQueryForRuleType(self, ruletype):
        if ruletype.lower() == 'test blocker':
            return '(blocker == "test")'
        elif ruletype.lower() == "regression":
            return '(attributes ~ "regression-pr")'
        elif ruletype.lower() == "beta blocker":
            return '((blocker == "beta") | ((planned-release ~ "b1" | planned-release ~ "b2" | planned-release ~ "b3") & (blocker != "")))'
        elif ruletype.lower() == "cl1":
#.........这里部分代码省略.........
开发者ID:richil-bhalerao,项目名称:DAM,代码行数:103,代码来源:rule.py


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