diff options
author | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-09 17:25:46 +0000 |
---|---|---|
committer | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-09 17:25:46 +0000 |
commit | a137e93fb63f88cf47b70ac5bba51a79df47bd41 (patch) | |
tree | 9338b8f48a0741b17970e15da5f80fc502aea0f1 /libbe/cmdutil.py | |
parent | 1bf1ec598b436f41ff27094eddf0b28c797e359d (diff) | |
download | bugseverywhere-a137e93fb63f88cf47b70ac5bba51a79df47bd41.tar.gz |
Added basic bug-listing functionality
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r-- | libbe/cmdutil.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py new file mode 100644 index 0000000..6c5285a --- /dev/null +++ b/libbe/cmdutil.py @@ -0,0 +1,73 @@ +import os +import os.path + +class NoBugDir(Exception): + def __init__(self, path): + msg = "The directory \"%s\" has no bug directory." % path + Exception.__init__(self, msg) + self.path = path + + +def tree_root(dir): + rootdir = os.path.realpath(dir) + while (True): + versionfile=os.path.join(rootdir, ".be/version") + if os.path.exists(versionfile): + test_version(versionfile) + break; + elif rootdir == "/": + raise NoBugDir(dir) + rootdir=os.path.dirname(rootdir) + return BugDir(os.path.join(rootdir, ".be")) + +def test_version(path): + assert (file(path, "rb").read() == "Bugs Everywhere Tree 0 0\n") + +class BugDir: + def __init__(self, dir): + self.dir = dir + self.bugs_path = os.path.join(self.dir, "bugs") + + + def list(self): + for uuid in os.listdir(self.bugs_path): + if (uuid.startswith('.')): + continue + yield Bug(self.bugs_path, uuid) + +def unique_name(bug, bugs): + return bug.name + +def file_property(name): + def getter(self): + return self._get_value(name) + def setter(self, value): + return self._set_value(name, value) + return property(getter, setter) + +class Bug(object): + def __init__(self, path, uuid): + self.path = os.path.join(path, uuid) + self.uuid = uuid + + def get_path(self, file): + return os.path.join(self.path, file) + + def _get_name(self): + return self._get_value("name") + + def _set_name(self, value): + return self._set_value("name", value) + + name = file_property("name") + summary = file_property("summary") + + def _set_status(self, status): + assert status in ("open", "closed") + + def _get_value(self, name): + return file(self.get_path(name), "rb").read().rstrip("\n") + + def _set_value(self, name, value): + file(self.get_path(name), "wb").write("%s\n" % value) + |