Updated to trunk
authorGianluca Montecchi <gian@grys.it>
Wed, 7 Oct 2009 18:41:49 +0000 (20:41 +0200)
committerGianluca Montecchi <gian@grys.it>
Wed, 7 Oct 2009 18:41:49 +0000 (20:41 +0200)
26 files changed:
becommands/init.py
interfaces/email/interactive/becommands/init.py
interfaces/email/interactive/libbe/arch.py
interfaces/email/interactive/libbe/bugdir.py
interfaces/email/interactive/libbe/bzr.py
interfaces/email/interactive/libbe/darcs.py
interfaces/email/interactive/libbe/git.py
interfaces/email/interactive/libbe/hg.py
interfaces/email/interactive/libbe/utility.py
interfaces/email/interactive/libbe/vcs.py
interfaces/web/Bugs-Everywhere-Web/libbe/arch.py
interfaces/web/Bugs-Everywhere-Web/libbe/bugdir.py
interfaces/web/Bugs-Everywhere-Web/libbe/bzr.py
interfaces/web/Bugs-Everywhere-Web/libbe/darcs.py
interfaces/web/Bugs-Everywhere-Web/libbe/git.py
interfaces/web/Bugs-Everywhere-Web/libbe/hg.py
interfaces/web/Bugs-Everywhere-Web/libbe/utility.py
interfaces/web/Bugs-Everywhere-Web/libbe/vcs.py
libbe/arch.py
libbe/bugdir.py
libbe/bzr.py
libbe/darcs.py
libbe/git.py
libbe/hg.py
libbe/utility.py
libbe/vcs.py

index 1125d937e158940fb5eb41ddf8ea5f488fe7f859..a6098ba191306c17a72fe59051ccd0e18596ba19 100644 (file)
@@ -32,7 +32,7 @@ def execute(args, manipulate_encodings=True):
     >>> execute(['--root', dir.path], manipulate_encodings=False)
     No revision control detected.
     Directory initialized.
-    >>> del(dir)
+    >>> dir.cleanup()
 
     >>> dir = utility.Dir()
     >>> os.chdir(dir.path)
index 1125d937e158940fb5eb41ddf8ea5f488fe7f859..a6098ba191306c17a72fe59051ccd0e18596ba19 100644 (file)
@@ -32,7 +32,7 @@ def execute(args, manipulate_encodings=True):
     >>> execute(['--root', dir.path], manipulate_encodings=False)
     No revision control detected.
     Directory initialized.
-    >>> del(dir)
+    >>> dir.cleanup()
 
     >>> dir = utility.Dir()
     >>> os.chdir(dir.path)
index ab551729da670de122e9de31f91bd155710a095b..daa8ac6114773997abfa4ed14ecc3705cbc833ab 100644 (file)
@@ -53,8 +53,8 @@ class Arch(vcs.VCS):
     _project_name = None
     _tmp_project = False
     _arch_paramdir = os.path.expanduser("~/.arch-params")
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Arch"""
@@ -70,7 +70,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch archive in the directory PATH.  This
         archive will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_archive
+          cleanup->_vcs_cleanup->_remove_archive
         """
         # http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive
         assert self._archive_name == None
@@ -112,7 +112,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch project in the directory PATH.  This
         project will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_project
+          cleanup->_vcs_cleanup->_remove_project
         """
         # http://mwolson.org/projects/GettingStartedWithArch.html
         # http://regexps.srparish.net/tutorial-tla/new-project.html#Starting_a_New_Project
index c4f0f9192b327035f90c8a88689f60a6044d6ccb..532416315b394e60c6d17f5f2529831c026a5848 100644 (file)
@@ -305,6 +305,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.root = self._find_root(root)
         else:
             if not os.path.exists(root):
+                self.root = None
                 raise NoRootEntry(root)
             self.root = root
         # get a temporary vcs until we've loaded settings
@@ -324,9 +325,6 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.vcs = vcs
             self._setup_user_id(self.user_id)
 
-    def __del__(self):
-        self.cleanup()
-
     def cleanup(self):
         self.vcs.cleanup()
 
@@ -339,6 +337,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         then only if sink_to_existing_root == True.
         """
         if not os.path.exists(path):
