Added RCS configuration.
authorAaron Bentley <aaron.bentley@utoronto.ca>
Sat, 19 Mar 2005 06:04:41 +0000 (06:04 +0000)
committerAaron Bentley <aaron.bentley@utoronto.ca>
Sat, 19 Mar 2005 06:04:41 +0000 (06:04 +0000)
.be/bugs/ee681951-f254-43d3-a53a-1b36ae415d5c/values
.be/settings [new file with mode: 0644]
becommands/set.py [new file with mode: 0644]
becommands/set_root.py
libbe/arch.py
libbe/bugdir.py
libbe/no_rcs.py [new file with mode: 0644]
libbe/rcs.py

index 4dc31897e13cb70adbe95315f332ede6f52e4e9c..2e595f98059198c87296f620edeedf300d679742 100644 (file)
@@ -15,7 +15,7 @@ severity=minor
 
 
 
-status=open
+status=closed
 
 
 
diff --git a/.be/settings b/.be/settings
new file mode 100644 (file)
index 0000000..68d1c75
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+
+rcs_name=Arch
+
+
+
diff --git a/becommands/set.py b/becommands/set.py
new file mode 100644 (file)
index 0000000..956a95e
--- /dev/null
@@ -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()
+
index 0775da3891263397c55870b771281fa6729d2d6b..ff7662a9e29ddf09e0ecd38374a79369abcbb9d6 100644 (file)
@@ -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."
index b1b88fd89c28e18f223524a01bfdf542d8c97ca8..7e1cd1f37c9b8b6da896ad562ff99976d0895bdb 100644 (file)
@@ -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"
index e1c95c56ba86424ff4fd638d53e0f7e7107850c1..9084ee86221b265a953f0f73cda0c406327bbe4d 100644 (file)
@@ -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 (file)
index 0000000..a866f79
--- /dev/null
@@ -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"
index dd0c008a9764bc50d4313a6041406a1b65ad4d47..6dba51a9a510bf52cc53856556a89ad482c6b5ef 100644 (file)
@@ -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