aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-14 02:01:06 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-14 02:01:06 -0500
commit1bec5c0d3880a1cd848d765365104e221f390e71 (patch)
tree0e9a14e7985ae17a228f7b17b7bdedd7130024c7
parent5e769027075ce0f95d5cf9006d097f7fe7d8b38d (diff)
downloadbugseverywhere-1bec5c0d3880a1cd848d765365104e221f390e71.tar.gz
Added parse_user() calls to Assign
-rw-r--r--libbe/command/assign.py16
-rw-r--r--libbe/ui/util/repo.py4
-rw-r--r--libbe/util/id.py59
3 files changed, 48 insertions, 31 deletions
diff --git a/libbe/command/assign.py b/libbe/command/assign.py
index 2b4ed9f..287c649 100644
--- a/libbe/command/assign.py
+++ b/libbe/command/assign.py
@@ -34,19 +34,19 @@ class Assign (libbe.command.Command):
>>> bd.bug_from_uuid('a').assigned is None
True
- >>> cmd.run(bd, {'user-id':u'Fran\xe7ois'}, ['-', 'a'])
+ >>> cmd.run(bd, {'user-id':u'Fran\xe7ois'}, ['-', '/a'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned
u'Fran\\xe7ois'
- >>> cmd.run(bd, args=['someone', 'a', 'b'])
+ >>> cmd.run(bd, args=['someone', '/a', '/b'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned
'someone'
>>> bd.bug_from_uuid('b').assigned
'someone'
- >>> cmd.run(bd, args=['none', 'a'])
+ >>> cmd.run(bd, args=['none', '/a'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned is None
True
@@ -75,7 +75,15 @@ class Assign (libbe.command.Command):
elif assignee == '-':
assignee = params['user-id']
for bug_id in params['bug-id']:
- bug = bugdir.bug_from_uuid(bug_id)
+ p = libbe.util.id.parse_user(bugdir, bug_id)
+ if p['type'] != 'bug':
+ raise libbe.command.UserError(
+ '%s is a %s id, not a bug id' % (bug_id, p['type']))
+ if p['bugdir'] != bugdir.uuid:
+ raise libbe.command.UserError(
+ "%s doesn't belong to this bugdir (%s)"
+ % (bug_id, bugdir.uuid))
+ bug = bugdir.bug_from_uuid(p['bug'])
if bug.assigned != assignee:
bug.assigned = assignee
diff --git a/libbe/ui/util/repo.py b/libbe/ui/util/repo.py
deleted file mode 100644
index 174c5b1..0000000
--- a/libbe/ui/util/repo.py
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright
-
-def complete(string):
- pass
diff --git a/libbe/util/id.py b/libbe/util/id.py
index 645a17c..3838259 100644
--- a/libbe/util/id.py
+++ b/libbe/util/id.py
@@ -107,6 +107,7 @@ def _truncate(uuid, other_uuids, min_length=3):
def _expand(truncated_id, other_ids):
matches = []
+ other_ids = list(other_ids)
for id in other_ids:
if id.startswith(truncated_id):
matches.append(id)
@@ -209,28 +210,7 @@ def child_uuids(child_storage_ids):
fields = _split(id)
if len(fields) == 1:
yield fields[0]
-
-
-def parse_user(id):
- """
- >>> parse_user('ABC/DEF/GHI') == \\
- ... {'bugdir':'ABC', 'bug':'DEF', 'comment':'GHI', 'type':'comment'}
- True
- >>> parse_user('ABC/DEF') == \\
- ... {'bugdir':'ABC', 'bug':'DEF', 'type':'bug'}
- True
- >>> parse_user('ABC') == \\
- ... {'bugdir':'ABC', 'type':'bugdir'}
- True
- """
- ret = {}
- args = _split(id)
- assert len(args) > 0 and len(args) < 4, 'Invalid id "%s"' % id
- for type,arg in zip(HIERARCHY, args):
- assert len(arg) > 0, 'Invalid part "%s" of id "%s"' % (arg, id)
- ret['type'] = type
- ret[type] = arg
- return ret
+
REGEXP = '#([-a-f0-9]*)(/[-a-g0-9]*)?(/[-a-g0-9]*)?#'
@@ -275,9 +255,37 @@ class IDreplacer (object):
def short_to_long_user(bugdirs, text):
return re.sub(REGEXP, IDreplacer(bugdirs, 'short_to_long'), text)
+
def long_to_short_user(bugdirs, text):
return re.sub(REGEXP, IDreplacer(bugdirs, 'long_to_short'), text)
+
+def _parse_user(id):
+ """
+ >>> _parse_user('ABC/DEF/GHI') == \\
+ ... {'bugdir':'ABC', 'bug':'DEF', 'comment':'GHI', 'type':'comment'}
+ True
+ >>> _parse_user('ABC/DEF') == \\
+ ... {'bugdir':'ABC', 'bug':'DEF', 'type':'bug'}
+ True
+ >>> _parse_user('ABC') == \\
+ ... {'bugdir':'ABC', 'type':'bugdir'}
+ True
+ """
+ ret = {}
+ args = _split(id)
+ assert len(args) > 0 and len(args) < 4, 'Invalid id "%s"' % id
+ for type,arg in zip(HIERARCHY, args):
+ assert len(arg) > 0, 'Invalid part "%s" of id "%s"' % (arg, id)
+ ret['type'] = type
+ ret[type] = arg
+ return ret
+
+def parse_user(bugdir, id):
+ long_id = short_to_long_user([bugdir], '#%s#' % id).strip('#')
+ return _parse_user(long_id)
+
+
if libbe.TESTING == True:
class UUIDtestCase(unittest.TestCase):
def testUUID_gen(self):
@@ -328,7 +336,7 @@ if libbe.TESTING == True:
self.failUnless(self.c_id.user() == '123/abc/12345',
self.c_id.user())
- class IDtestCase(unittest.TestCase):
+ class ShortLongParseTestCase(unittest.TestCase):
def setUp(self):
self.bugdir = DummyObject('1234abcd')
self.bug = DummyObject('abcdef', ['a1234', 'ab9876'])
@@ -344,12 +352,17 @@ if libbe.TESTING == True:
self.c_id = ID(self.comment, 'comment')
self.short = 'bla bla #123/abc# bla bla #123/abc/12345# bla bla'
self.long = 'bla bla #1234abcd/abcdef# bla bla #1234abcd/abcdef/12345678# bla bla'
+ self.short_id = '123/abc'
def test_short_to_long(self):
self.failUnless(short_to_long_user([self.bugdir], self.short) == self.long,
'\n' + self.short + '\n' + short_to_long_user([self.bugdir], self.short) + '\n' + self.long)
def test_long_to_short(self):
self.failUnless(long_to_short_user([self.bugdir], self.long) == self.short,
'\n' + long_to_short_user([self.bugdir], self.long) + '\n' + self.short)
+ def test_parse_user(self):
+ self.failUnless(parse_user(self.bugdir, self.short_id) == \
+ {'bugdir':'1234abcd', 'bug':'abcdef', 'type':'bug'},
+ parse_user(self.bugdir, self.short_id))
unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])