示例#1
0
    def processObject(self, obj):
        """Operate on the provided job object."""

        # ask the user if we should continue
        if not obj.pre(self, "Change the crews of the job?"):
            return

        if self.opts.add or self.opts.remove:
            # make sure everything is unique
            origcrews = listutil.getUnion(obj.crews)
            # make a copy so we can add/remove crews
            newcrews = list(origcrews)
            for crew in (self.opts.add or self.opts.remove):
                if self.opts.add:
                    newcrews.append(crew)
                else:
                    if crew in origcrews:
                        newcrews.remove(crew)
                    else:
                        obj.post(
                            self,
                            "crew %s is not in crews %s" % (crew, origcrews))
            # make sure everything is unique again
            newcrews = listutil.getUnion(newcrews)
            if newcrews == origcrews:
                obj.post(self, "doesn't need to change")
                return
            crews = newcrews
        else:
            crews = listutil.getUnion(self.opts.crews)

        # try to run the operation
        query.chcrews(obj, crews=crews)
        obj.post(self, "crews changed")
示例#2
0
文件: JobCmds.py 项目: utsdab/usr
    def processObject(self, obj):
        """Operate on the provided job object."""

        # ask the user if we should continue
        if not obj.pre(self, "Change the crews of the job?"):
            return

        if self.opts.add or self.opts.remove:
            # make sure everything is unique
            origcrews = listutil.getUnion(obj.crews)
            # make a copy so we can add/remove crews
            newcrews = list(origcrews)
            for crew in self.opts.add or self.opts.remove:
                if self.opts.add:
                    newcrews.append(crew)
                else:
                    if crew in origcrews:
                        newcrews.remove(crew)
                    else:
                        obj.post(self, "crew %s is not in crews %s" % (crew, origcrews))
            # make sure everything is unique again
            newcrews = listutil.getUnion(newcrews)
            if newcrews == origcrews:
                obj.post(self, "doesn't need to change")
                return
            crews = newcrews
        else:
            crews = listutil.getUnion(self.opts.crews)

        # try to run the operation
        query.chcrews(obj, crews=crews)
        obj.post(self, "crews changed")
示例#3
0
def mergeDict(dict1, dict2, unionLists=0):
    """
    Merge two dictionaries

    >>> d = mergeDict({'a': 1, 'b': 2}, {'c': 3, 'd': 4})
    >>> d == {'a': 1, 'b': 2, 'c': 3, 'd': 4}
    1

    >>> d = mergeDict(
    ...     {'a': [1,2], 'b': {1:2, 3:4}}, 
    ...     {'a': [3,4], 'b': {3:4, 5:6}, 'c': 7})
    >>> d == {'a': [3,4], 'b': {1:2, 3:4, 5:6}, 'c': 7}
    1

    >>> d = mergeDict(
    ...     {'a': [1,2], 'b': {1:2, 3:4}}, 
    ...     {'a': [3,4], 'b': {3:4, 5:6}, 'c': 7}, unionLists=1)
    >>> d == {'a': [1,2,3,4], 'b': {1:2, 3:4, 5:6}, 'c': 7}
    1
    
    """

    for key,val2 in dict2.iteritems():
        try:
            val1 = dict1[key]
        except KeyError:
            # make a deep copy of the value is a dictionary
            if type(val2) is types.DictType:
                dict1[key] = {}
                mergeDict(dict1[key], val2)
            # make a new list
            elif type(val2) is types.ListType:
                dict1[key] = list(val2)
            else:
                dict1[key] = val2
        else:
            # recursively merge the two dictionaries
            if type(val1) is types.DictType and \
               type(val2) is types.DictType:
                mergeDict(val1, val2)
            # take the union of the two lists
            elif unionLists and \
                 type(val1) is types.ListType and \
                 type(val2) is types.ListType:
                dict1[key] = getUnion(val1, val2)
            # replace the value in dict1 with dict2's
            else:
                dict1[key] = val2
    return dict1
