aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/bug.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/bug.py')
-rw-r--r--libbe/bug.py62
1 files changed, 30 insertions, 32 deletions
diff --git a/libbe/bug.py b/libbe/bug.py
index a4ef53d..d211c30 100644
--- a/libbe/bug.py
+++ b/libbe/bug.py
@@ -25,16 +25,8 @@
"""
import copy
-import os
-import os.path
-import errno
-import sys
import time
-import types
-try: # import core module, Python >= 2.5
- from xml.etree import ElementTree
-except ImportError: # look for non-core module
- from elementtree import ElementTree
+from xml.etree import ElementTree
import xml.sax.saxutils
import libbe
@@ -47,7 +39,7 @@ import libbe.storage.util.mapfile as mapfile
import libbe.comment as comment
import libbe.util.utility as utility
-if libbe.TESTING == True:
+if libbe.TESTING:
import doctest
@@ -86,7 +78,7 @@ def load_severities(severity_def):
global severity_values
global severity_description
global severity_index
- if severity_def == None:
+ if severity_def is None:
return
severity_values = tuple([val for val,description in severity_def])
severity_description = dict(severity_def)
@@ -95,6 +87,12 @@ def load_severities(severity_def):
severity_index[severity] = i
load_severities(severity_def)
+
+# https://stackoverflow.com/a/56719588/164233
+def cmp(a, b):
+ return (int(a) > int(b)) - (int(a) < int(b))
+
+
active_status_values = []
inactive_status_values = []
status_values = []
@@ -106,9 +104,9 @@ def load_status(active_status_def, inactive_status_def):
global status_values
global status_description
global status_index
- if active_status_def == None:
+ if active_status_def is None:
active_status_def = globals()["active_status_def"]
- if inactive_status_def == None:
+ if inactive_status_def is None:
inactive_status_def = globals()["inactive_status_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])
@@ -197,7 +195,7 @@ class Bug (settings_object.SavedSettingsObject):
def time_string(): return {}
def _get_time(self):
- if self.time_string == None:
+ if self.time_string is None:
self._cached_time_string = None
self._cached_time = None
return None
@@ -253,7 +251,7 @@ class Bug (settings_object.SavedSettingsObject):
self.uuid = uuid
self.id = libbe.util.id.ID(self, 'bug')
if from_storage == False:
- if uuid == None:
+ if uuid is None:
self.uuid = libbe.util.id.uuid_gen()
self.time = int(time.time()) # only save to second precision
self.summary = summary
@@ -277,7 +275,7 @@ class Bug (settings_object.SavedSettingsObject):
def _setting_attr_string(self, setting):
value = getattr(self, setting)
- if value == None:
+ if value is None:
return ""
if type(value) not in (str,):
return str(value)
@@ -285,7 +283,7 @@ class Bug (settings_object.SavedSettingsObject):
def string(self, shortlist=False, show_comments=False):
if shortlist == False:
- if self.time == None:
+ if self.time is None:
timestring = ""
else:
htime = utility.handy_time(self.time)
@@ -309,7 +307,7 @@ class Bug (settings_object.SavedSettingsObject):
chars = "%c%c" % (statuschar, severitychar)
bugout = "%s:%s: %s" % (self.id.user(),chars,self.summary.rstrip('\n'))
- if show_comments == True:
+ if show_comments:
self.comment_root.sort(cmp=libbe.comment.cmp_time, reverse=True)
comout = self.comment_root.string_thread(flatten=False)
output = bugout + '\n' + comout.rstrip('\n')
@@ -409,7 +407,7 @@ class Bug (settings_object.SavedSettingsObject):
</comment>
</bug>
"""
- if self.time == None:
+ if self.time is None:
timestring = ""
else:
timestring = utility.time_to_str(self.time)
@@ -429,7 +427,7 @@ class Bug (settings_object.SavedSettingsObject):
lines.append(' <%s>%s</%s>' % (k,xml.sax.saxutils.escape(v),k))
for estr in self.extra_strings:
lines.append(' <extra-string>%s</extra-string>' % estr)
- if show_comments == True:
+ if show_comments:
comout = self.comment_root.xml_thread(indent=indent+2)
if comout:
comout = comout[indent:] # strip leading indent spaces
@@ -588,7 +586,7 @@ class Bug (settings_object.SavedSettingsObject):
default parent via default_parent.
"""
uuid_map = {}
- if default_parent == None:
+ if default_parent is None:
default_parent = self.comment_root
for c in list(self.comments()) + comments:
assert c.uuid != None
@@ -609,7 +607,7 @@ class Bug (settings_object.SavedSettingsObject):
try:
parent = uuid_map[c.in_reply_to]
except KeyError:
- if ignore_missing_references == True:
+ if ignore_missing_references:
libbe.LOG.warning(
'ignoring missing reference to {0}'.format(
c.in_reply_to))
@@ -715,9 +713,9 @@ class Bug (settings_object.SavedSettingsObject):
).format(attr, old, new, self.uuid))
for estr in other.extra_strings:
if not estr in self.extra_strings:
- if accept_extra_strings == True:
+ if accept_extra_strings:
self.extra_strings += [estr]
- elif change_exception == True:
+ elif change_exception:
raise ValueError('Merge would add extra string "%s" for bug %s' \
% (estr, self.uuid))
for o_comm in other.comments():
@@ -728,13 +726,13 @@ class Bug (settings_object.SavedSettingsObject):
s_comm = self.comment_root.comment_from_uuid(o_comm.alt_id)
except KeyError as e:
s_comm = None
- if s_comm == None:
- if accept_comments == True:
+ if s_comm is None:
+ if accept_comments:
o_comm_copy = copy.copy(o_comm)
o_comm_copy.bug = self
o_comm_copy.id = libbe.util.id.ID(o_comm_copy, 'comment')
self.comment_root.add_reply(o_comm_copy)
- elif change_exception == True:
+ elif change_exception:
raise ValueError('Merge would add comment %s (alt: %s) to bug %s' \
% (o_comm.uuid, o_comm.alt_id, self.uuid))
else:
@@ -745,7 +743,7 @@ class Bug (settings_object.SavedSettingsObject):
# methods for saving/loading/acessing settings and properties.
def load_settings(self, settings_mapfile=None):
- if settings_mapfile == None:
+ if settings_mapfile is None:
settings_mapfile = self.storage.get(
self.id.storage('values'), '{}\n')
try:
@@ -782,7 +780,7 @@ class Bug (settings_object.SavedSettingsObject):
comment.save_comments(self)
def load_comments(self, load_full=True):
- if load_full == True:
+ if load_full:
# Force a complete load of the whole comment tree
self.comment_root = self._get_comment_root(load_full=True)
else:
@@ -895,8 +893,8 @@ def cmp_attr(bug_1, bug_2, attr, invert=False):
return 1
val_1 = getattr(bug_1, attr)
val_2 = getattr(bug_2, attr)
- if val_1 == None: val_1 = None
- if val_2 == None: val_2 = None
+ if val_1 is None: val_1 = None
+ if val_2 is None: val_2 = None
if invert == True :
return -cmp(val_1, val_2)
@@ -970,5 +968,5 @@ def cmp_last_modified(bug_1, bug_2):
return -cmp(val_1, val_2)
-if libbe.TESTING == True:
+if libbe.TESTING:
suite = doctest.DocTestSuite()