import libbe.bug
import libbe.command
import libbe.command.depend
+import libbe.command.tag
import libbe.command.target
import libbe.command.util
arg=libbe.command.Argument(
name='sort', metavar='SORT', default=None,
completion_callback=libbe.command.util.Completer(AVAILABLE_CMPS))),
+ libbe.command.Option(name='tags', short_name='t',
+ help='Add TAGS: field to standard listing format.'),
libbe.command.Option(name='ids', short_name='i',
help='Only print the bug IDS'),
libbe.command.Option(name='xml', short_name='x',
for bug in bugs:
print >> self.stdout, bug.id.user()
else:
- self._list_bugs(bugs, xml=params['xml'])
+ self._list_bugs(bugs, show_tags=params['tags'], xml=params['xml'])
bugdir.storage.writeable = writeable
return 0
bugs.sort(cmp_fn)
return bugs
- def _list_bugs(self, bugs, xml=False):
+ def _list_bugs(self, bugs, show_tags=False, xml=False):
if xml == True:
print >> self.stdout, \
'<?xml version="1.0" encoding="%s" ?>' % self.stdout.encoding
if xml == True:
print >> self.stdout, bug.xml(show_comments=True)
else:
- print >> self.stdout, bug.string(shortlist=True)
+ bug_string = bug.string(shortlist=True)
+ if show_tags == True:
+ attrs,summary = bug_string.split(' ', 1)
+ bug_string = (
+ '%s%s: %s'
+ % (attrs,
+ ','.join(libbe.command.tag.get_tags(bug)),
+ summary))
+ print >> self.stdout, bug_string
if xml == True:
print >> self.stdout, '</be-xml>'
def _long_help(self):
return """
This command lists bugs. Normally it prints a short string like
- bea/576:om: Allow attachments
+ bea/576:om:[TAGS:] Allow attachments
Where
bea/576 the bug id
o the bug status is 'open' (first letter)
m the bug severity is 'minor' (first letter)
+ TAGS comma-separated list of bug tags (if --tags is set)
Allo... the bug summary string
You can optionally (-u) print only the bug ids.
'Do not specify a bug id with the --list option.')
bugdir = self._get_bugdir()
if params['list'] == True:
- bugdir.load_all_bugs()
- tags = []
- for bug in bugdir:
- for estr in bug.extra_strings:
- if estr.startswith(TAG_TAG):
- tag = estr[len(TAG_TAG):]
- if tag not in tags:
- tags.append(tag)
+ tags = get_all_tags(bugdir)
tags.sort()
if len(tags) > 0:
print >> self.stdout, '\n'.join(tags)
bug,dummy_comment = libbe.command.util.bug_comment_from_user_id(
bugdir, params['id'])
if len(params['tag']) > 0:
- estrs = bug.extra_strings
+ tags = get_tags(bug)
for tag in params['tag']:
- tag_string = '%s%s' % (TAG_TAG, tag)
if params['remove'] == True:
- estrs.remove(tag_string)
+ tags.remove(tag)
else: # add the tag
- estrs.append(tag_string)
- bug.extra_strings = estrs # reassign to notice change
+ tags.append(tag)
+ set_tags(bug, tags)
tags = []
for estr in bug.extra_strings:
To search for bugs with a particular tag, try
$ be list --extra-strings %s<your-tag>
""" % TAG_TAG
+
+# functions exposed to other modules
+
+def get_all_tags(bugdir):
+ bugdir.load_all_bugs()
+ tags = []
+ for bug in bugdir:
+ for tag in get_tags(bug):
+ if tag not in tags:
+ tags.append(tag)
+ return tags
+
+def get_tags(bug):
+ tags = []
+ for estr in bug.extra_strings:
+ if estr.startswith(TAG_TAG):
+ tag = estr[len(TAG_TAG):]
+ if tag not in tags:
+ tags.append(tag)
+ return tags
+
+def set_tags(bug, tags):
+ estrs = bug.extra_strings
+ new_estrs = []
+ for estr in estrs:
+ if not estr.startswith(TAG_TAG):
+ new_estrs.append(estr)
+ for tag in tags:
+ new_estrs.append('%s%s' % (TAG_TAG, tag))
+ bug.extra_strings = new_estrs # reassign to notice change
+
+def append_tag(bug, tag):
+ estrs = bug.extra_strings
+ estrs.append('%s%s' % (TAG_TAG, tag))
+ bug.extra_strings = estrs # reassign to notice change
+
+def remove_tag(bug, tag):
+ estrs = bug.extra_strings
+ estrs.remove('%s%s' % (TAG_TAG, tag))
+ bug.extra_strings = estrs # reassign to notice change