+            self.root = None
             raise NoRootEntry(path)
         versionfile=utility.search_parent_directories(path,
                                                       os.path.join(".be", "version"))
@@ -349,6 +348,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         else:
             beroot = utility.search_parent_directories(path, ".be")
             if beroot == None:
+                self.root = None
                 raise NoBugDir(path)
             return beroot
 
@@ -671,7 +671,7 @@ class SimpleBugDir (BugDir):
                     assert_new_BugDir=assert_new_BugDir,
                     allow_vcs_init=vcs_init,
                     manipulate_encodings=False)
-        if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
+        if sync_with_disk == True: # postpone cleanup since dir.cleanup() removes dir.
             self._dir_ref = dir
         bug_a = self.new_bug("a", summary="Bug A")
         bug_a.creator = "John Doe <jdoe@example.com>"
index e9e0649615ef86a0c618228fa091f3f42c1f2221..ed9e03297b10d4b0641f94c282b128242ddbc91b 100644 (file)
@@ -37,8 +37,8 @@ class Bzr(vcs.VCS):
     name = "bzr"
     client = "bzr"
     versioned = True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output        
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".bzr") != None :
index 16005f2a71e065f2fbb8155920bf0fabea6632a9..91158860f14e0a32d48673ee5a5968ded1806b74 100644 (file)
@@ -40,8 +40,10 @@ class Darcs(vcs.VCS):
     name="darcs"
     client="darcs"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
+        num_part = output.split(" ")[0]
+        self.parsed_version = [int(i) for i in num_part.split(".")]
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, "_darcs") != None :
@@ -95,20 +97,20 @@ class Darcs(vcs.VCS):
     def _vcs_get_file_contents(self, path, revision=None, binary=False):
         if revision == None:
             return vcs.VCS._vcs_get_file_contents(self, path, revision,
-                                              binary=binary)
+                                                  binary=binary)
         else:
-            try:
-                return self._u_invoke_client("show", "contents", "--patch", revision, path)
-            except vcs.CommandError:
+            if self.parsed_version[0] >= 2:
+                status,output,error = self._u_invoke_client( \
+                    "show", "contents", "--patch", revision, path)
+                return output
+            else:
                 # Darcs versions < 2.0.0pre2 lack the "show contents" command
 
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--from-patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--from-patch", revision, path)
                 major_patch = output
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--patch", revision, path)
                 target_patch = output
                 
                 # "--output -" to be supported in GNU patch > 2.5.9
index 3abe3b816bd4bc5c63ed22f7578e7fe62391e416..628f9b9697f4273e75e59663a84f6722ceb8df48 100644 (file)
@@ -36,8 +36,8 @@ class Git(vcs.VCS):
     name="git"
     client="git"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".git") != None :
index f8f8121dd9f63669e7bbfb7a592427ecc6c1105a..7cd4c2fa60146110c4fb372df5dd888c7401d25b 100644 (file)
@@ -36,8 +36,8 @@ class Hg(vcs.VCS):
     name="hg"
     client="hg"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Mercurial"""
index aafbf8d164c5d77b446114d28347299c450c9b38..1e4351603c1d1a0bd3b9b94bc628bf46eefcba1d 100644 (file)
@@ -58,13 +58,10 @@ class Dir (object):
     "A temporary directory for testing use"
     def __init__(self):
         self.path = tempfile.mkdtemp(prefix="BEtest")
-        self.rmtree = shutil.rmtree # save local reference for __del__
         self.removed = False
-    def __del__(self):
-        self.cleanup()
     def cleanup(self):
         if self.removed == False:
-            self.rmtree(self.path)
+            shutil.rmtree(self.path)
             self.removed = True
     def __call__(self):
         return self.path
index a1d302264700e7993351b3ddda914b8ca50294ab..7b506e8dac3043aef0a58a26e5512b8c7d59e0fa 100644 (file)
@@ -50,7 +50,7 @@ def _get_matching_vcs(matchfn):
         vcs = module.new()
         if matchfn(vcs) == True:
             return vcs
-        del(vcs)
+        vcs.cleanup()
     return VCS()
     
 def vcs_by_name(vcs_name):
@@ -124,15 +124,12 @@ class VCS(object):
         self._duplicateBasedir = None
         self._duplicateDirname = None
         self.encoding = encoding
-    def __del__(self):
-        self.cleanup()
-
-    def _vcs_help(self):
+        self.version = self._get_version()
+    def _vcs_version(self):
         """
