Various Windows-related bugfixes
authorAaron Bentley <aaron.bentley@utoronto.ca>
Thu, 22 Dec 2005 07:59:52 +0000 (02:59 -0500)
committerAaron Bentley <aaron.bentley@utoronto.ca>
Thu, 22 Dec 2005 07:59:52 +0000 (02:59 -0500)
libbe/arch.py
libbe/bugdir.py
libbe/bzr.py
libbe/no_rcs.py
libbe/plugin.py
libbe/utility.py

index 3152073f42137692a697f7168ffadfa793ab133b..28d64d4128501f9e511625cb3534a1fe95e386c6 100644 (file)
 #    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"
index 0af4706d29a97643ff1344bbdda045fcf2f1ad51..9fee68098195eec277b73882ef6ba0053aef6229 100644 (file)
@@ -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):
index fd6d4a66bfdb43a15ef9b0066af5f5e5c39da42c..bc4d98db54750e9fef29fd417e09cef8c6e5e5ca 100644 (file)
 #    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)
 
 
index 1c02725d77160f725d545490c8c7e156119ba8e8..7e070b33e97d1ca10780ac95220a1576abd3d669 100644 (file)
@@ -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
index 234d22130d29ec430f67f076ef663a12d6f2524a..b175733a41d1fa74143532b8b39332ff6b10a922 100644 (file)
@@ -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)
index 3d805cdf332e7554714442d64a3e3664035b1b2c..e62f2cd04420747e97ebe06a45adc9a7859f3e0c 100644 (file)
@@ -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