Moved libbe.cmdutil.bug_summary() to libbe.bug.Bug.string().
authorW. Trevor King <wking@drexel.edu>
Sat, 15 Nov 2008 23:35:41 +0000 (18:35 -0500)
committerW. Trevor King <wking@drexel.edu>
Sat, 15 Nov 2008 23:35:41 +0000 (18:35 -0500)
This seems like a natual place for a function that only operates on Bugs.

becommands/list.py
becommands/show.py
becommands/upgrade.py
libbe/bug.py
libbe/bugdir.py
libbe/cmdutil.py
libbe/diff.py

index e127c50abc6b63ca8cf8408ebeec157783595f6e..6cd7826c403b3903682b20131024abb38c488267 100644 (file)
@@ -107,8 +107,7 @@ def execute(args):
             if title != None:
                 print cmdutil.underlined(title)
             for bug in cur_bugs:
-                print cmdutil.bug_summary(bug, all_bugs, no_target=no_target,
-                                          shortlist=True),
+                print bug.string(all_bugs, shortlist=True),
     
     list_bugs(bugs, no_target=False)
 
index 786ba294b20865e91a8ea5e4f2a37785d29f82a7..678a607c5d2ac76c858431eedd70eb77c02fb6c7 100644 (file)
@@ -25,7 +25,7 @@ def execute(args):
         raise cmdutil.UserError("Please specify a bug id.")
     bug_dir = cmdutil.bug_tree()
     bug = cmdutil.get_bug(args[0], bug_dir)
-    print cmdutil.bug_summary(bug, list(bug_dir.list())).rstrip("\n")
+    print bug.string().rstrip("\n")
     unique_name = cmdutil.unique_name(bug, bug_dir.list())
     comments = []
     name_map = {}
index 8f7c3a4e58929e0870747b89ab516165eb7fcf5c..f5b12ef0775f41cd19a7cffbca38ff9d99258ebf 100644 (file)
@@ -18,7 +18,6 @@
 import os.path
 import errno
 from libbe import bugdir, rcs, cmdutil
-from libbe.bug import Bug
 
 def execute(args):
     options, args = get_parser().parse_args(args)
@@ -26,7 +25,7 @@ def execute(args):
     for uuid in root.list_uuids():
         old_bug = OldBug(root.bugs_path, uuid)
         
-        new_bug = Bug(root.bugs_path, None)
+        new_bug = root.get_bug(uuid)
         new_bug.uuid = old_bug.uuid
         new_bug.summary = old_bug.summary
         new_bug.creator = old_bug.creator
index b0ebca4265c3796f16931e7e2617ab25011afb1b..02c0d7aee73e2c858db4084e22a28c4e5f6495ed 100644 (file)
@@ -88,7 +88,7 @@ class Bug(object):
     severity = checked_property("severity", severity_values)
     status = checked_property("status", status_values)
 
-    def __init__(self, path, uuid, rcs_name):
+    def __init__(self, path, uuid, rcs_name, bugdir):
         self.path = path
         self.uuid = uuid
         if uuid is not None:
@@ -97,7 +97,8 @@ class Bug(object):
             dict = {}
 
         self.rcs_name = rcs_name
-
+        self.bugdir = bugdir
+        
         self.summary = dict.get("summary")
         self.creator = dict.get("creator")
         self.target = dict.get("target")
@@ -111,6 +112,37 @@ class Bug(object):
     def __repr__(self):
         return "Bug(uuid=%r)" % self.uuid
 
+    def string(self, bugs=None, shortlist=False):
+        if shortlist == False:
+            if bugs == None:
+                bugs = list(self.bugdir.list())
+            htime = utility.handy_time(bug.time)
+            ftime = utility.time_to_str(bug.time)
+            info = [("ID", bug.uuid),
+                    ("Short name", unique_name(bug, bugs)),
+                    ("Severity", bug.severity),
+                    ("Status", bug.status),
+                    ("Assigned", bug.assigned),
+                    ("Target", bug.target),
+                    ("Creator", bug.creator),
+                    ("Created", "%s (%s)" % (htime, ftime))]
+            newinfo = []
+            for k,v in info:
+                if v == None:
+                    newinfo.append((k,""))
+                else:
+                    newinfo.append((k,v))
+            info = newinfo
+            longest_key_len = max([len(k) for k,v in info])
+            infolines = ["  %*s : %s\n" % (longest_key_len,k,v) for k,v in info]
+            return "".join(infolines) + "%s\n" % bug.summary
+        else:
+            statuschar = bug.status[0]
+            severitychar = bug.severity[0]
+            chars = "%c%c" % (statuschar, severitychar)
+            return "%s:%s: %s\n" % (cmdutil.unique_name(bug, bugs), chars, bug.summary)        
+    def __str__(self):
+        return self.string(shortlist=True)
     def get_path(self, file):
         return os.path.join(self.path, self.uuid, file)
 