-        Return the command help string.
-        (Allows a simple test to see if the client is installed.)
+        Return the VCS version string.
         """
-        pass
+        return "0.0"
     def _vcs_detect(self, path=None):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -231,15 +228,21 @@ class VCS(object):
         specified revision does not exist.
         """
         return None
-    def installed(self):
+    def _get_version(self):
         try:
-            self._vcs_help()
-            return True
+            ret = self._vcs_version()
+            return ret
         except OSError, e:
             if e.errno == errno.ENOENT:
-                return False
+                return None
+            else:
+                raise OSError, e
         except CommandError:
-            return False
+            return None
+    def installed(self):
+        if self.version != None:
+            return True
+        return False
     def detect(self, path="."):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -674,7 +677,7 @@ class VCSTestCase(unittest.TestCase):
         setup_vcs_test_fixtures(self)
 
     def tearDown(self):
-        del(self.vcs)
+        self.vcs.cleanup()
         super(VCSTestCase, self).tearDown()
 
     def full_path(self, rel_path):
@@ -837,6 +840,7 @@ class VCS_commit_TestCase(VCSTestCase):
 
     def test_revision_file_contents_as_committed(self):
         """Should get file contents as committed to specified revision."""
+        import sys
         if not self.vcs.versioned:
             return
         for path in self.test_files:
index ab551729da670de122e9de31f91bd155710a095b..daa8ac6114773997abfa4ed14ecc3705cbc833ab 100644 (file)
@@ -53,8 +53,8 @@ class Arch(vcs.VCS):
     _project_name = None
     _tmp_project = False
     _arch_paramdir = os.path.expanduser("~/.arch-params")
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Arch"""
@@ -70,7 +70,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch archive in the directory PATH.  This
         archive will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_archive
+          cleanup->_vcs_cleanup->_remove_archive
         """
         # http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive
         assert self._archive_name == None
@@ -112,7 +112,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch project in the directory PATH.  This
         project will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_project
+          cleanup->_vcs_cleanup->_remove_project
         """
         # http://mwolson.org/projects/GettingStartedWithArch.html
         # http://regexps.srparish.net/tutorial-tla/new-project.html#Starting_a_New_Project
index c4f0f9192b327035f90c8a88689f60a6044d6ccb..532416315b394e60c6d17f5f2529831c026a5848 100644 (file)
@@ -305,6 +305,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.root = self._find_root(root)
         else:
             if not os.path.exists(root):
+                self.root = None
                 raise NoRootEntry(root)
             self.root = root
         # get a temporary vcs until we've loaded settings
@@ -324,9 +325,6 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.vcs = vcs
             self._setup_user_id(self.user_id)
 
-    def __del__(self):
-        self.cleanup()
-
     def cleanup(self):
         self.vcs.cleanup()
 
@@ -339,6 +337,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         then only if sink_to_existing_root == True.
         """
         if not os.path.exists(path):
+            self.root = None
             raise NoRootEntry(path)
         versionfile=utility.search_parent_directories(path,
                                                       os.path.join(".be", "version"))
@@ -349,6 +348,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         else:
             beroot = utility.search_parent_directories(path, ".be")
             if beroot == None:
+                self.root = None
                 raise NoBugDir(path)
             return beroot
 
@@ -671,7 +671,7 @@ class SimpleBugDir (BugDir):
                     assert_new_BugDir=assert_new_BugDir,
                     allow_vcs_init=vcs_init,
                     manipulate_encodings=False)
-        if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
+        if sync_with_disk == True: # postpone cleanup since dir.cleanup() removes dir.
             self._dir_ref = dir
         bug_a = self.new_bug("a", summary="Bug A")
         bug_a.creator = "John Doe <jdoe@example.com>"
index e9e0649615ef86a0c618228fa091f3f42c1f2221..ed9e03297b10d4b0641f94c282b128242ddbc91b 100644 (file)
@@ -37,8 +37,8 @@ class Bzr(vcs.VCS):
     name = "bzr"
     client = "bzr"
     versioned = True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output        
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".bzr") != None :
index 16005f2a71e065f2fbb8155920bf0fabea6632a9..91158860f14e0a32d48673ee5a5968ded1806b74 100644 (file)
@@ -40,8 +40,10 @@ class Darcs(vcs.VCS):
     name="darcs"
     client="darcs"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
+        num_part = output.split(" ")[0]
+        self.parsed_version = [int(i) for i in num_part.split(".")]
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, "_darcs") != None :
@@ -95,20 +97,20 @@ class Darcs(vcs.VCS):
     def _vcs_get_file_contents(self, path, revision=None, binary=False):
         if revision == None:
             return vcs.VCS._vcs_get_file_contents(self, path, revision,
-                                              binary=binary)
+                                                  binary=binary)
         else:
-            try:
-                return self._u_invoke_client("show", "contents", "--patch", revision, path)
-            except vcs.CommandError:
+            if self.parsed_version[0] >= 2:
+                status,output,error = self._u_invoke_client( \
+                    "show", "contents", "--patch", revision, path)
+                return output
+            else:
                 # Darcs versions < 2.0.0pre2 lack the "show contents" command
 
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--from-patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--from-patch", revision, path)
                 major_patch = output
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--patch", revision, path)
                 target_patch = output
                 
                 # "--output -" to be supported in GNU patch > 2.5.9
index 3abe3b816bd4bc5c63ed22f7578e7fe62391e416..628f9b9697f4273e75e59663a84f6722ceb8df48 100644 (file)
@@ -36,8 +36,8 @@ class Git(vcs.VCS):
     name="git"
     client="git"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".git") != None :
index f8f8121dd9f63669e7bbfb7a592427ecc6c1105a..7cd4c2fa60146110c4fb372df5dd888c7401d25b 100644 (file)
@@ -36,8 +36,8 @@ class Hg(vcs.VCS):
     name="hg"
     client="hg"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Mercurial"""
index aafbf8d164c5d77b446114d28347299c450c9b38..1e4351603c1d1a0bd3b9b94bc628bf46eefcba1d 100644 (file)
@@ -58,13 +58,10 @@ class Dir (object):
     "A temporary directory for testing use"
     def __init__(self):
         self.path = tempfile.mkdtemp(prefix="BEtest")
-        self.rmtree = shutil.rmtree # save local reference for __del__
         self.removed = False
-    def __del__(self):
-        self.cleanup()
     def cleanup(self):
         if self.removed == False:
-            self.rmtree(self.path)
+            shutil.rmtree(self.path)
             self.removed = True
     def __call__(self):
         return self.path
index a1d302264700e7993351b3ddda914b8ca50294ab..7b506e8dac3043aef0a58a26e5512b8c7d59e0fa 100644 (file)
@@ -50,7 +50,7 @@ def _get_matching_vcs(matchfn):
         vcs = module.new()
         if matchfn(vcs) == True:
             return vcs
-        del(vcs)
+        vcs.cleanup()
     return VCS()
     
 def vcs_by_name(vcs_name):
@@ -124,15 +124,12 @@ class VCS(object):
         self._duplicateBasedir = None
         self._duplicateDirname = None
         self.encoding = encoding
-    def __del__(self):
-        self.cleanup()
-
-    def _vcs_help(self):
+        self.version = self._get_version()
+    def _vcs_version(self):
         """
-        Return the command help string.
-        (Allows a simple test to see if the client is installed.)
+        Return the VCS version string.
         """
-        pass
+        return "0.0"
     def _vcs_detect(self, path=None):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -231,15 +228,21 @@ class VCS(object):
         specified revision does not exist.
         """
         return None
-    def installed(self):
+    def _get_version(self):
         try:
-            self._vcs_help()
-            return True
+            ret = self._vcs_version()
+            return ret
         except OSError, e:
             if e.errno == errno.ENOENT:
-                return False
+                return None
+            else:
+                raise OSError, e
         except CommandError:
-            return False
+            return None
+    def installed(self):
+        if self.version != None:
+            return True
+        return False
     def detect(self, path="."):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -674,7 +677,7 @@ class VCSTestCase(unittest.TestCase):
         setup_vcs_test_fixtures(self)
 
     def tearDown(self):
-        del(self.vcs)
+        self.vcs.cleanup()
         super(VCSTestCase, self).tearDown()
 
     def full_path(self, rel_path):
@@ -837,6 +840,7 @@ class VCS_commit_TestCase(VCSTestCase):
 
     def test_revision_file_contents_as_committed(self):
         """Should get file contents as committed to specified revision."""
+        import sys
         if not self.vcs.versioned:
             return
         for path in self.test_files:
index ab551729da670de122e9de31f91bd155710a095b..daa8ac6114773997abfa4ed14ecc3705cbc833ab 100644 (file)
@@ -53,8 +53,8 @@ class Arch(vcs.VCS):
     _project_name = None
     _tmp_project = False
     _arch_paramdir = os.path.expanduser("~/.arch-params")
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Arch"""
@@ -70,7 +70,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch archive in the directory PATH.  This
         archive will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_archive
+          cleanup->_vcs_cleanup->_remove_archive
         """
         # http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive
         assert self._archive_name == None
@@ -112,7 +112,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch project in the directory PATH.  This
         project will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_project
+          cleanup->_vcs_cleanup->_remove_project
         """
         # http://mwolson.org/projects/GettingStartedWithArch.html
         # http://regexps.srparish.net/tutorial-tla/new-project.html#Starting_a_New_Project
index c4f0f9192b327035f90c8a88689f60a6044d6ccb..532416315b394e60c6d17f5f2529831c026a5848 100644 (file)
@@ -305,6 +305,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.root = self._find_root(root)
         else:
             if not os.path.exists(root):
+                self.root = None
                 raise NoRootEntry(root)
             self.root = root
         # get a temporary vcs until we've loaded settings
@@ -324,9 +325,6 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.vcs = vcs
             self._setup_user_id(self.user_id)
 
-    def __del__(self):
-        self.cleanup()
-
     def cleanup(self):
         self.vcs.cleanup()
 
@@ -339,6 +337,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         then only if sink_to_existing_root == True.
         """
         if not os.path.exists(path):
+            self.root = None
             raise NoRootEntry(path)
         versionfile=utility.search_parent_directories(path,
                                                       os.path.join(".be", "version"))
@@ -349,6 +348,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         else:
             beroot = utility.search_parent_directories(path, ".be")
             if beroot == None:
+                self.root = None
                 raise NoBugDir(path)
             return beroot
 
@@ -671,7 +671,7 @@ class SimpleBugDir (BugDir):
                     assert_new_BugDir=assert_new_BugDir,
                     allow_vcs_init=vcs_init,
                     manipulate_encodings=False)
-        if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
+        if sync_with_disk == True: # postpone cleanup since dir.cleanup() removes dir.
             self._dir_ref = dir
         bug_a = self.new_bug("a", summary="Bug A")
         bug_a.creator = "John Doe <jdoe@example.com>"
index e9e0649615ef86a0c618228fa091f3f42c1f2221..ed9e03297b10d4b0641f94c282b128242ddbc91b 100644 (file)
@@ -37,8 +37,8 @@ class Bzr(vcs.VCS):
     name = "bzr"
     client = "bzr"
     versioned = True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output        
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".bzr") != None :
index 16005f2a71e065f2fbb8155920bf0fabea6632a9..91158860f14e0a32d48673ee5a5968ded1806b74 100644 (file)
@@ -40,8 +40,10 @@ class Darcs(vcs.VCS):
     name="darcs"
     client="darcs"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
+        num_part = output.split(" ")[0]
+        self.parsed_version = [int(i) for i in num_part.split(".")]
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, "_darcs") != None :
@@ -95,20 +97,20 @@ class Darcs(vcs.VCS):
     def _vcs_get_file_contents(self, path, revision=None, binary=False):
         if revision == None:
             return vcs.VCS._vcs_get_file_contents(self, path, revision,
-                                              binary=binary)
+                                                  binary=binary)
         else:
