From 19b153b9a86377a2b30cc80fa3f475fed892e2fe Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 18 Nov 2008 20:42:50 -0500 Subject: Major rewrite of RCS backends. RCS now represented as a class. Lots of changes and just one commit. This started with bug dac91856-cb6a-4f69-8c03-38ff0b29aab2, when I noticed that new bugs were not being added appropriately with the Git backend. I'd been working with Git trouble before with bug 0cad2ac6-76ef-4a88-abdf-b2e02de76f5c, and decided things would be better off if I just scrapped the current RCS architecture and went to a more object oriented setup. So I did. It's not clear how to add support for an RCS backend: * Create a new module that - defines an inheritor of rsc.RCS, overriding the _rcs_*() methods - provide a new() function for instantizating the new class - defines an inheritor of rcs.RCStestCase, overiding the Class attribute - defines 'suite' a unittest.TestSuite testing the module * Add your new module to the rest in rcs._get_matching_rcs() * Add your new module to the rest in libbe/tests.py Although I'm not sure libbe/tests.py is still usefull. The new framework clears out a bunch of hackery that used to be involved with supporting becommands/diff.py. There's still room for progress though. While implementing the new verision, I moved the testing framework over from doctest to a doctest/unittest combination. Longer tests that don't demonstrate a function's usage should be moved to unittests at the end of the module, since unittest has better support for setup/teardown, etc. The new framework also revealed some underimplented backends, most notably arch. These backends have now been fixed. I also tweaked the test_usage.sh script to run through all the backends if it is called with no arguments. The fix for the dac bug turned out to be an unflushed file write :p. --- becommands/assign.py | 11 +++++------ becommands/close.py | 5 ++--- becommands/comment.py | 9 ++++----- becommands/list.py | 5 +++-- becommands/new.py | 13 ++++++------- becommands/open.py | 5 ++--- becommands/remove.py | 8 +++----- becommands/set.py | 5 ++--- becommands/set_root.py | 35 ++++++++++++++++++++--------------- becommands/severity.py | 5 ++--- becommands/status.py | 5 ++--- becommands/target.py | 4 +--- becommands/upgrade.py | 3 +++ 13 files changed, 55 insertions(+), 58 deletions(-) (limited to 'becommands') diff --git a/becommands/assign.py b/becommands/assign.py index d595c1d..3513ab1 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -15,19 +15,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Assign an individual or group to fix a bug""" -from libbe import cmdutil, names +from libbe import cmdutil __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests, names + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> dir.get_bug("a").assigned is None True >>> execute(["a"]) - >>> dir.get_bug("a").assigned == names.creator() + >>> dir.get_bug("a").assigned == dir.rcs.get_user_id() True >>> execute(["a", "someone"]) >>> dir.get_bug("a").assigned @@ -35,7 +35,6 @@ def execute(args): >>> execute(["a","none"]) >>> dir.get_bug("a").assigned is None True - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) assert(len(args) in (0, 1, 2)) @@ -44,7 +43,7 @@ def execute(args): return bug = cmdutil.get_bug(args[0]) if len(args) == 1: - bug.assigned = names.creator() + bug.assigned = bug.rcs.get_user_id() elif len(args) == 2: if args[1] == "none": bug.assigned = None diff --git a/becommands/close.py b/becommands/close.py index 8e62b90..9e6987c 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -20,16 +20,15 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> dir.get_bug("a").status u'open' >>> execute(["a"]) >>> dir.get_bug("a").status u'closed' - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) !=1: diff --git a/becommands/comment.py b/becommands/comment.py index 5939490..b2dad4e 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -15,22 +15,22 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Add a comment to a bug""" -from libbe import cmdutil, names, utility +from libbe import cmdutil, utility from libbe.bug import new_comment import os __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests, names + >>> from libbe import bugdir >>> import os, time - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> execute(["a", "This is a comment about a"]) >>> comment = dir.get_bug("a").list_comments()[0] >>> comment.body u'This is a comment about a\\n' - >>> comment.From == names.creator() + >>> comment.From == dir.rcs.get_user_id() True >>> comment.time <= int(time.time()) True @@ -45,7 +45,6 @@ def execute(args): >>> execute(["b"]) >>> dir.get_bug("b").list_comments()[0].body u'I like cheese\\n' - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) < 1: diff --git a/becommands/list.py b/becommands/list.py index 59eb8ad..8fd830b 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -109,7 +109,7 @@ def execute(args): if title != None: print cmdutil.underlined(title) for bug in cur_bugs: - print bug.string(all_bugs, shortlist=True), + print bug.string(all_bugs, shortlist=True) list_bugs(bugs, no_target=False) @@ -137,7 +137,8 @@ def get_parser(): short = "-%c" % s[0] long = "--%s" % s[1] help = s[2] - parser.add_option(short, long, action="store_true", dest=attr, help=help) + parser.add_option(short, long, action="store_true", + dest=attr, help=help) return parser longhelp=""" diff --git a/becommands/new.py b/becommands/new.py index 40ab3f5..d09d048 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -15,20 +15,20 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Create a new bug""" -from libbe import cmdutil, names, utility +from libbe import cmdutil, names from libbe.bug import new_bug __desc__ = __doc__ def execute(args): """ >>> import os, time - >>> from libbe import tests - >>> dir = tests.bug_arch_dir() + >>> from libbe import bugdir + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) - >>> names.uuid = lambda: "a" + >>> names.uuid = lambda: "X" >>> execute (["this is a test",]) - Created bug with ID a - >>> bug = list(dir.list())[0] + Created bug with ID X + >>> bug = cmdutil.get_bug("X", dir) >>> bug.summary u'this is a test' >>> bug.creator = os.environ["LOGNAME"] @@ -38,7 +38,6 @@ def execute(args): u'minor' >>> bug.target == None True - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) != 1: diff --git a/becommands/open.py b/becommands/open.py index 654a1f5..2463969 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -20,16 +20,15 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> dir.get_bug("b").status u'closed' >>> execute(["b"]) >>> dir.get_bug("b").status u'open' - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) !=1: diff --git a/becommands/remove.py b/becommands/remove.py index 3834e16..172fb96 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -15,15 +15,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Remove (delete) a bug and its comments""" -from libbe import cmdutil, names, utility -from libbe.bug import new_bug +from libbe import cmdutil __desc__ = __doc__ def execute(args): """ >>> import os - >>> from libbe import tests, mapfile - >>> dir = tests.simple_bug_dir() + >>> from libbe import bugdir, mapfile + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> dir.get_bug("b").status u'closed' @@ -34,7 +33,6 @@ def execute(args): ... except mapfile.NoSuchFile: ... print "Bug not found" Bug not found - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) != 1: diff --git a/becommands/set.py b/becommands/set.py index 8a76133..368aa65 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -20,9 +20,9 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> execute(["a"]) None @@ -32,7 +32,6 @@ def execute(args): >>> execute(["a", "none"]) >>> execute(["a"]) None - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) if len(args) > 2: diff --git a/becommands/set_root.py b/becommands/set_root.py index cc21c31..1c731da 100644 --- a/becommands/set_root.py +++ b/becommands/set_root.py @@ -15,51 +15,56 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Assign the root directory for bug tracking""" +import os.path from libbe import bugdir, cmdutil, rcs __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import utility >>> import os - >>> dir = tests.Dir() + >>> dir = utility.Dir() >>> try: - ... bugdir.tree_root(dir.name) + ... bugdir.tree_root(dir.path) ... except bugdir.NoBugDir, e: ... True True - >>> execute([dir.name]) + >>> execute([dir.path]) No revision control detected. Directory initialized. - >>> bd = bugdir.tree_root(dir.name) - >>> bd.root = dir.name - >>> dir = tests.arch_dir() - >>> os.chdir(dir.name) + >>> bd = bugdir.tree_root(dir.path) + >>> bd.root = dir.path + >>> dir_rcs = rcs.installed_rcs() + >>> dir_rcs.init(bd.dir) + >>> bd.rcs_name = dir_rcs.name + >>> del(dir_rcs) + >>> os.chdir(bd.dir) >>> execute(['.']) Using Arch for revision control. Directory initialized. - >>> bd = bugdir.tree_root(dir.name+"/{arch}") - >>> bd.root = dir.name >>> try: ... execute(['.']) ... except cmdutil.UserError, e: ... str(e).startswith("Directory already initialized: ") True - >>> tests.clean_up() >>> execute(['/highly-unlikely-to-exist']) Traceback (most recent call last): UserError: No such directory: /highly-unlikely-to-exist """ options, args = get_parser().parse_args(args) + basedir = args[0] if len(args) != 1: raise cmdutil.UsageError - dir_rcs = rcs.detect(args[0]) + if os.path.exists(basedir) == False: + raise cmdutil.UserError, "No such directory: %s" % basedir + dir_rcs = rcs.detect_rcs(basedir) + dir_rcs.root(basedir) try: - bugdir.create_bug_dir(args[0], dir_rcs) + bugdir.create_bug_dir(basedir, dir_rcs) except bugdir.NoRootEntry: - raise cmdutil.UserError("No such directory: %s" % args[0]) + raise cmdutil.UserError("No such directory: %s" % basedir) except bugdir.AlreadyInitialized: - raise cmdutil.UserError("Directory already initialized: %s" % args[0]) + raise cmdutil.UserError("Directory already initialized: %s" % basedir) if dir_rcs.name is not "None": print "Using %s for revision control." % dir_rcs.name else: diff --git a/becommands/severity.py b/becommands/severity.py index 6845875..b055695 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -21,9 +21,9 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> execute(["a"]) minor @@ -33,7 +33,6 @@ def execute(args): >>> execute(["a", "none"]) Traceback (most recent call last): UserError: Invalid severity level: none - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) assert(len(args) in (0, 1, 2)) diff --git a/becommands/status.py b/becommands/status.py index b57db4e..5559e59 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -21,9 +21,9 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests + >>> from libbe import bugdir >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> execute(["a"]) open @@ -33,7 +33,6 @@ def execute(args): >>> execute(["a", "none"]) Traceback (most recent call last): UserError: Invalid status: none - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) assert(len(args) in (0, 1, 2)) diff --git a/becommands/target.py b/becommands/target.py index 4b015b4..16de8fe 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -21,9 +21,8 @@ __desc__ = __doc__ def execute(args): """ - >>> from libbe import tests >>> import os - >>> dir = tests.simple_bug_dir() + >>> dir = bugdir.simple_bug_dir() >>> os.chdir(dir.dir) >>> execute(["a"]) No target assigned. @@ -33,7 +32,6 @@ def execute(args): >>> execute(["a", "none"]) >>> execute(["a"]) No target assigned. - >>> tests.clean_up() """ options, args = get_parser().parse_args(args) assert(len(args) in (0, 1, 2)) diff --git a/becommands/upgrade.py b/becommands/upgrade.py index 7ed3630..c48eaaa 100644 --- a/becommands/upgrade.py +++ b/becommands/upgrade.py @@ -14,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# OUTDATED + """Upgrade the bugs to the latest format""" import os.path import errno -- cgit