diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-08 03:51:27 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-08 03:51:27 -0500 |
commit | e5177b9150290004f472d08c13dfe78075f029e8 (patch) | |
tree | e6ee0ee2fc06491dafb841ace6968026f7eb765d /libbe | |
parent | fe1d6dff22f73671928eaadbf4c83bdaa21d9bb9 (diff) | |
download | bugseverywhere-e5177b9150290004f472d08c13dfe78075f029e8.tar.gz |
Extend libbe.util.id to handle id (path) creation.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/util/id.py (renamed from libbe/util/beuuid.py) | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/libbe/util/beuuid.py b/libbe/util/id.py index a3a3b6c..0f1576c 100644 --- a/libbe/util/beuuid.py +++ b/libbe/util/id.py @@ -16,15 +16,14 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -Backwards compatibility support for Python 2.4. Once people give up -on 2.4 ;), the uuid call should be merged into bugdir.py +Handle ID creation and parsing. """ import libbe + if libbe.TESTING == True: import unittest - try: from uuid import uuid4 # Python >= 2.5 def uuid_gen(): @@ -58,6 +57,50 @@ except ImportError: raise Exception, strerror return output.rstrip('\n') + +def _assemble(*args): + for i,arg in enumerate(args): + if arg == None: + args[i] = '' + return '/'.join(args) + +def _split(id): + args = id.split('/') + for i,arg in enumerate(args): + if arg == '': + args[i] = None + return args + + +def bugdir_id(bugdir, *args): + return _assemble(bugdir.uuid, args) + +def bug_id(bug, *args): + if bug.bug == None: + bugdir_id = None + else: + bugdir_id = bugdir_id(bug.bugdir) + return _assemble(bugdir_id, bug.uuid, args) + +def comment_id(comment, *args): + if comment.bug == None: + bug_id = None + else: + bug_id = bug_id(comment.bug) + return _assemble(bug_id, comment.uuid, args) + +def parse_id(id): + args = _split(id) + ret = {'bugdir':args.pop(0)} + type = 'bugdir' + for child_name in ['bug', 'comment']: + if len(args) > 0 and is_a_uuid(args[0]): + ret[child_name] = args.pop(0) + type = child_name + ret['type'] = type + ret['remaining'] = os.path.join(args) + return ret + if libbe.TESTING == True: class UUIDtestCase(unittest.TestCase): def testUUID_gen(self): |