-            try:
-                return self._u_invoke_client("show", "contents", "--patch", revision, path)
-            except vcs.CommandError:
+            if self.parsed_version[0] >= 2:
+                status,output,error = self._u_invoke_client( \
+                    "show", "contents", "--patch", revision, path)
+                return output
+            else:
                 # Darcs versions < 2.0.0pre2 lack the "show contents" command
 
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--from-patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--from-patch", revision, path)
                 major_patch = output
-                status,output,error = self._u_invoke_client("diff", "--unified",
-                                                            "--patch",
-                                                            revision, path)
+                status,output,error = self._u_invoke_client( \
+                    "diff", "--unified", "--patch", revision, path)
                 target_patch = output
                 
                 # "--output -" to be supported in GNU patch > 2.5.9
index 3abe3b816bd4bc5c63ed22f7578e7fe62391e416..628f9b9697f4273e75e59663a84f6722ceb8df48 100644 (file)
@@ -36,8 +36,8 @@ class Git(vcs.VCS):
     name="git"
     client="git"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".git") != None :
index f8f8121dd9f63669e7bbfb7a592427ecc6c1105a..7cd4c2fa60146110c4fb372df5dd888c7401d25b 100644 (file)
@@ -36,8 +36,8 @@ class Hg(vcs.VCS):
     name="hg"
     client="hg"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Mercurial"""
index aafbf8d164c5d77b446114d28347299c450c9b38..1e4351603c1d1a0bd3b9b94bc628bf46eefcba1d 100644 (file)
@@ -58,13 +58,10 @@ class Dir (object):
     "A temporary directory for testing use"
     def __init__(self):
         self.path = tempfile.mkdtemp(prefix="BEtest")
-        self.rmtree = shutil.rmtree # save local reference for __del__
         self.removed = False
-    def __del__(self):
-        self.cleanup()
     def cleanup(self):
         if self.removed == False:
-            self.rmtree(self.path)
+            shutil.rmtree(self.path)
             self.removed = True
     def __call__(self):
         return self.path
index a1d302264700e7993351b3ddda914b8ca50294ab..7b506e8dac3043aef0a58a26e5512b8c7d59e0fa 100644 (file)
@@ -50,7 +50,7 @@ def _get_matching_vcs(matchfn):
         vcs = module.new()
         if matchfn(vcs) == True:
             return vcs
-        del(vcs)
+        vcs.cleanup()
     return VCS()
     
 def vcs_by_name(vcs_name):
@@ -124,15 +124,12 @@ class VCS(object):
         self._duplicateBasedir = None
         self._duplicateDirname = None
         self.encoding = encoding
-    def __del__(self):
-        self.cleanup()
-
-    def _vcs_help(self):
+        self.version = self._get_version()
+    def _vcs_version(self):
         """
-        Return the command help string.
-        (Allows a simple test to see if the client is installed.)
+        Return the VCS version string.
         """
-        pass
+        return "0.0"
     def _vcs_detect(self, path=None):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -231,15 +228,21 @@ class VCS(object):
         specified revision does not exist.
         """
         return None
-    def installed(self):
+    def _get_version(self):
         try:
-            self._vcs_help()
-            return True
+            ret = self._vcs_version()
+            return ret
         except OSError, e:
             if e.errno == errno.ENOENT:
-                return False
+                return None
+            else:
+                raise OSError, e
         except CommandError:
-            return False
+            return None
+    def installed(self):
+        if self.version != None:
+            return True
+        return False
     def detect(self, path="."):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -674,7 +677,7 @@ class VCSTestCase(unittest.TestCase):
         setup_vcs_test_fixtures(self)
 
     def tearDown(self):
-        del(self.vcs)
+        self.vcs.cleanup()
         super(VCSTestCase, self).tearDown()
 
     def full_path(self, rel_path):
@@ -837,6 +840,7 @@ class VCS_commit_TestCase(VCSTestCase):
 
     def test_revision_file_contents_as_committed(self):
         """Should get file contents as committed to specified revision."""
+        import sys
         if not self.vcs.versioned:
             return
         for path in self.test_files: