aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-06-25 14:31:34 -0400
committerW. Trevor King <wking@drexel.edu>2010-06-25 14:31:34 -0400
commit57c61e2e78078322bfae6b338bede66ec3107203 (patch)
treeed29d453702a854c1f9c9076ff844ff4b5e198f7 /libbe/command
parenteaa9ad50c853e57d85b774c69cd338458e648329 (diff)
downloadbugseverywhere-57c61e2e78078322bfae6b338bede66ec3107203.tar.gz
Added --tags to `be list`.
And broke out tagging functions in libbe.command.tag, so they are accessible to other commands.
Diffstat (limited to 'libbe/command')
-rw-r--r--libbe/command/list.py20
-rw-r--r--libbe/command/tag.py58
2 files changed, 61 insertions, 17 deletions
diff --git a/libbe/command/list.py b/libbe/command/list.py
index a522b4a..197604b 100644
--- a/libbe/command/list.py
+++ b/libbe/command/list.py
@@ -25,6 +25,7 @@ import libbe
import libbe.bug
import libbe.command
import libbe.command.depend
+import libbe.command.tag
import libbe.command.target
import libbe.command.util
@@ -127,6 +128,8 @@ class List (libbe.command.Command):
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',
@@ -173,7 +176,7 @@ class List (libbe.command.Command):
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
@@ -230,7 +233,7 @@ class List (libbe.command.Command):
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
@@ -240,18 +243,27 @@ class List (libbe.command.Command):
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.
diff --git a/libbe/command/tag.py b/libbe/command/tag.py
index da7c03e..156bc6f 100644
--- a/libbe/command/tag.py
+++ b/libbe/command/tag.py
@@ -108,14 +108,7 @@ class Tag (libbe.command.Command):
'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)
@@ -124,14 +117,13 @@ class Tag (libbe.command.Command):
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:
@@ -151,3 +143,43 @@ print the tags for BUG-ID.
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