示例#4
0
def mergeDict(dict1, dict2, unionLists=0):
    """
    Merge two dictionaries

    >>> d = mergeDict({'a': 1, 'b': 2}, {'c': 3, 'd': 4})
    >>> d == {'a': 1, 'b': 2, 'c': 3, 'd': 4}
    1

    >>> d = mergeDict(
    ...     {'a': [1,2], 'b': {1:2, 3:4}}, 
    ...     {'a': [3,4], 'b': {3:4, 5:6}, 'c': 7})
    >>> d == {'a': [3,4], 'b': {1:2, 3:4, 5:6}, 'c': 7}
    1

    >>> d = mergeDict(
    ...     {'a': [1,2], 'b': {1:2, 3:4}}, 
    ...     {'a': [3,4], 'b': {3:4, 5:6}, 'c': 7}, unionLists=1)
    >>> d == {'a': [1,2,3,4], 'b': {1:2, 3:4, 5:6}, 'c': 7}
    1
    
    """

    for key, val2 in dict2.iteritems():
        try:
            val1 = dict1[key]
        except KeyError:
            # make a deep copy of the value is a dictionary
            if type(val2) is types.DictType:
                dict1[key] = {}
                mergeDict(dict1[key], val2)
            # make a new list
            elif type(val2) is types.ListType:
                dict1[key] = list(val2)
            else:
                dict1[key] = val2
        else:
            # recursively merge the two dictionaries
            if type(val1) is types.DictType and \
               type(val2) is types.DictType:
                mergeDict(val1, val2)
            # take the union of the two lists
            elif unionLists and \
                 type(val1) is types.ListType and \
                 type(val2) is types.ListType:
                dict1[key] = getUnion(val1, val2)
            # replace the value in dict1 with dict2's
            else:
                dict1[key] = val2
    return dict1
示例#5
0
 def runQuery(self):
     """Overloaded from the super so a different Task object
     can be returned."""
     # check if we need to contact the db
     if self.objects:
         result = self.objects
     else:
         # only query existing jobs
         # AWG: not deleted not getting translated right yet
         #where  = "(%s) and not deleted" % self.where
         where  = self.where
         self.members = listutil.getUnion(self.members + ["cids"])
         result = self.db.getTasks(members=self.members,
                                   where=where,
                                   limit=self.opts.limit,
                                   orderby=self.opts.sortby,
                                   objtype=tq.OperationRow)
     if not result:
         print "no tasks found"
     return result
示例#6
0
 def runQuery(self):
     """Overloaded from the super so a different Task object
     can be returned."""
     # check if we need to contact the db
     if self.objects:
         result = self.objects
     else:
         # only query existing jobs
         # AWG: not deleted not getting translated right yet
         #where  = "(%s) and not deleted" % self.where
         where = self.where
         self.members = listutil.getUnion(self.members + ["cids"])
         result = self.db.getTasks(members=self.members,
                                   where=where,
                                   limit=self.opts.limit,
                                   orderby=self.opts.sortby,
                                   objtype=tq.OperationRow)
     if not result:
         print "no tasks found"
     return result
示例#7
0
        try:
            for alias, args in prefs.aliases.args["global"].items():
                aliases.append(("args", "global", alias, args))
        except (AttributeError, KeyError):
            pass

        # add command aliases
        try:
            ualiases = prefs.aliases.command
        except (AttributeError, KeyError):
            ualiases = {}
        for alias, args in self.parent.aliases.items() + ualiases.items():
            aliases.append(("command", "global", alias, args))

        # sort the aliases
        aliases = [Alias(*a) for a in listutil.getUnion(aliases)]

        form = Formats.Formatter([
            "type",
            Formats.StringFormat("usedby", header="used by"),
            "alias",
            Formats.StringFormat("avalue",
                                 header="resolves to",
                                 maxWidth=50,
                                 truncate="wrap"),
        ])

        print form.formatList(aliases)


class ColumnsHelp(TqHelp):
示例#8
0
        try:
            for alias,args in prefs.aliases.args["global"].items():
                aliases.append(("args", "global", alias, args))
        except (AttributeError, KeyError):
            pass

        # add command aliases
        try:
            ualiases = prefs.aliases.command
        except (AttributeError, KeyError):
            ualiases = {}
        for alias,args in self.parent.aliases.items() + ualiases.items():
            aliases.append(("command", "global", alias, args))

        # sort the aliases
        aliases = [Alias(*a) for a in listutil.getUnion(aliases)]

        form = Formats.Formatter(
            ["type",
             Formats.StringFormat("usedby", header="used by"),
             "alias",
             Formats.StringFormat("avalue", header="resolves to",
                                  maxWidth=50, truncate="wrap"),
             ])

        print form.formatList(aliases)


class ColumnsHelp(TqHelp):
    """Help for customizing the output of commands."""