index 7570bb37f9a632b58f571d28e915b45e059af3ae..f8f45b899d8b0da2ca77a39ea09efe7d8183cceb 100644 (file)
@@ -174,7 +174,7 @@ class BugDir:
         return bugs
 
     def get_bug(self, uuid):
-        return Bug(self.bugs_path, uuid, self.rcs_name)
+        return Bug(self.bugs_path, uuid, self.rcs_name, self)
 
     def list_uuids(self):
         for uuid in os.listdir(self.bugs_path):
@@ -187,7 +187,7 @@ class BugDir:
             uuid = names.uuid()
         path = os.path.join(self.bugs_path, uuid)
         self.rcs.mkdir(path)
-        bug = Bug(self.bugs_path, None, self.rcs_name)
+        bug = Bug(self.bugs_path, None, self.rcs_name, self)
         bug.uuid = uuid
         return bug
 
index 69cfe842f50e481e025a149038c28fa0ee07ec4d..b5a93c7728fe77e8bd640128c3b9ed62fadfbbcc 100644 (file)
@@ -72,29 +72,6 @@ def get_bug(spec, bug_dir=None):
         raise UserError("No bug matches %s" % spec)
     return matches[0]
 
-def bug_summary(bug, bugs, no_target=False, shortlist=False):
-    info = [("ID", bug.uuid),
-            ("Short name", unique_name(bug, bugs)),
-            ("Severity", bug.severity),
-            ("Status", bug.status),
-            ("Assigned", bug.assigned),
-            ("Target", bug.target),
-            ("Creator", bug.creator),
-            ("Created", "%s (%s)" % (utility.handy_time(bug.time),utility.time_to_str(bug.time)))]
-    newinfo = []
-    for k,v in info:
-        if v == None:
-            newinfo.append((k,""))
-        else:
-            newinfo.append((k,v))
-    info = newinfo
-    if shortlist == False:
-        longest_key_len = max([len(k) for k,v in info])
-        infolines = ["  %*s : %s\n" % (longest_key_len,k,v) for k,v in info]
-        return "".join(infolines) + "%s\n" % bug.summary
-    else:
-       return "%s: %s\n" % (unique_name(bug, bugs), bug.summary)
-
 def iter_commands():
     for name, module in plugin.iter_plugins("becommands"):
         yield name.replace("_", "-"), module
index 97eca54c61f6fdd7fda42247e5f12e108acfb690..fb3cfeaf4f40fd243a2f8799e8b3970ceb80ac83 100644 (file)
@@ -54,7 +54,7 @@ def diff_report(diff_data, bug_dir):
     if len(added) > 0: 
         print "New bug reports:"
         for bug in added:
-            print cmdutil.bug_summary(bug, bugs, no_target=True)
+            print bug.string(shortlist=True)
 
     if len(modified) > 0:
         printed = False
@@ -70,7 +70,7 @@ def diff_report(diff_data, bug_dir):
     if len(removed) > 0: 
         print "Removed bug reports:"
         for bug in removed:
-            print cmdutil.bug_summary(bug, bugs, no_target=True)
+            print bug.string(bug, bugs, shortlist=True)
    
 def change_lines(old, new, attributes):
     change_list = []    
@@ -102,7 +102,7 @@ def bug_changes(old, new, bugs):
 
     if len(change_strings) == 0:
         return None
-    return "%s%s\n" % (cmdutil.bug_summary(new, bugs, shortlist=True), 
+    return "%s%s\n" % (new.string(bugs, shortlist=True), 
                        "\n".join(change_strings))