--- /dev/null
+
+
+
+creator=W. Trevor King <wking@drexel.edu>
+
+
+
+
+
+
+severity=critical
+
+
+
+
+
+
+status=fixed
+
+
+
+
+
+
+summary=Slow be commands due to bugdir loading, go back to lazy bug loading.
+
+
+
+
+
+
+time=Sun, 23 Nov 2008 13:48:01 +0000
+
+
+
True
>>> execute(["a"])
- >>> bd.load()
- >>> bd.bug_from_shortname("a").assigned == bd.rcs.get_user_id()
+ >>> bd._clear_bugs()
+ >>> bd.bug_from_shortname("a").assigned == bd.user_id
True
>>> execute(["a", "someone"])
- >>> bd.load()
+ >>> bd._clear_bugs()
>>> print bd.bug_from_shortname("a").assigned
someone
>>> execute(["a","none"])
- >>> bd.load()
+ >>> bd._clear_bugs()
>>> bd.bug_from_shortname("a").assigned is None
True
"""
if len(args) > 2:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
if len(args) == 1:
- bug.assigned = bug.rcs.get_user_id()
+ bug.assigned = bd.user_id
elif len(args) == 2:
if args[1] == "none":
bug.assigned = None
>>> print bd.bug_from_shortname("a").status
open
>>> execute(["a"])
- >>> bd.load()
+ >>> bd._clear_bugs()
>>> print bd.bug_from_shortname("a").status
closed
"""
if len(args) > 1:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
bug.status = "closed"
bd.save()
>>> bd = bugdir.simple_bug_dir()
>>> os.chdir(bd.root)
>>> execute(["a", "This is a comment about a"])
- >>> bd.load()
- >>> comment = bd.bug_from_shortname("a").comment_root[0]
+ >>> bd._clear_bugs()
+ >>> bug = bd.bug_from_shortname("a")
+ >>> bug.load_comments()
+ >>> comment = bug.comment_root[0]
>>> print comment.body
This is a comment about a
<BLANKLINE>
- >>> comment.From == bd.rcs.get_user_id()
+ >>> comment.From == bd.user_id
True
>>> comment.time <= int(time.time())
True
>>> os.environ["EDITOR"] = "echo 'I like cheese' > "
>>> execute(["b"])
- >>> bd.load()
- >>> print bd.bug_from_shortname("b").comment_root[0].body
+ >>> bd._clear_bugs()
+ >>> bug = bd.bug_from_shortname("b")
+ >>> bug.load_comments()
+ >>> comment = bug.comment_root[0]
+ >>> print comment.body
I like cheese
<BLANKLINE>
"""
bugname = shortname
is_reply = False
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(bugname)
+ bug.load_comments()
if is_reply:
parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname)
else:
if len(args) > 1:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
if bd.rcs.versioned == False:
print "This directory is not revision-controlled."
else:
if len(args) > 0:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
+ bd.load_all_bugs()
# select status
if options.status != None:
if options.status == "all":
assigned = "all"
for i in range(len(assigned)):
if assigned[i] == '-':
- assigned[i] = bd.rcs.get_user_id()
+ assigned[i] = bd.user_id
# select target
if options.target != None:
if options.target == "all":
options, args = get_parser().parse_args(args)
if len(args) != 1:
raise cmdutil.UserError("Please supply a summary message")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.new_bug(summary=args[0])
bd.save()
print "Created bug with ID %s" % bd.bug_shortname(bug)
>>> print bd.bug_from_shortname("b").status
closed
>>> execute(["b"])
- >>> bd.load()
+ >>> bd._clear_bugs()
>>> print bd.bug_from_shortname("b").status
open
"""
if len(args) > 1:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
bug.status = "open"
bd.save()
closed
>>> execute (["b"])
Removed bug b
- >>> bd.load()
+ >>> bd._clear_bugs()
>>> try:
... bd.bug_from_shortname("b")
... except KeyError:
options, args = get_parser().parse_args(args)
if len(args) != 1:
raise cmdutil.UserError("Please specify a bug id.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
bd.remove_bug(bug)
bd.save()
if len(args) > 2:
help()
raise cmdutil.UserError("Too many arguments.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
if len(args) == 0:
keys = bd.settings.keys()
keys.sort()
pass
#raise cmdutil.UserError, "No such directory: %s" % basedir
try:
- bd = bugdir.BugDir(basedir, loadNow=False, sink_to_existing_root=False, assert_new_BugDir=True)
+ bd = bugdir.BugDir(basedir, from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True)
except bugdir.NoRootEntry:
raise cmdutil.UserError("No such directory: %s" % basedir)
except bugdir.AlreadyInitialized:
if len(args) not in (1,2):
print help()
return
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
if len(args) == 1:
print bug.severity
options, args = get_parser().parse_args(args)
if len(args) == 0:
raise cmdutil.UserError("Please specify a bug id.")
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
for bugid in args:
bug = bd.bug_from_shortname(bugid)
print bug.string(show_comments=True)
if len(args) not in (1,2):
print help()
return
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
if len(args) == 1:
print bug.status
if len(args) == 0:
print help()
return
- bd = bugdir.BugDir(loadNow=True)
+ bd = bugdir.BugDir(from_disk=True)
bug = bd.bug_from_shortname(args[0])
if len(args) == 1:
if bug.target is None:
active = property(_get_active)
- def __init__(self, bugdir=None, uuid=None, loadNow=False, summary=None):
+ def __init__(self, bugdir=None, uuid=None, from_disk=False,
+ load_comments=False, summary=None):
self.bugdir = bugdir
if bugdir != None:
self.rcs = bugdir.rcs
else:
self.rcs = None
- if loadNow == True:
+ if from_disk == True:
+ self._comments_loaded = False
self.uuid = uuid
- self.load()
+ self.load(load_comments=load_comments)
else:
# Note: defaults should match those in Bug.load()
+ self._comments_loaded = True
if uuid != None:
self.uuid = uuid
else:
bugout = "%s:%s: %s" % (shortname, chars, self.summary.rstrip('\n'))
if show_comments == True:
+ if self._comments_loaded == False:
+ self.load_comments()
comout = self.comment_root.string_thread(auto_name_map=True,
bug_shortname=shortname)
output = bugout + '\n' + comout.rstrip('\n')
assert name in ["values", "comments"]
return os.path.join(my_dir, name)
- def load(self):
+ def load(self, load_comments=False):
map = mapfile.map_load(self.get_path("values"))
self.summary = map.get("summary")
self.creator = map.get("creator")
self.time = map.get("time")
if self.time is not None:
self.time = utility.str_to_time(self.time)
-
+
+ if load_comments == True:
+ self.load_comments()
+
+ def load_comments(self):
self.comment_root = comment.loadComments(self)
+ self._comments_loaded = True
def _add_attr(self, map, name):
value = getattr(self, name)
path = self.get_path("values")
mapfile.map_save(self.rcs, path, map)
- if len(self.comment_root) > 0:
- self.rcs.mkdir(self.get_path("comments"))
- comment.saveComments(self)
+ if self._comments_loaded:
+ if len(self.comment_root) > 0:
+ self.rcs.mkdir(self.get_path("comments"))
+ comment.saveComments(self)
def remove(self):
+ self.load_comments()
self.comment_root.remove()
path = self.get_path()
self.rcs.recursive_remove(path)
be flushed to the file system automatically. However, the BugDir
will only load information from the file system when it loads new
bugs/comments that it doesn't already have in memory, or when it
- explicitly asked to do so (e.g. .load() or __init__(loadNow=True)).
+ explicitly asked to do so (e.g. .load() or __init__(from_disk=True)).
"""
def __init__(self, root=None, sink_to_existing_root=True,
assert_new_BugDir=False, allow_rcs_init=False,
- loadNow=False, rcs=None):
+ from_disk=False, rcs=None):
list.__init__(self)
self._save_user_id = False
self.settings = {}
if not os.path.exists(root):
raise NoRootEntry(root)
self.root = root
- if loadNow == True:
+ if from_disk == True:
self.load()
else:
if assert_new_BugDir == True:
self.settings = self._get_settings(self.get_path("settings"))
self.rcs = rcs_by_name(self.rcs_name)
- if self._user_id != None: # there was a user name in the settings file
- self.save_user_id()
-
- self._clear_bugs()
- for uuid in self.list_uuids():
- self._load_bug(uuid)
+ if self._user_id != None: # was a user name in the settings file
+ self.save_user_id()
self._bug_map_gen()
+ def load_all_bugs(self):
+ "Warning: this could take a while."
+ self._clear_bugs()
+ for uuid in self.list_uuids():
+ self._load_bug(uuid)
+
def save(self):
self.rcs.mkdir(self.get_path())
self.set_version()
duplicate_settings["user-id"] = self.user_id
self._save_settings(duplicate_settings_path, duplicate_settings)
- return BugDir(duplicate_path, loadNow=True)
+ return BugDir(duplicate_path, from_disk=True)
def remove_duplicate_bugdir(self):
self.rcs.remove_duplicate_repo()
map = {}
for bug in self:
map[bug.uuid] = bug
+ for uuid in self.list_uuids():
+ if uuid not in map:
+ map[uuid] = None
self.bug_map = map
def list_uuids(self):
self.pop()
def _load_bug(self, uuid):
- bg = bug.Bug(bugdir=self, uuid=uuid, loadNow=True)
+ bg = bug.Bug(bugdir=self, uuid=uuid, from_disk=True)
self.append(bg)
self._bug_map_gen()
return bg
a:om: Bug A
"""
matches = []
- for bug in self:
- if bug.uuid.startswith(shortname):
- matches.append(bug)
+ self._bug_map_gen()
+ for uuid in self.bug_map.keys():
+ if uuid.startswith(shortname):
+ matches.append(uuid)
if len(matches) > 1:
- raise cmdutil.UserError("More than one bug matches %s. Please be more"
- " specific." % shortname)
+ raise cmdutil.UserError("More than one bug matches %s. "
+ "Please be more specific." % shortname)
if len(matches) == 1:
- return matches[0]
+ return self.bug_from_uuid(matches[0])
raise KeyError("No bug matches %s" % shortname)
def bug_from_uuid(self, uuid):
self._bug_map_gen()
if uuid not in self.bug_map:
raise KeyError("No bug matches %s" % uuid +str(self.bug_map)+str(self))
+ if self.bug_map[uuid] == None:
+ self._load_bug(uuid)
return self.bug_map[uuid]
for uuid in os.listdir(path):
if uuid.startswith('.'):
continue
- comm = Comment(bug, uuid, loadNow=True)
+ comm = Comment(bug, uuid, from_disk=True)
comments.append(comm)
return _list_to_root(comments, bug)
comment.save()
class Comment(Tree):
- def __init__(self, bug=None, uuid=None, loadNow=False,
+ def __init__(self, bug=None, uuid=None, from_disk=False,
in_reply_to=None, body=None):
"""
- Set loadNow=True to load an old bug.
- Set loadNow=False to create a new bug.
+ Set from_disk=True to load an old bug.
+ Set from_disk=False to create a new bug.
- The uuid option is required when loadNow==True.
+ The uuid option is required when from_disk==True.
The in_reply_to and body options are only used if
- loadNow==False (the default). When loadNow==True, they are
+ from_disk==False (the default). When from_disk==True, they are
loaded from the bug database.
in_reply_to should be the uuid string of the parent comment.
self.rcs = bug.rcs
else:
self.rcs = None
- if loadNow == True:
+ if from_disk == True:
self.uuid = uuid
self.load()
else:
added = []
removed = []
modified = []
- for old_bug in old_bugdir:
- new_bug = new_bugdir.bug_map.get(old_bug.uuid)
- if new_bug is None :
- removed.append(old_bug)
- else:
+ for uuid in old_bugdir.list_uuids():
+ old_bug = old_bugdir.bug_from_uuid(uuid)
+ try:
+ new_bug = new_bugdir.bug_from_uuid(uuid)
if old_bug != new_bug:
modified.append((old_bug, new_bug))
- for new_bug in new_bugdir:
+ except KeyError:
+ removed.append(old_bug)
+ for uuid in new_bugdir.list_uuids():
if not old_bugdir.bug_map.has_key(new_bug.uuid):
+ new_bug = new_bugdir.bug_from_uuid(uuid)
added.append(new_bug)
return (removed, modified, added)
change_list = change_lines(old, new, ("time", "creator", "severity",
"target", "summary", "status", "assigned"))
+ old.load_comments()
old_comment_ids = [c.uuid for c in old.comment_root.traverse()]
+ new.load_comments()
new_comment_ids = [c.uuid for c in new.comment_root.traverse()]
change_strings = ["%s: %s -> %s" % f for f in change_list]
for comment_id in new_comment_ids: