diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-15 06:44:20 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-15 06:44:20 -0500 |
commit | 89b7a1411e4658e831f5d635534b24355dbb941d (patch) | |
tree | 77f84979931ac4bf8bcf14d293154fe29e8491bc /libbe/storage/util | |
parent | 380889988b6d7881c4e0b5968053f85676d27211 (diff) | |
download | bugseverywhere-89b7a1411e4658e831f5d635534b24355dbb941d.tar.gz |
Fixed libbe.command.diff + ugly BugDir.duplicate_bugdir implementation
duplicate_bugdir() works, but for the vcs backends, it could require
shelling out for _every_ file read. This could, and probably will, be
horribly slow. Still it works ;).
I'm not sure what a better implementation would be. The old
implementation checked out the entire earlier state into a temporary
directory
pros: single shell out, simple upgrade implementation
cons: wouldn't work well for HTTP backens
I think a good solution would run along the lines of the currently
commented out code in duplicate_bugdir(), where a
VersionedStorage.changed_since(revision)
call would give you a list of changed files. diff could work off of
that directly, without the need to generate a whole duplicate bugdir.
I'm stuck on how to handle upgrades though...
Also removed trailing whitespace from all python files.
Diffstat (limited to 'libbe/storage/util')
-rw-r--r-- | libbe/storage/util/config.py | 2 | ||||
-rw-r--r-- | libbe/storage/util/mapfile.py | 48 | ||||
-rw-r--r-- | libbe/storage/util/settings_object.py | 5 | ||||
-rw-r--r-- | libbe/storage/util/upgrade.py | 36 |
4 files changed, 52 insertions, 39 deletions
diff --git a/libbe/storage/util/config.py b/libbe/storage/util/config.py index a0a252e..9f95d14 100644 --- a/libbe/storage/util/config.py +++ b/libbe/storage/util/config.py @@ -46,7 +46,7 @@ def set_val(name, value, section="DEFAULT", encoding=None): if encoding == None: encoding = default_encoding config = ConfigParser.ConfigParser() - if os.path.exists(path()) == False: # touch file or config + if os.path.exists(path()) == False: # touch file or config open(path(), 'w').close() # read chokes on missing file f = codecs.open(path(), 'r', encoding) config.readfp(f, path()) diff --git a/libbe/storage/util/mapfile.py b/libbe/storage/util/mapfile.py index a8d5516..35ae1a0 100644 --- a/libbe/storage/util/mapfile.py +++ b/libbe/storage/util/mapfile.py @@ -24,6 +24,7 @@ independent/conflicting changes. import errno import os.path +import types import yaml import libbe @@ -39,32 +40,37 @@ class IllegalKey(Exception): class IllegalValue(Exception): def __init__(self, value): Exception.__init__(self, 'Illegal value "%s"' % value) - self.value = value + self.value = value + +class InvalidMapfileContents(Exception): + def __init__(self, contents): + Exception.__init__(self, 'Invalid YAML contents') + self.contents = contents def generate(map): """Generate a YAML mapfile content string. - >>> generate({"q":"p"}) + >>> generate({'q':'p'}) 'q: p\\n\\n' - >>> generate({"q":u"Fran\u00e7ais"}) + >>> generate({'q':u'Fran\u00e7ais'}) 'q: Fran\\xc3\\xa7ais\\n\\n' - >>> generate({"q":u"hello"}) + >>> generate({'q':u'hello'}) 'q: hello\\n\\n' - >>> generate({"q=":"p"}) + >>> generate({'q=':'p'}) Traceback (most recent call last): IllegalKey: Illegal key "q=" - >>> generate({"q:":"p"}) + >>> generate({'q:':'p'}) Traceback (most recent call last): IllegalKey: Illegal key "q:" - >>> generate({"q\\n":"p"}) + >>> generate({'q\\n':'p'}) Traceback (most recent call last): IllegalKey: Illegal key "q\\n" - >>> generate({"":"p"}) + >>> generate({'':'p'}) Traceback (most recent call last): IllegalKey: Illegal key "" - >>> generate({">q":"p"}) + >>> generate({'>q':'p'}) Traceback (most recent call last): IllegalKey: Illegal key ">q" - >>> generate({"q":"p\\n"}) + >>> generate({'q':'p\\n'}) Traceback (most recent call last): IllegalValue: Illegal value "p\\n" """ @@ -97,20 +103,28 @@ def parse(contents): 'p' >>> parse('q: \\'p\\'\\n\\n')['q'] 'p' - >>> contents = generate({"a":"b", "c":"d", "e":"f"}) + >>> contents = generate({'a':'b', 'c':'d', 'e':'f'}) >>> dict = parse(contents) - >>> dict["a"] + >>> dict['a'] 'b' - >>> dict["c"] + >>> dict['c'] 'd' - >>> dict["e"] + >>> dict['e'] 'f' - >>> contents = generate({"q":u"Fran\u00e7ais"}) + >>> contents = generate({'q':u'Fran\u00e7ais'}) >>> dict = parse(contents) - >>> dict["q"] + >>> dict['q'] u'Fran\\xe7ais' + >>> dict = parse('a!') + Traceback (most recent call last): + ... + InvalidMapfileContents: Invalid YAML contents """ - return yaml.load(contents) or {} + c = yaml.load(contents) + if type(c) == types.StringType: + raise InvalidMapfileContents( + 'Unable to parse YAML (BE format missmatch?):\n\n%s' % contents) + return c or {} if libbe.TESTING == True: suite = doctest.DocTestSuite() diff --git a/libbe/storage/util/settings_object.py b/libbe/storage/util/settings_object.py index 760df03..8b86829 100644 --- a/libbe/storage/util/settings_object.py +++ b/libbe/storage/util/settings_object.py @@ -197,9 +197,8 @@ class SavedSettingsObject(object): settings as primed. """ for property in self.settings_properties: - if property not in self.settings: - self.settings[property] = EMPTY - elif self.settings[property] == UNPRIMED: + if property not in self.settings \ + or self.settings[property] == UNPRIMED: self.settings[property] = EMPTY if flag_as_loaded == True: self._settings_loaded = True diff --git a/libbe/storage/util/upgrade.py b/libbe/storage/util/upgrade.py index 7ef760e..c94f171 100644 --- a/libbe/storage/util/upgrade.py +++ b/libbe/storage/util/upgrade.py @@ -24,17 +24,16 @@ import sys import libbe import libbe.bug as bug -import libbe.util.encoding as encoding import libbe.storage.util.mapfile as mapfile +import libbe.util.encoding as encoding +import libbe.util.id -if libbe.TESTING == True: - import doctest # 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"] +BUGDIR_DISK_VERSIONS = ['Bugs Everywhere Tree 1 0', + 'Bugs Everywhere Directory v1.1', + 'Bugs Everywhere Directory v1.2', + 'Bugs Everywhere Directory v1.3'] # the current version BUGDIR_DISK_VERSION = BUGDIR_DISK_VERSIONS[-1] @@ -43,13 +42,17 @@ class Upgrader (object): "Class for converting between different on-disk BE storage formats." initial_version = None final_version = None - def __init__(self, root): - self.root = root + def __init__(self, repo): + self.repo = repo - def get_path(self, *args): + def get_path(self, id): """ - Return a path relative to .root. + Return a path relative to .repo. """ + if id == 'version': + return os.path.join(self.repo, id) + +TODO dir = os.path.join(self.root, '.be') if len(args) == 0: return dir @@ -58,15 +61,15 @@ class Upgrader (object): def check_initial_version(self): path = self.get_path('version') - version = self.vcs.get_file_contents(path).rstrip('\n') + version = encoding.get_file_contents(path).rstrip('\n') assert version == self.initial_version, version def set_version(self): - path = self.get_path("version") - self.vcs.set_file_contents(path, self.final_version+"\n") + path = self.get_path('version') + encoding.set_file_contents(path, self.final_version+'\n') def upgrade(self): - print >> sys.stderr, "upgrading bugdir from '%s' to '%s'" \ + print >> sys.stderr, 'upgrading bugdir from "%s" to "%s"' \ % (self.initial_version, self.final_version) self.check_initial_version() self.set_version() @@ -237,6 +240,3 @@ def upgrade(path, current_version, if version_b == target_version: break i += 1 - -if libbe.TESTING == True: - suite = doctest.DocTestSuite() |