From: Aaron Bentley Date: Wed, 4 May 2005 10:22:12 +0000 (+0000) Subject: Support for bzr inventory operations X-Git-Tag: 1.0.0~298^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=27e854cd1cb243b08ac435d259a057138db320f6;p=be.git Support for bzr inventory operations --- 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