diff options
-rw-r--r-- | libbe/bugdir.py | 3 | ||||
-rw-r--r-- | libbe/command/__init__.py | 4 | ||||
-rw-r--r-- | libbe/command/base.py | 12 | ||||
-rw-r--r-- | libbe/storage/__init__.py | 5 | ||||
-rw-r--r-- | libbe/storage/base.py | 13 | ||||
-rw-r--r-- | libbe/storage/vcs/base.py | 13 | ||||
-rwxr-xr-x | libbe/ui/command_line.py | 4 |
7 files changed, 33 insertions, 21 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 9d90a70..50dc8ba 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -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): diff --git a/libbe/command/__init__.py b/libbe/command/__init__.py index ab9d2db..916b5ce 100644 --- a/libbe/command/__init__.py +++ b/libbe/command/__init__.py @@ -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] diff --git a/libbe/command/base.py b/libbe/command/base.py index 1409c74..ac6a58b 100644 --- a/libbe/command/base.py +++ b/libbe/command/base.py @@ -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): diff --git a/libbe/storage/__init__.py b/libbe/storage/__init__.py index 104b1e1..e99f799 100644 --- a/libbe/storage/__init__.py +++ b/libbe/storage/__init__.py @@ -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] diff --git a/libbe/storage/base.py b/libbe/storage/base.py index f32353f..b43f765 100644 --- a/libbe/storage/base.py +++ b/libbe/storage/base.py @@ -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 diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 1df08cf..e96b466 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -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() if libbe.TESTING == True: diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py index 6eead67..3812789 100755 --- a/libbe/ui/command_line.py +++ b/libbe/ui/command_line.py @@ -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 |