Rewrite commands to use bugdirs instead of a single bugdir.
[be.git] / libbe / command / show.py
index 3175df8c2e8ce28ad46c1ad7abc983c08adce6ea..4bf5bd8fa87f9828169e7650a3dca75dae2704ba 100644 (file)
@@ -39,7 +39,7 @@ class Show (libbe.command.Command):
     >>> io.stdout = sys.stdout
     >>> io.stdout.encoding = 'ascii'
     >>> ui = libbe.command.UserInterface(io=io)
-    >>> ui.storage_callbacks.set_bugdir(bd)
+    >>> ui.storage_callbacks.set_storage(bd.storage)
     >>> cmd = Show(ui=ui)
 
     >>> ret = ui.run(cmd, args=['/a',])  # doctest: +ELLIPSIS
@@ -98,13 +98,14 @@ class Show (libbe.command.Command):
                 ])
 
     def _run(self, **params):
-        bugdir = self._get_bugdir()
+        bugdirs = self._get_bugdirs()
         if params['only-raw-body'] == True:
             if len(params['id']) != 1:
                 raise libbe.command.UserError(
                     'only one ID accepted with --only-raw-body')
-            bug,comment = libbe.command.util.bug_comment_from_user_id(
-                bugdir, params['id'][0])
+            bugdir,bug,comment = (
+                libbe.command.util.bugdir_bug_comment_from_user_id(
+                    bugdirs, params['id'][0]))
             if comment == bug.comment_root:
                 raise libbe.command.UserError(
                     "--only-raw-body requires a comment ID, not '%s'"
@@ -112,7 +113,7 @@ class Show (libbe.command.Command):
             sys.__stdout__.write(comment.body)
             return 0
         print >> self.stdout, \
-            output(bugdir, params['id'], encoding=self.stdout.encoding,
+            output(bugdirs, params['id'], encoding=self.stdout.encoding,
                    as_xml=params['xml'],
                    with_comments=not params['no-comments'])
         return 0
@@ -134,11 +135,11 @@ placed at the end of the output, so the ordering may not match the
 order of the listed IDs.
 """
 
-def _sort_ids(bugdir, ids, with_comments=True):
+def _sort_ids(bugdirs, ids, with_comments=True):
     bugs = []
     root_comments = {}
     for id in ids:
-        p = libbe.util.id.parse_user(bugdir, id)
+        p = libbe.util.id.parse_user(bugdirs, id)
         if p['type'] == 'bug':
             bugs.append(p['bug'])
         elif with_comments == True:
@@ -165,18 +166,20 @@ def _xml_header(encoding):
 def _xml_footer():
     return ['</be-xml>']
 
-def output(bd, ids, encoding, as_xml=True, with_comments=True):
+def output(bugdirs, ids, encoding, as_xml=True, with_comments=True):
     if ids == None or len(ids) == 0:
-        bd.load_all_bugs()
-        ids = [bug.id.user() for bug in bd]
-    bugs,root_comments = _sort_ids(bd, ids, with_comments)
+        ids = []
+        for bugdir in bugdirs.values():
+            bugdir.load_all_bugs()
+            ids.extend([bug.id.user() for bug in bugdir])
+    uuids,root_comments = _sort_ids(bugdirs, ids, with_comments)
     lines = []
     if as_xml:
         lines.extend(_xml_header(encoding))
     else:
         spaces_left = len(ids) - 1
-    for bugname in bugs:
-        bug = bd.bug_from_uuid(bugname)
+    for bugname in uuids:
+        bug = libbe.command.util.bug_from_uuid(bugdirs, bugname)
         if as_xml:
             lines.append(bug.xml(indent=2, show_comments=with_comments))
         else:
@@ -185,7 +188,7 @@ def output(bd, ids, encoding, as_xml=True, with_comments=True):
                 spaces_left -= 1
                 lines.append('') # add a blank line between bugs/comments
     for bugname,comments in root_comments.items():
-        bug = bd.bug_from_uuid(bugname)
+        bug = libbe.command.util.bug_from_uuid(bugdirs, bugname)
         if as_xml:
             lines.extend(['  <bug>', '    <uuid>%s</uuid>' % bug.uuid])
         for commname in comments: