Moved InvalidStorageVersion from libbe.command to libbe.storage
authorW. Trevor King <wking@drexel.edu>
Sun, 27 Dec 2009 21:50:36 +0000 (16:50 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 27 Dec 2009 21:50:36 +0000 (16:50 -0500)
Also added ConnectionError pretty-print to ui.command_line, storage
version checking to BugDir.duplicate_bugdir(), and optional revision
argument to Storage.storage_version().

libbe/bugdir.py
libbe/command/__init__.py
libbe/command/base.py
libbe/storage/__init__.py
libbe/storage/base.py
libbe/storage/vcs/base.py
libbe/ui/command_line.py

index 9d90a70702dc8df7834a16650956ff1efb1a6ede..50dc8ba7f6f2e2368d0e212210bb1764f9a07987 100644 (file)
@@ -295,6 +295,9 @@ class BugDir (list, settings_object.SavedSettingsObject):
         Duplicate bugdirs are read-only copies used for generating
         diffs between revisions.
         """
+        storage_version = self.storage.storage_version(revision)
+        if storage_version != libbe.storage.STORAGE_VERSION:
+            raise libbe.storage.InvalidStorageVersion(storage_version)
         s = copy.deepcopy(self.storage)
         s.writeable = False
         class RevisionedStorageGet (object):
index ab9d2dbc9e2a50c31c3a916b306b9aa01bf7e94e..916b5ce90b4832b58b9a01f579d281ddd5ee815a 100644 (file)
@@ -19,7 +19,6 @@ import base
 
 UserError = base.UserError
 UnknownCommand = base.UnknownCommand
-InvalidStorageVersion = base.InvalidStorageVersion
 get_command = base.get_command
 get_command_class = base.get_command_class
 commands = base.commands
@@ -27,6 +26,5 @@ Option = base.Option
 Argument = base.Argument
 Command = base.Command
 
-__all__ = [UserError, UnknownCommand, InvalidStorageVersion,
-           get_command, get_command_class,
+__all__ = [UserError, UnknownCommand, get_command, get_command_class,
            commands, Option, Argument, Command]
index 1409c7449bf707ec10b2aec2c34b1f94e075e083..ac6a58b79d1f0139963ec171409c6840784a6a25 100644 (file)
@@ -19,16 +19,6 @@ class UnknownCommand(UserError):
         Exception.__init__(self, "Unknown command '%s'" % cmd)
         self.cmd = cmd
 
-class InvalidStorageVersion(UserError):
-    def __init__(self, active_version, expected_version=None):
-        if expected_version == None:
-            expected_version = libbe.storage.STORAGE_VERSION
-        msg = 'Storage in "%s" not the expected "%s"' \
-            % (active_version, expected_version)
-        UserError.__init__(self, msg)
-        self.active_version = active_version
-        self.expected_version = expected_version
-
 def get_command(command_name):
     """Retrieves the module for a user command
 
@@ -366,7 +356,7 @@ class Command (object):
             self._storage.connect()
             version = self._storage.storage_version()
             if version != libbe.storage.STORAGE_VERSION:
-                raise InvalidStorageVersion(version)
+                raise libbe.storage.InvalidStorageVersion(version)
         return self._storage
 
     def _get_bugdir(self):
index 104b1e1dfe362052d1f97f21b6f2619e2a42f9ad..e99f799e08b6dd8868500d4da9d3ac34019c816d 100644 (file)
@@ -3,6 +3,7 @@
 import base
 
 ConnectionError = base.ConnectionError
+InvalidStorageVersion = base.InvalidStorageVersion
 InvalidID = base.InvalidID
 InvalidRevision = base.InvalidRevision
 InvalidDirectory = base.InvalidDirectory
@@ -30,7 +31,7 @@ def get_storage(location):
     s.repo = location
     return s
 
-__all__ = [ConnectionError, InvalidID, InvalidRevision,
-           InvalidDirectory, NotWriteable, NotReadable,
+__all__ = [ConnectionError, InvalidStorageVersion, InvalidID,
+           InvalidRevision, InvalidDirectory, NotWriteable, NotReadable,
            EmptyCommit, STORAGE_VERSIONS, STORAGE_VERSION,
            get_storage]
index f32353ff0144f27e1e7cd8dd4717a036beb2feb0..b43f765361a092cffe81b579404ef737dd98507d 100644 (file)
@@ -26,6 +26,16 @@ if TESTING == True:
 class ConnectionError (Exception):
     pass
 
+class InvalidStorageVersion(ConnectionError):
+    def __init__(self, active_version, expected_version=None):
+        if expected_version == None:
+            expected_version = libbe.storage.STORAGE_VERSION
+        msg = 'Storage in "%s" not the expected "%s"' \
+            % (active_version, expected_version)
+        Exception.__init__(self, msg)
+        self.active_version = active_version
+        self.expected_version = expected_version
+
 class InvalidID (KeyError):
     pass
 
@@ -50,6 +60,7 @@ class EmptyCommit(Exception):
     def __init__(self):
         Exception.__init__(self, 'No changes to commit')
 
+
 class Entry (Tree):
     def __init__(self, id, value=None, parent=None, directory=False,
                  children=None):
@@ -134,7 +145,7 @@ class Storage (object):
         """Return a version string for this backend."""
         return '0'
 
-    def storage_version(self):
+    def storage_version(self, revision=None):
         """Return the storage format for this backend."""
         return libbe.storage.STORAGE_VERSION
 
index 1df08cf91e2559a5bd7f25af830190a88f6e7099..e96b46657533194a30efdc909f20b805607b2387 100644 (file)
@@ -32,6 +32,7 @@ import re
 import shutil
 import sys
 import tempfile
+import types
 
 import libbe
 import libbe.storage
@@ -885,15 +886,19 @@ os.listdir(self.get_path("bugs")):
         if version != libbe.storage.STORAGE_VERSION:
             upgrade.upgrade(self.repo, version)
 
-    def storage_version(self, path=None):
+    def storage_version(self, revision=None, path=None):
         """
         Requires disk access.
         """
         if path == None:
             path = os.path.join(self.repo, '.be', 'version')
-        return libbe.util.encoding.get_file_contents(
-            path, decode=True).rstrip('\n')
-
+        if revision == None: # don't require connection
+            return libbe.util.encoding.get_file_contents(
+                path, decode=True).rstrip('\n')
+        contents = self._vcs_get_file_contents(path, revision=revision)
+        if type(contents) != types.UnicodeType:
+            contents = unicode(contents, self.encoding)
+        return contents.strip()
 
 \f
 if libbe.TESTING == True:
index 6eead671b2bea455df6a379ea2ae8271bc3580ce..38127891507bd860cdafe5e9d60ccd1bde3cce88 100755 (executable)
@@ -284,6 +284,10 @@ def main():
         command.cleanup()
         print 'ERROR:\n', e
         return 1
+    except libbe.storage.ConnectionError, e:
+        command.cleanup()
+        print 'Connection Error:\n', e
+        return 1
     command.cleanup()
     return 0