def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> bd.bug_from_shortname("a").assigned is None
True
>>> bd._clear_bugs()
>>> bd.bug_from_shortname("a").assigned is None
True
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
"""
>>> from libbe import bugdir
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> print bd.bug_from_shortname("a").status
open
>>> bd._clear_bugs()
>>> print bd.bug_from_shortname("a").status
closed
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import time
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute(["a", "This is a comment about a"], manipulate_encodings=False)
>>> bd._clear_bugs()
>>> print comment.body
I like cheese
<BLANKLINE>
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
"""
>>> import os, time
>>> from libbe import bug
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> full_path = "testfile"
>>> test_contents = "A test file"
>>> bd.rcs.set_file_contents(full_path, test_contents)
>>> execute(["Added %s." % (full_path)], manipulate_encodings=False) # doctest: +ELLIPSIS
Committed ...
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> from libbe import utility
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> bd.save()
>>> os.chdir(bd.root)
>>> execute(["a", "b"], manipulate_encodings=False)
Blocks on a:
b closed
>>> execute(["-r", "a", "b"], manipulate_encodings=False)
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> bd.set_sync_with_disk(True)
>>> original = bd.rcs.commit("Original status")
>>> bug = bd.bug_from_uuid("a")
... else:
... print "This directory is not revision-controlled."
This directory is not revision-controlled.
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute([], manipulate_encodings=False)
a:om: Bug A
>>> execute(["--status", "all"], manipulate_encodings=False)
a:om: Bug A
b:cm: Bug B
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> from libbe import utility
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> bd.set_sync_with_disk(True)
>>> a = bd.bug_from_shortname("a")
>>> a.comment_root.time = 0
Merged into bug a
>>> print b.status
closed
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
"""
>>> import os, time
>>> from libbe import bug
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> bug.uuid_gen = lambda: "X"
>>> execute (["this is a test",], manipulate_encodings=False)
Created bug with ID X
- >>> bd.load()
+ >>> bd.load() # breaks simple bug dir rcs for cleanup!
>>> bug = bd.bug_from_uuid("X")
>>> print bug.summary
this is a test
minor
>>> bug.target == None
True
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> print bd.bug_from_shortname("b").status
closed
>>> bd._clear_bugs()
>>> print bd.bug_from_shortname("b").status
open
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
"""
>>> from libbe import mapfile
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> print bd.bug_from_shortname("b").status
closed
... except bugdir.NoBugMatches:
... print "Bug not found"
Bug not found
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute(["target"], manipulate_encodings=False)
None
>>> execute(["target", "none"], manipulate_encodings=False)
>>> execute(["target"], manipulate_encodings=False)
None
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute(["a"], manipulate_encodings=False)
minor
>>> execute(["a", "none"], manipulate_encodings=False)
Traceback (most recent call last):
UserError: Invalid severity level: none
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute (["a",], manipulate_encodings=False) # doctest: +ELLIPSIS
ID : a
<created>...</created>
<summary>Bug A</summary>
</bug>
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute(["a"], manipulate_encodings=False)
open
>>> execute(["a", "none"], manipulate_encodings=False)
Traceback (most recent call last):
UserError: Invalid status: none
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> bd.set_sync_with_disk(True)
>>> os.chdir(bd.root)
>>> a = bd.bug_from_shortname("a")
>>> execute(["-s","Jane Doe <J@doe.com>", "DIR"], manipulate_encodings=False) # doctest: +NORMALIZE_WHITESPACE
Subscriptions for bug directory:
Jane Doe <J@doe.com> all *
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
where id is either a bug.uuid (in the case of a bug subscription)
or "DIR" (in the case of a bugdir subscription).
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir(sync_with_disk=False)
>>> a = bd.bug_from_shortname("a")
>>> bd.extra_strings = subscribe(bd.extra_strings, "John Doe <j@doe.com>", [BUGDIR_TYPE_ALL], ["a.com"], BUGDIR_TYPE_ALL)
>>> bd.extra_strings = subscribe(bd.extra_strings, "Jane Doe <J@doe.com>", [BUGDIR_TYPE_NEW], ["*"], BUGDIR_TYPE_ALL)
[<SubscriptionType: all>]
>>> get_bugdir_subscribers(bd, "b.net")
{'Jane Doe <J@doe.com>': {'DIR': [<SubscriptionType: new>]}}
+ >>> bd.cleanup()
"""
subscribers = {}
for sub in get_subscribers(bugdir.extra_strings, BUGDIR_TYPE_ALL, server,
def execute(args, manipulate_encodings=True):
"""
>>> from libbe import utility
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> bd.set_sync_with_disk(True)
>>> os.chdir(bd.root)
>>> a = bd.bug_from_shortname("a")
Tags for a:
Alphabetically first
>>> execute(["--remove", "a", "Alphabetically first"], manipulate_encodings=False)
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
def execute(args, manipulate_encodings=True):
"""
>>> import os
- >>> bd = bugdir.simple_bug_dir()
+ >>> bd = bugdir.SimpleBugDir()
>>> os.chdir(bd.root)
>>> execute(["a"], manipulate_encodings=False)
No target assigned.
>>> execute(["a", "none"], manipulate_encodings=False)
>>> execute(["a"], manipulate_encodings=False)
No target assigned.
+ >>> bd.cleanup()
"""
parser = get_parser()
options, args = parser.parse_args(args)
self._create_project(path)
self._add_project_code(path)
def _create_archive(self, path):
- # Create a new archive
+ """
+ Create a temporary Arch archive in the directory PATH. This
+ archive will be removed by
+ __del__->cleanup->_rcs_cleanup->_remove_archive
+ """
# http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive
assert self._archive_name == None
id = self.get_user_id()
self.rcs = rcs
self._setup_user_id(self.user_id)
+ def __del__(self):
+ self.cleanup()
+
+ def cleanup(self):
+ self.rcs.cleanup()
+
# methods for getting the BugDir situated in the filesystem
def _find_root(self, path):
def bug_from_shortname(self, shortname):
"""
- >>> bd = simple_bug_dir(sync_with_disk=False)
+ >>> bd = SimpleBugDir(sync_with_disk=False)
>>> bug_a = bd.bug_from_shortname('a')
>>> print type(bug_a)
<class 'libbe.bug.Bug'>
>>> print bug_a
a:om: Bug A
+ >>> bd.cleanup()
"""
matches = []
self._bug_map_gen()
return True
-def simple_bug_dir(sync_with_disk=True):
+class SimpleBugDir (BugDir):
"""
For testing. Set sync_with_disk==False for a memory-only bugdir.
- >>> bugdir = simple_bug_dir()
+ >>> bugdir = SimpleBugDir()
>>> uuids = list(bugdir.list_uuids())
>>> uuids.sort()
>>> print uuids
['a', 'b']
+ >>> bugdir.cleanup()
"""
- if sync_with_disk == True:
- dir = utility.Dir()
- assert os.path.exists(dir.path)
- root = dir.path
- assert_new_BugDir = True
- rcs_init = True
- else:
- root = "/"
- assert_new_BugDir = False
- rcs_init = False
- bugdir = BugDir(root, sink_to_existing_root=False,
+ def __init__(self, sync_with_disk=True):
+ if sync_with_disk == True:
+ dir = utility.Dir()
+ assert os.path.exists(dir.path)
+ root = dir.path
+ assert_new_BugDir = True
+ rcs_init = True
+ else:
+ root = "/"
+ assert_new_BugDir = False
+ rcs_init = False
+ BugDir.__init__(self, root, sink_to_existing_root=False,
assert_new_BugDir=assert_new_BugDir,
allow_rcs_init=rcs_init,
manipulate_encodings=False)
- if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
- bugdir._dir_ref = dir
- bug_a = bugdir.new_bug("a", summary="Bug A")
- bug_a.creator = "John Doe <jdoe@example.com>"
- bug_a.time = 0
- bug_b = bugdir.new_bug("b", summary="Bug B")
- bug_b.creator = "Jane Doe <jdoe@example.com>"
- bug_b.time = 0
- bug_b.status = "closed"
- if sync_with_disk == True:
- bugdir.save()
- bugdir.set_sync_with_disk(True)
- return bugdir
-
+ if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
+ self._dir_ref = dir
+ bug_a = self.new_bug("a", summary="Bug A")
+ bug_a.creator = "John Doe <jdoe@example.com>"
+ bug_a.time = 0
+ bug_b = self.new_bug("b", summary="Bug B")
+ bug_b.creator = "Jane Doe <jdoe@example.com>"
+ bug_b.time = 0
+ bug_b.status = "closed"
+ if sync_with_disk == True:
+ self.save()
+ self.set_sync_with_disk(True)
+ def cleanup(self):
+ if hasattr(self, "_dir_ref"):
+ self._dir_ref.cleanup()
+ BugDir.cleanup(self)
class BugDirTestCase(unittest.TestCase):
def setUp(self):
allow_rcs_init=True)
self.rcs = self.bugdir.rcs
def tearDown(self):
- self.rcs.cleanup()
+ self.bugdir.cleanup()
self.dir.cleanup()
def fullPath(self, path):
return os.path.join(self.dir.path, path)
self.bugdir.save()
def tearDown(self):
os.chdir(self.original_working_dir)
+ self.bugdir.cleanup()
self.dir.cleanup()
def testOnDiskCleanLoad(self):
- """simple_bug_dir(sync_with_disk==True) should not import preexisting bugs."""
- bugdir = simple_bug_dir(sync_with_disk=True)
+ """SimpleBugDir(sync_with_disk==True) should not import preexisting bugs."""
+ bugdir = SimpleBugDir(sync_with_disk=True)
self.failUnless(bugdir.sync_with_disk==True, bugdir.sync_with_disk)
uuids = sorted([bug.uuid for bug in bugdir])
self.failUnless(uuids == ['a', 'b'], uuids)
bugdir.load_all_bugs()
uuids = sorted([bug.uuid for bug in bugdir])
self.failUnless(uuids == ['a', 'b'], uuids)
+ bugdir.cleanup()
def testInMemoryCleanLoad(self):
- """simple_bug_dir(sync_with_disk==False) should not import preexisting bugs."""
- bugdir = simple_bug_dir(sync_with_disk=False)
+ """SimpleBugDir(sync_with_disk==False) should not import preexisting bugs."""
+ bugdir = SimpleBugDir(sync_with_disk=False)
self.failUnless(bugdir.sync_with_disk==False, bugdir.sync_with_disk)
uuids = sorted([bug.uuid for bug in bugdir])
self.failUnless(uuids == ['a', 'b'], uuids)
bugdir._clear_bugs()
uuids = sorted([bug.uuid for bug in bugdir])
self.failUnless(uuids == [], uuids)
-
+ bugdir.cleanup()
unitsuite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])
"""
Difference tree generator for BugDirs.
>>> import copy
- >>> bd = bugdir.simple_bug_dir(sync_with_disk=False)
+ >>> bd = bugdir.SimpleBugDir(sync_with_disk=False)
>>> bd.user_id = "John Doe <j@doe.com>"
>>> bd_new = copy.deepcopy(bd)
>>> bd_new.target = "1.0"
New comments:
from John Doe <j@doe.com> on Thu, 01 Jan 1970 00:00:00 +0000
I'm closing this bug...
+ >>> bd.cleanup()
"""
def __init__(self, old_bugdir, new_bugdir):
self.old_bugdir = old_bugdir