From 92826d47239312d7ed3cbc6638be44c6e84ca8a3 Mon Sep 17 00:00:00 2001 From: Aaron Bentley Date: Sat, 19 Mar 2005 06:04:41 +0000 Subject: [PATCH] Added RCS configuration. --- .../values | 2 +- .be/settings | 7 ++ becommands/set.py | 11 +++ becommands/set_root.py | 10 ++- libbe/arch.py | 32 +++++++ libbe/bugdir.py | 88 ++++++++++++++++--- libbe/no_rcs.py | 24 +++++ libbe/rcs.py | 32 ++++--- 8 files changed, 172 insertions(+), 34 deletions(-) create mode 100644 .be/settings create mode 100644 becommands/set.py create mode 100644 libbe/no_rcs.py diff --git a/.be/bugs/ee681951-f254-43d3-a53a-1b36ae415d5c/values b/.be/bugs/ee681951-f254-43d3-a53a-1b36ae415d5c/values index 4dc3189..2e595f9 100644 --- a/.be/bugs/ee681951-f254-43d3-a53a-1b36ae415d5c/values +++ b/.be/bugs/ee681951-f254-43d3-a53a-1b36ae415d5c/values @@ -15,7 +15,7 @@ severity=minor -status=open +status=closed diff --git a/.be/settings b/.be/settings new file mode 100644 index 0000000..68d1c75 --- /dev/null +++ b/.be/settings @@ -0,0 +1,7 @@ + + + +rcs_name=Arch + + + diff --git a/becommands/set.py b/becommands/set.py new file mode 100644 index 0000000..956a95e --- /dev/null +++ b/becommands/set.py @@ -0,0 +1,11 @@ +"""Change tree settings""" +from libbe import cmdutil +def execute(args): + assert len(args) in (1, 2) + tree = cmdutil.bug_tree() + if len(args) == 1: + print tree.settings.get(args[0]) + else: + tree.settings[args[0]] = args[1] + tree.save_settings() + diff --git a/becommands/set_root.py b/becommands/set_root.py index 0775da3..ff7662a 100644 --- a/becommands/set_root.py +++ b/becommands/set_root.py @@ -1,7 +1,13 @@ """Assign the root directory for bug tracking""" -from libbe import bugdir, cmdutil +from libbe import bugdir, cmdutil, rcs def execute(args): if len(args) != 1: raise cmdutil.UserError("Please supply a directory path") - bugdir.create_bug_dir(args[0]) + dir_rcs = rcs.detect(args[0]) + if dir_rcs.name is not "None": + print "Using %s for revision control." % dir_rcs.name + else: + print "No revision control detected." + bugdir.create_bug_dir(args[0], dir_rcs) + print "Directory initialized." diff --git a/libbe/arch.py b/libbe/arch.py index b1b88fd..7e1cd1f 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -24,3 +24,35 @@ def add_id(filename): def delete_id(filename): invoke_client("delete-id", filename) + +def mkdir(path): + os.mkdir(path) + add_id(path) + +def set_file_contents(path, contents): + add = not os.path.exists(path) + file(path, "wb").write(contents) + if add: + add_id(path) + +def unlink(path): + try: + os.unlink(path) + delete_id(path) + except OSError, e: + if e.errno != 2: + raise + + +def detect(path): + """Detect whether a directory is revision-controlled using Arch""" + path = os.path.realpath(path) + while True: + if os.path.exists(os.path.join(path, "{arch}")): + return True + if path == "/": + return False + path = os.path.dirname(path) + + +name = "Arch" diff --git a/libbe/bugdir.py b/libbe/bugdir.py index e1c95c5..9084ee8 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -3,8 +3,8 @@ import os.path import cmdutil import errno import names -import rcs import mapfile +from rcs import rcs_by_name class NoBugDir(Exception): def __init__(self, path): @@ -36,28 +36,67 @@ def test_version(path): if tree_version != TREE_VERSION_STRING: raise BadTreeVersion(tree_version) -def set_version(path): +def set_version(path, rcs): rcs.set_file_contents(os.path.join(path, "version"), TREE_VERSION_STRING) TREE_VERSION_STRING = "Bugs Everywhere Tree 1 0\n" -def create_bug_dir(path): +def create_bug_dir(path, rcs): root = os.path.join(path, ".be") rcs.mkdir(root) rcs.mkdir(os.path.join(root, "bugs")) - set_version(root) - + set_version(root, rcs) + map_save(rcs, os.path.join(root, "settings"), {"rcs_name": rcs.name}) return BugDir(path) + +def setting_property(name, valid=None): + def getter(self): + value = self.settings.get(name) + if valid is not None: + if value not in valid: + raise InvalidValue(name, value) + return value + + def setter(self, value): + if valid is not None: + if value not in valid and value is not None: + raise InvalidValue(name, value) + if value is None: + del self.settings[name] + else: + self.settings[name] = value + self.save_settings() + return property(getter, setter) + + class BugDir: def __init__(self, dir): self.dir = dir self.bugs_path = os.path.join(self.dir, "bugs") + try: + self.settings = map_load(os.path.join(self.dir, "settings")) + except NoSuchFile: + self.settings = {"rcs_name": "None"} + + rcs_name = setting_property("rcs_name", ("None", "Arch")) + _rcs = None + + def save_settings(self): + map_save(self.rcs, os.path.join(self.dir, "settings"), self.settings) + + def get_rcs(self): + if self._rcs is not None and self.rcs_name == _rcs.name: + return self._rcs + self._rcs = rcs_by_name(self.rcs_name) + return self._rcs + + rcs = property(get_rcs) def list(self): for uuid in self.list_uuids(): - yield Bug(self.bugs_path, uuid) + yield Bug(self.bugs_path, uuid, self.rcs_name) def list_uuids(self): for uuid in os.listdir(self.bugs_path): @@ -68,8 +107,8 @@ class BugDir: def new_bug(self): uuid = names.uuid() path = os.path.join(self.bugs_path, uuid) - rcs.mkdir(path) - bug = Bug(self.bugs_path, None) + self.rcs.mkdir(path) + bug = Bug(self.bugs_path, None, self.rcs_name) bug.uuid = uuid return bug @@ -105,14 +144,16 @@ class Bug(object): severity = checked_property("severity", (None, "wishlist", "minor", "serious", "critical", "fatal")) - def __init__(self, path, uuid): + def __init__(self, path, uuid, rcs_name): self.path = path self.uuid = uuid if uuid is not None: - dict = mapfile.parse(file(self.get_path("values"))) + dict = map_load(self.get_path("values")) else: dict = {} + self.rcs_name = rcs_name + self.summary = dict.get("summary") self.creator = dict.get("creator") self.target = dict.get("target") @@ -142,10 +183,29 @@ class Bug(object): self.add_attr(map, "status") self.add_attr(map, "severity") path = self.get_path("values") - if not os.path.exists(path): - rcs.add_id(path) - output = file(path, "wb") - mapfile.generate(output, map) + map_save(rcs_by_name(self.rcs_name), path, map) + + +def map_save(rcs, path, map): + """Save the map as a mapfile to the specified path""" + if not os.path.exists(path): + rcs.add_id(path) + output = file(path, "wb") + mapfile.generate(output, map) + +class NoSuchFile(Exception): + def __init__(self, pathname): + Exception.__init__(self, "No such file: %s" % pathname) + + +def map_load(path): + try: + return mapfile.parse(file(path, "rb")) + except IOError, e: + if e.errno != errno.ENOENT: + raise e + raise NoSuchFile(path) + class MockBug: def __init__(self, severity): diff --git a/libbe/no_rcs.py b/libbe/no_rcs.py new file mode 100644 index 0000000..a866f79 --- /dev/null +++ b/libbe/no_rcs.py @@ -0,0 +1,24 @@ +from popen2 import Popen4 +import os +import config +from os import mkdir, unlink + +def add_id(filename): + """Compatibility function""" + pass + +def delete_id(filename): + """Compatibility function""" + pass + +def set_file_contents(path, contents): + add = not os.path.exists(path) + file(path, "wb").write(contents) + if add: + add_id(path) + +def detect(path): + """Compatibility function""" + return True + +name = "None" diff --git a/libbe/rcs.py b/libbe/rcs.py index dd0c008..6dba51a 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -1,18 +1,16 @@ -from arch import * -def mkdir(path): - os.mkdir(path) - add_id(path) +def rcs_by_name(rcs_name): + """Return the module for the RCS with the given name""" + if rcs_name == "Arch": + import arch + return arch + elif rcs_name == "None": + import no_rcs + return no_rcs -def set_file_contents(path, contents): - add = not os.path.exists(path) - file(path, "wb").write(contents) - if add: - add_id(path) - -def unlink(path): - try: - os.unlink(path) - delete_id(path) - except OSError, e: - if e.errno != 2: - raise +def detect(dir): + """Return the module for the rcs being used in this directory""" + import arch + if arch.detect(dir): + return arch + import no_rcs + return no_rcs -- 2.26.2