diff options
author | W. Trevor King <wking@drexel.edu> | 2009-11-21 10:53:04 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-11-21 10:53:04 -0500 |
commit | 3b168403ff5e50d767476c4c0f037d1841bb2bf9 (patch) | |
tree | 1929369aed3b5b4b0b6c87b27c92732798d0714a /libbe/cmdutil.py | |
parent | 75fedab07f9e566ca1c984051d7deece4d910e2c (diff) | |
download | bugseverywhere-3b168403ff5e50d767476c4c0f037d1841bb2bf9.tar.gz |
Broke `be comment --xml` out and extended into `be import-xml`.
It should currently do everything that `be comment --xml` did, but it
still has a way to go before it lives up to it's longhelp string,
mostly figuring out bug/comment merging.
The allowed XML format also changed a bit, becoming a bit more
structured.
cmdutil.bug_from_shortname() renamed to cmdutil.bug_from_id().
New functions cmdutil.parse_id() and cmdutil.bug_comment_from_id().
Additional doctests in libbe.comment.Comment.comment_shortnames() to
show example output if bug_shortname==None.
Brought be-xml-to-mbox and be-mbox-to-xml up to speed on the current
<be-xml>-rooted format.
* Added <extra-string> handling to their comment handling.
* Moved extra strings from email bodies to X-Extra-String headers
(some comment bodies are not text, and we should keep the estr
location consistent between bugs and comments.)
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r-- | libbe/cmdutil.py | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index f1c8acd..96430eb 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -30,10 +30,10 @@ import sys import doctest import bugdir +import comment import plugin import encoding - class UserError(Exception): def __init__(self, msg): Exception.__init__(self, msg) @@ -213,16 +213,69 @@ def underlined(instring): return "%s\n%s" % (instring, "="*len(instring)) -def bug_from_shortname(bdir, shortname): +def parse_id(id): + """ + Return (bug_id, comment_id) tuple. + Basically inverts Comment.comment_shortnames() + >>> parse_id('XYZ') + ('XYZ', None) + >>> parse_id('XYZ:123') + ('XYZ', ':123') + >>> parse_id('') + Traceback (most recent call last): + ... + UserError: invalid id ''. + >>> parse_id('::') + Traceback (most recent call last): + ... + UserError: invalid id '::'. + """ + if len(id) == 0: + raise UserError("invalid id '%s'." % id) + if id.count(':') > 1: + raise UserError("invalid id '%s'." % id) + elif id.count(':') == 1: + # Split shortname generated by Comment.comment_shortnames() + bug_id,comment_id = id.split(':') + comment_id = ':'+comment_id + else: + bug_id = id + comment_id = None + return (bug_id, comment_id) + +def bug_from_id(bdir, id): """ Exception translation for the command-line interface. + id can be either the bug shortname or the full uuid. """ try: - bug = bdir.bug_from_shortname(shortname) + bug = bdir.bug_from_shortname(id) except (bugdir.MultipleBugMatches, bugdir.NoBugMatches), e: raise UserError(e.message) return bug +def bug_comment_from_id(bdir, id): + """ + Return (bug,comment) tuple matching shortname. id can be either + the bug/comment shortname or the full uuid. If there is no + comment part to the id, the returned comment is the bug's + .comment_root. + """ + bug_id,comment_id = parse_id(id) + try: + bug = bdir.bug_from_shortname(bug_id) + except (bugdir.MultipleBugMatches, bugdir.NoBugMatches), e: + raise UserError(e.message) + if comment_id == None: + comm = bug.comment_root + else: + #bug.load_comments(load_full=False) + try: + comm = bug.comment_root.comment_from_shortname(comment_id) + except comment.InvalidShortname, e: + raise UserError(e.message) + return (bug, comm) + def _test(): import doctest import sys |