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):
UserError = base.UserError
UnknownCommand = base.UnknownCommand
-InvalidStorageVersion = base.InvalidStorageVersion
get_command = base.get_command
get_command_class = base.get_command_class
commands = base.commands
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]
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
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):
import base
ConnectionError = base.ConnectionError
+InvalidStorageVersion = base.InvalidStorageVersion
InvalidID = base.InvalidID
InvalidRevision = base.InvalidRevision
InvalidDirectory = base.InvalidDirectory
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]
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
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):
"""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
import shutil
import sys
import tempfile
+import types
import libbe
import libbe.storage
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:
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