From: W. Trevor King Date: Mon, 14 Dec 2009 07:01:06 +0000 (-0500) Subject: Added parse_user() calls to Assign X-Git-Tag: 1.0.0~59^2~52^2~62 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1bec5c0d3880a1cd848d765365104e221f390e71;p=be.git Added parse_user() calls to Assign --- 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()])