Now commands automatically check for storage version compatibility.
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, get_command, get_command_class,
+__all__ = [UserError, UnknownCommand, InvalidStorageVersion,
+ get_command, get_command_class,
commands, Option, Argument, Command]
import sys
import libbe
+import libbe.storage
import libbe.ui.util.user
import libbe.util.encoding
import libbe.util.plugin
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
if not hasattr(self, '_storage'):
self._storage = self._get_unconnected_storage()
self._storage.connect()
+ version = self._storage.storage_version()
+ if version != libbe.storage.STORAGE_VERSION:
+ raise InvalidStorageVersion(version)
return self._storage
def _get_bugdir(self):
NotReadable = base.NotReadable
EmptyCommit = base.EmptyCommit
+# a list of all past versions
+STORAGE_VERSIONS = ['Bugs Everywhere Tree 1 0',
+ 'Bugs Everywhere Directory v1.1',
+ 'Bugs Everywhere Directory v1.2',
+ 'Bugs Everywhere Directory v1.3',
+ 'Bugs Everywhere Directory v1.4',
+ ]
+
+# the current version
+STORAGE_VERSION = STORAGE_VERSIONS[-1]
+
def get_storage(location):
"""
Return a Storage instance from a repo location string.
__all__ = [ConnectionError, InvalidID, InvalidRevision,
InvalidDirectory, NotWriteable, NotReadable,
- EmptyCommit, get_storage]
+ EmptyCommit, STORAGE_VERSIONS, STORAGE_VERSION,
+ get_storage]
import types
from libbe.error import NotSupported
+import libbe.storage
from libbe.util.tree import Tree
from libbe.util import InvalidObject
from libbe import TESTING
"""Return a version string for this backend."""
return '0'
+ def storage_version(self):
+ """Return the storage format for this backend."""
+ return libbe.storage.STORAGE_VERSION
+
def is_readable(self):
return self.readable and self._readable
import libbe
import libbe.bug
import libbe.storage.util.mapfile as mapfile
+from libbe.storage import STORAGE_VERSIONS, STORAGE_VERSION
#import libbe.storage.vcs # delay import to avoid cyclic dependency
import libbe.ui.util.editor
import libbe.util
import libbe.util.id
-# a list of all past versions
-BUGDIR_DISK_VERSIONS = ['Bugs Everywhere Tree 1 0',
- 'Bugs Everywhere Directory v1.1',
- 'Bugs Everywhere Directory v1.2',
- 'Bugs Everywhere Directory v1.3',
- 'Bugs Everywhere Directory v1.4',
- ]
-
-# the current version
-BUGDIR_DISK_VERSION = BUGDIR_DISK_VERSIONS[-1]
-
class Upgrader (object):
"Class for converting between different on-disk BE storage formats."
initial_version = None
upgrade_classes[(upgrader.initial_version,upgrader.final_version)]=upgrader
def upgrade(path, current_version,
- target_version=BUGDIR_DISK_VERSION):
+ target_version=STORAGE_VERSION):
"""
Call the appropriate upgrade function to convert current_version
to target_version. If a direct conversion function does not exist,
use consecutive conversion functions.
"""
- if current_version not in BUGDIR_DISK_VERSIONS:
+ if current_version not in STORAGE_VERSIONS:
raise NotImplementedError, \
"Cannot handle version '%s' yet." % current_version
- if target_version not in BUGDIR_DISK_VERSIONS:
+ if target_version not in STORAGE_VERSIONS:
raise NotImplementedError, \
"Cannot handle version '%s' yet." % current_version
u.upgrade()
else:
# consecutive single-step conversion
- i = BUGDIR_DISK_VERSIONS.index(current_version)
+ i = STORAGE_VERSIONS.index(current_version)
while True:
- version_a = BUGDIR_DISK_VERSIONS[i]
- version_b = BUGDIR_DISK_VERSIONS[i+1]
+ version_a = STORAGE_VERSIONS[i]
+ version_b = STORAGE_VERSIONS[i+1]
try:
upgrade_class = upgrade_classes[(version_a, version_b)]
except KeyError:
import tempfile
import libbe
+import libbe.storage
import libbe.storage.base
import libbe.util.encoding
from libbe.storage.base import EmptyCommit, InvalidRevision
if not os.path.isdir(self.be_dir):
raise libbe.storage.base.ConnectionError(self)
self._cached_path_id.connect()
- self.check_disk_version()
+ self.check_storage_version()
def disconnect(self):
self._cached_path_id.disconnect()
f.close()
return (summary, body)
- def check_disk_version(self):
- version = self.disk_version()
- if version != upgrade.BUGDIR_DISK_VERSION:
+ def check_storage_version(self):
+ version = self.storage_version()
+ if version != libbe.storage.STORAGE_VERSION:
upgrade.upgrade(self.repo, version)
- def disk_version(self, path=None):
+ def storage_version(self, path=None):
"""
Requires disk access.
"""
if path == None:
path = os.path.join(self.repo, '.be', 'version')
- return libbe.util.encoding.get_file_contents(path).rstrip('\n')
+ return libbe.util.encoding.get_file_contents(
+ path, decode=True).rstrip('\n')
\f
import copy
import libbe._version as _version
-import libbe.storage.util.upgrade as upgrade
+import libbe.storage
# Manually set a version string (optional, defaults to bzr revision id)
#_VERSION = "1.2.3"
string = _version.version_info["revision_id"]
if verbose == True:
info = copy.copy(_version.version_info)
- info['storage'] = upgrade.BUGDIR_DISK_VERSION
+ info['storage'] = libbe.storage.STORAGE_VERSION
string += ("\n"
"revision: %(revno)d\n"
"nick: %(branch_nick)s\n"