Per-tree settings now passed into bug module.
authorW. Trevor King <wking@drexel.edu>
Thu, 4 Dec 2008 14:54:39 +0000 (09:54 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 4 Dec 2008 14:54:39 +0000 (09:54 -0500)
becommands/severity gets the configured settings appropriately.

Todo:
  adjust setting-validation to compare against the current values.
  setup becommands/severity to --complete severities.

.be/settings
becommands/severity.py
libbe/bug.py
libbe/bugdir.py

index 331e353d9e4c3dcb3643e949ef9f0eeb0254745b..26f81cdddbd148040849e096465b877861d52384 100644 (file)
@@ -5,6 +5,8 @@ severities:
   description: A feature that could improve usefulness, but not a bug.
 - name: minor
   description: The standard bug level.
+- name: moderate
+  description: Yet another bug severity.
 - name: serious
   description: A bug that requires workarounds.
 - name: critical
index 7b7ee29d0b963c38ad1a530e0149479e96f024cd..92f31e8aad519e7425e9d8695ca215d2425ed5ff 100644 (file)
@@ -15,8 +15,7 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Show or change a bug's severity level"""
-from libbe import cmdutil, bugdir
-from libbe.bug import severity_values, severity_description
+from libbe import cmdutil, bugdir, bug
 __desc__ = __doc__
 
 def execute(args, test=False):
@@ -56,7 +55,8 @@ def get_parser():
     parser = cmdutil.CmdOptionParser("be severity BUG-ID [SEVERITY]")
     return parser
 
-longhelp=["""
+def help():
+    longhelp=["""
 Show or change a bug's severity level.
 
 If no severity is specified, the current value is printed.  If a severity level
@@ -64,13 +64,14 @@ is specified, it will be assigned to the bug.
 
 Severity levels are:
 """]
-longest_severity_len = max([len(s) for s in severity_values])
-for severity in severity_values :
-    description = severity_description[severity]
-    s = "%*s : %s\n" % (longest_severity_len, severity, description)
-    longhelp.append(s)
-longhelp = ''.join(longhelp)
-
-
-def help():
+    try:
+        bd = bugdir.BugDir(from_disk=True, manipulate_encodings=False)
+    except bugdir.NoBugDir, e:
+        pass
+    longest_severity_len = max([len(s) for s in bug.severity_values])
+    for severity in bug.severity_values :
+        description = bug.severity_description[severity]
+        s = "%*s : %s\n" % (longest_severity_len, severity, description)
+        longhelp.append(s)
+    longhelp = ''.join(longhelp)
     return get_parser().help_str() + longhelp
index b98067f7f60c895985596f20bc2f04bf5cf72dee..46f244f46bec2c94f562828aef595149b01817cf 100644 (file)
@@ -34,8 +34,8 @@ import utility
 # Use a tuple of (category, description) tuples since we don't have
 # ordered dicts in Python yet http://www.python.org/dev/peps/pep-0372/
 
-# in order of increasing severity
-severity_level_def = (
+# in order of increasing severity.  (name, description) pairs
+severity_def = (
   ("wishlist","A feature that could improve usefulness, but not a bug."),
   ("minor","The standard bug level."),
   ("serious","A bug that requires workarounds."),
@@ -58,11 +58,23 @@ inactive_status_def = (
 
 ### Convert the description tuples to more useful formats
 
-severity_values = tuple([val for val,description in severity_level_def])
-severity_description = dict(severity_level_def)
+severity_values = ()
+severity_description = {}
 severity_index = {}
-for i in range(len(severity_values)):
-    severity_index[severity_values[i]] = i
+def load_severities(severity_def):
+    global severity_values
+    global severity_description
+    global severity_index
+    if type(severity_def[0]) == dict:
+        # Convert {"name": "X", "description": "Y"} severities to ("X","Y").
+        # The dict form is loaded from the per-tree settings file.
+        severity_def = [(d["name"], d["description"]) for d in severity_def]
+    severity_values = tuple([val for val,description in severity_def])
+    severity_description = dict(severity_def)
+    severity_index = {}
+    for i,severity in enumerate(severity_values):
+        severity_index[severity] = i
+load_severities(severity_def)
 
 active_status_values = tuple(val for val,description in active_status_def)
 inactive_status_values = tuple(val for val,description in inactive_status_def)
index d554ebe274234b3286aff2705698ba4ca3321e5d..cdb4cf5a2ae349e683c47661cd6d2db608c889b8 100644 (file)
@@ -218,8 +218,15 @@ settings easy.  Don't set this attribute.  Set .rcs instead, and
     @doc_property(doc="A dict of (bug-uuid, bug-instance) pairs.")
     def _bug_map(): return {}
 
+    def _setup_severities(self, severities):
+        if severities != None and severities != settings_object.EMPTY:
+            bug.load_severities(severities)
+    def _set_severities(self, old_severities, new_severities):
+        self._setup_severities(new_severities)
+        self._prop_save_settings(old_severities, new_severities)
     @_versioned_property(name="severities",
-                         doc="The allowed bug severities and their descriptions.")
+                         doc="The allowed bug severities and their descriptions.",
+                         change_hook=_set_severities)
     def severities(): return {}
 
 
@@ -322,6 +329,7 @@ settings easy.  Don't set this attribute.  Set .rcs instead, and
             
             self.rcs = rcs.rcs_by_name(self.rcs_name)
             self._setup_encoding(self.encoding)
+            self._setup_severities(self.severities)
 
     def load_all_bugs(self):
         "Warning: this could take a while."