aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Bentley <aaron.bentley@utoronto.ca>2005-05-04 10:22:12 +0000
committerAaron Bentley <aaron.bentley@utoronto.ca>2005-05-04 10:22:12 +0000
commit27e854cd1cb243b08ac435d259a057138db320f6 (patch)
tree8f9f7734bf74d59c5f2e888e3a6b1bc8e265eeed
parent91b0ee377126974bf4fa60e5caba0e87b27c7578 (diff)
downloadbugseverywhere-27e854cd1cb243b08ac435d259a057138db320f6.tar.gz
Support for bzr inventory operations
-rw-r--r--libbe/bugdir.py7
-rw-r--r--libbe/bzr.py65
-rw-r--r--libbe/rcs.py6
3 files changed, 75 insertions, 3 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index ab39a18..61f5e30 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -82,7 +82,7 @@ class BugDir:
except NoSuchFile:
self.settings = {"rcs_name": "None"}
- rcs_name = setting_property("rcs_name", ("None", "Arch"))
+ rcs_name = setting_property("rcs_name", ("None", "bzr", "Arch"))
_rcs = None
target = setting_property("target")
@@ -312,10 +312,11 @@ def pyname_to_header(name):
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)
+ add = not os.path.exists(path)
output = file(path, "wb")
mapfile.generate(output, map)
+ if add:
+ rcs.add_id(path)
class NoSuchFile(Exception):
def __init__(self, pathname):
diff --git a/libbe/bzr.py b/libbe/bzr.py
new file mode 100644
index 0000000..350e86b
--- /dev/null
+++ b/libbe/bzr.py
@@ -0,0 +1,65 @@
+from popen2 import Popen3
+import os
+import config
+
+def invoke(args):
+ q=Popen3(args, True)
+ output = q.fromchild.read()
+ error = q.childerr.read()
+ status = q.wait()
+ if os.WIFEXITED(status):
+ return os.WEXITSTATUS(status), output, error
+ raise Exception("Command failed: %s" % error)
+
+def invoke_client(*args, **kwargs):
+ cl_args = ["bzr"]
+ cl_args.extend(args)
+ status,output,error = invoke(cl_args)
+ if status not in (0,):
+ raise Exception("Command failed: %s" % error)
+ return output
+
+def add_id(filename):
+ invoke_client("add", filename)
+
+def delete_id(filename):
+ invoke_client("remove", 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 path_in_reference(bug_dir, spec):
+ if spec is not None:
+ return invoke_client("file-find", bug_dir, spec).rstrip('\n')
+ return invoke_client("file-find", bug_dir).rstrip('\n')
+
+
+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 bzr"""
+ path = os.path.realpath(path)
+ while True:
+ if os.path.exists(os.path.join(path, ".bzr")):
+ return True
+ if path == "/":
+ return False
+ path = os.path.dirname(path)
+
+
+name = "bzr"
diff --git a/libbe/rcs.py b/libbe/rcs.py
index 6dba51a..fac4b0b 100644
--- a/libbe/rcs.py
+++ b/libbe/rcs.py
@@ -3,6 +3,9 @@ def rcs_by_name(rcs_name):
if rcs_name == "Arch":
import arch
return arch
+ elif rcs_name == "bzr":
+ import bzr
+ return bzr
elif rcs_name == "None":
import no_rcs
return no_rcs
@@ -10,7 +13,10 @@ def rcs_by_name(rcs_name):
def detect(dir):
"""Return the module for the rcs being used in this directory"""
import arch
+ import bzr
if arch.detect(dir):
return arch
+ elif bzr.detect(dir):
+ return bzr
import no_rcs
return no_rcs