aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libbe/arch.py19
-rw-r--r--libbe/bugdir.py28
-rw-r--r--libbe/bzr.py17
-rw-r--r--libbe/no_rcs.py1
-rw-r--r--libbe/plugin.py2
-rw-r--r--libbe/utility.py3
6 files changed, 43 insertions, 27 deletions
diff --git a/libbe/arch.py b/libbe/arch.py
index 3152073..28d64d4 100644
--- a/libbe/arch.py
+++ b/libbe/arch.py
@@ -14,21 +14,22 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from popen2 import Popen3
+from subprocess import Popen, PIPE
import os
import config
+import errno
client = config.get_val("arch_client")
if client is None:
client = "tla"
config.set_val("arch_client", client)
def invoke(args):
- q=Popen3(args, True)
- output = q.fromchild.read()
- error = q.childerr.read()
+ q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ output = q.stdout.read()
+ error = q.stderr.read()
status = q.wait()
- if os.WIFEXITED(status):
- return os.WEXITSTATUS(status), output, error
+ if status >= 0:
+ return status, output, error
raise Exception("Command failed: %s" % error)
def invoke_client(*args, **kwargs):
@@ -161,12 +162,14 @@ def unlink(path):
def detect(path):
"""Detect whether a directory is revision-controlled using Arch"""
path = os.path.realpath(path)
+ old_path = None
while True:
if os.path.exists(os.path.join(path, "{arch}")):
return True
- if path == "/":
+ if path == old_path:
return False
- path = os.path.dirname(path)
+ old_path = path
+ path = os.path.join('..', path)
name = "Arch"
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index 0af4706..9fee680 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -29,22 +29,32 @@ class NoBugDir(Exception):
msg = "The directory \"%s\" has no bug directory." % path
Exception.__init__(self, msg)
self.path = path
-
+
+
+def iter_parent_dirs(cur_dir):
+ cur_dir = os.path.realpath(cur_dir)
+ old_dir = None
+ while True:
+ yield cur_dir
+ old_dir = cur_dir
+ cur_dir = os.path.normpath(os.path.join(cur_dir, '..'))
+ if old_dir == cur_dir:
+ break;
+
def tree_root(dir, old_version=False):
- rootdir = os.path.realpath(dir)
- while (True):
- versionfile=os.path.join(rootdir, ".be/version")
+ for rootdir in iter_parent_dirs(dir):
+ versionfile=os.path.join(rootdir, ".be", "version")
if os.path.exists(versionfile):
if not old_version:
test_version(versionfile)
- break;
- elif rootdir == "/":
- raise NoBugDir(dir)
+ return BugDir(os.path.join(rootdir, ".be"))
elif not os.path.exists(rootdir):
raise NoRootEntry(rootdir)
- rootdir=os.path.dirname(rootdir)
- return BugDir(os.path.join(rootdir, ".be"))
+ old_rootdir = rootdir
+ rootdir=os.path.join('..', rootdir)
+
+ raise NoBugDir(dir)
class BadTreeVersion(Exception):
def __init__(self, version):
diff --git a/libbe/bzr.py b/libbe/bzr.py
index fd6d4a6..bc4d98d 100644
--- a/libbe/bzr.py
+++ b/libbe/bzr.py
@@ -14,19 +14,20 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from popen2 import Popen3
+from subprocess import Popen
import os
import config
def invoke(args):
- q=Popen3(args, True)
- output = q.fromchild.read()
- error = q.childerr.read()
+ q=Popen(args)
+ output = q.stdout.read()
+ error = q.stderr.read()
status = q.wait()
- if os.WIFEXITED(status):
- return os.WEXITSTATUS(status), output, error
+ if status >= 0:
+ return status, output, error
raise Exception("Command failed: %s" % error)
+
def invoke_client(*args, **kwargs):
cl_args = ["bzr"]
cl_args.extend(args)
@@ -91,11 +92,13 @@ def unlink(path):
def detect(path):
"""Detect whether a directory is revision-controlled using bzr"""
path = os.path.realpath(path)
+ old_path = None
while True:
if os.path.exists(os.path.join(path, ".bzr")):
return True
- if path == "/":
+ if path == old_path:
return False
+ old_path = path
path = os.path.dirname(path)
diff --git a/libbe/no_rcs.py b/libbe/no_rcs.py
index 1c02725..7e070b3 100644
--- a/libbe/no_rcs.py
+++ b/libbe/no_rcs.py
@@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from popen2 import Popen4
import os
import config
from os import unlink
diff --git a/libbe/plugin.py b/libbe/plugin.py
index 234d221..b175733 100644
--- a/libbe/plugin.py
+++ b/libbe/plugin.py
@@ -46,7 +46,7 @@ def get_plugin(prefix, name):
>>> q.startswith("<module 'becommands.list' from ")
True
"""
- dirprefix = '/'.join(prefix.split('.'))
+ dirprefix = os.path.join(*prefix.split('.'))
command_path = os.path.join(plugin_path, dirprefix, name+".py")
if os.path.isfile(command_path):
return my_import(prefix + "." + name)
diff --git a/libbe/utility.py b/libbe/utility.py
index 3d805cd..e62f2cd 100644
--- a/libbe/utility.py
+++ b/libbe/utility.py
@@ -102,7 +102,8 @@ def editor_string():
"""Invokes the editor, and returns the user_produced text as a string
- >>> del os.environ["EDITOR"]
+ >>> if "EDITOR" in os.environ:
+ ... del os.environ["EDITOR"]
>>> editor_string()
Traceback (most recent call last):
CantFindEditor: Can't find editor to get string from