aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2005-05-09 13:39:16 +0000
committerAaron Bentley <abentley@panoramicfeedback.com>2005-05-09 13:39:16 +0000
commitcb9d4c77d8bd3d72cd61acdf940417fbfea1b3fc (patch)
tree66d1b36efdad25c508a53e8244b88df1e443dab7 /libbe
parent0c493b603acc58042c89e475354af25e4f82efed (diff)
parentf92ced7d577142b16ef86ed6aff6bb6b5f526e2d (diff)
downloadbugseverywhere-cb9d4c77d8bd3d72cd61acdf940417fbfea1b3fc.tar.gz
Merge (Aaron Bentley)
Patches applied: * aaron.bentley@utoronto.ca--lappy/be--devel--0--base-0 * tag of aaron.bentley@utoronto.ca--be/bugs-everywhere--devel--0--patch-90 * aaron.bentley@utoronto.ca--lappy/be--devel--0--patch-1 * Support for bzr inventory operations * aaron.bentley@utoronto.ca--lappy/be--devel--0--patch-2 * Added pseudo-revlib functionality for bzr
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bugdir.py7
-rw-r--r--libbe/bzr.py83
-rw-r--r--libbe/rcs.py6
3 files changed, 93 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..b2e0d6b
--- /dev/null
+++ b/libbe/bzr.py
@@ -0,0 +1,83 @@
+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 lookup_revision(revno):
+ return invoke_client("lookup-revision", str(revno)).rstrip('\n')
+
+def export(revno, revision_dir):
+ invoke_client("export", str(revno), revision_dir)
+
+def find_or_make_export(revno):
+ revision_id = lookup_revision(revno)
+ home = os.path.expanduser("~")
+ revision_dir = os.path.join(home, ".bzrrevs", revision_id)
+ if not os.path.exists(revision_dir):
+ export(revno, revision_dir)
+ return revision_dir
+
+def bzr_root(path):
+ return invoke_client("root", path).rstrip('\r')
+
+def path_in_reference(bug_dir, spec):
+ if spec is None:
+ spec = int(invoke_client("revno"))
+ rel_bug_dir = bug_dir[len(bzr_root(bug_dir)):]
+ export_root = find_or_make_export(spec)
+ return os.path.join(export_root, rel_bug_dir)
+
+
+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