import libbe
import libbe.bug
import libbe.command
+import libbe.command.depend
+import libbe.command.target
import libbe.command.util
# get a list of * for cmp_*() comparing two bugs.
AVAILABLE_CMPS.remove('attr') # a cmp_* template.
class Filter (object):
- def __init__(self, status, severity, assigned, extra_strings_regexps):
+ def __init__(self, status='all', severity='all', assigned='all',
+ target='all', extra_strings_regexps=[]):
self.status = status
self.severity = severity
self.assigned = assigned
+ self.target = target
self.extra_strings_regexps = extra_strings_regexps
- def __call__(self, bug):
- if self.status != "all" and not bug.status in self.status:
+ def __call__(self, bugdir, bug):
+ if self.status != 'all' and not bug.status in self.status:
return False
- if self.severity != "all" and not bug.severity in self.severity:
+ if self.severity != 'all' and not bug.severity in self.severity:
return False
- if self.assigned != "all" and not bug.assigned in self.assigned:
+ if self.assigned != 'all' and not bug.assigned in self.assigned:
return False
+ if self.target == 'all':
+ pass
+ else:
+ target_bug = libbe.command.target.bug_target(bugdir, bug)
+ if self.target in ['none', None]:
+ if target_bug.summary != None:
+ return False
+ else:
+ if target_bug.summary != self.target:
+ return False
if len(bug.extra_strings) == 0:
if len(self.extra_strings_regexps) > 0:
return False
bugdir.storage.writeable = False
cmp_list, status, severity, assigned, extra_strings_regexps = \
self._parse_params(params)
- filter = Filter(status, severity, assigned, extra_strings_regexps)
+ filter = Filter(status, severity, assigned,
+ extra_strings_regexps=extra_strings_regexps)
bugs = [bugdir.bug_from_uuid(uuid) for uuid in bugdir.uuids()]
- bugs = [b for b in bugs if filter(b) == True]
+ bugs = [b for b in bugs if filter(bugdir, b) == True]
self.result = bugs
if len(bugs) == 0 and params['xml'] == False:
print >> self.stdout, "No matching bugs found"
if params['assigned'] == "all":
assigned = "all"
else:
- possible_assignees = []
- for bug in self.bugdir:
- if bug.assigned != None \
- and not bug.assigned in possible_assignees:
- possible_assignees.append(bug.assigned)
assigned = libbe.command.util.select_values(
- params['assigned'], possible_assignees)
+ params['assigned'], libbe.command.util.assignees())
for i in range(len(assigned)):
if assigned[i] == '-':
assigned[i] = params['user-id']
return target
def targets(bugdir):
+ """Generate all possible target bug summaries."""
bugdir.load_all_bugs()
for bug in bugdir:
if bug.severity == 'target':
yield bug.summary
-def complete_target(command, argument, fragment=None):
+def target_dict(bugdir):
"""
- List possible command completions for fragment.
-
- argument argument is not used.
+ Return a dict with bug UUID keys and bug summary values for all
+ target bugs.
"""
+ ret = {}
+ bugdir.load_all_bugs()
+ for bug in bugdir:
+ if bug.severity == 'target':
+ ret[bug.uuid] = bug.summary
+ return ret
+
+def complete_target(command, argument, fragment=None):
+ """List possible command completions for fragment."""
return targets(command._get_bugdir())
"""
return list(libbe.command.commands())
-def complete_path(command, argument, fragment=None):
- """
- List possible path completions for fragment.
-
- command argument is not used.
- """
+def comp_path(fragment=None):
+ """List possible path completions for fragment."""
if fragment == None:
fragment = '.'
comps = glob.glob(fragment+'*') + glob.glob(fragment+'/*')
comps.extend(glob.glob(comps[0]+'/*'))
return comps
+def complete_path(command, argument, fragment=None):
+ """List possible path completions for fragment."""
+ return comp_path(fragment)
+
def complete_status(command, argument, fragment=None):
bd = command._get_bugdir()
import libbe.bug
import libbe.bug
return libbe.bug.severity_values
+def assignees(bugdir):
+ bugdir.load_all_bugs()
+ return list(set([bug.assigned for bug in bugdir
+ if bug.assigned != None]))
+
def complete_assigned(command, argument, fragment=None):
- if fragment == None:
- return []
- return [fragment]
+ return assignees(command._get_bugdir())
def complete_extra_strings(command, argument, fragment=None):
if fragment == None: