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/mapfile.py | |
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/mapfile.py')
-rw-r--r-- | libbe/storage/util/mapfile.py | 48 |
1 files changed, 31 insertions, 17 deletions
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() |