diff options
author | Aaron Bentley <aaron.bentley@utoronto.ca> | 2005-03-19 06:04:41 +0000 |
---|---|---|
committer | Aaron Bentley <aaron.bentley@utoronto.ca> | 2005-03-19 06:04:41 +0000 |
commit | 92826d47239312d7ed3cbc6638be44c6e84ca8a3 (patch) | |
tree | 43f27171822472f5445b7bd1b9bf14b131750c1c /libbe | |
parent | 148f6d366053422257b1c021cf86fb884c13dff8 (diff) | |
download | bugseverywhere-92826d47239312d7ed3cbc6638be44c6e84ca8a3.tar.gz |
Added RCS configuration.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/arch.py | 32 | ||||
-rw-r--r-- | libbe/bugdir.py | 88 | ||||
-rw-r--r-- | libbe/no_rcs.py | 24 | ||||
-rw-r--r-- | libbe/rcs.py | 32 |
4 files changed, 145 insertions, 31 deletions
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 |