diff options
author | W. Trevor King <wking@tremily.us> | 2012-10-26 13:18:21 -0400 |
---|---|---|
committer | W. Trevor King <wking@tremily.us> | 2012-10-26 13:18:24 -0400 |
commit | 7df9852ddf77304dde98217c71910723602dbde1 (patch) | |
tree | 35b041e780ab6f23d338a2b6d79a160493b6afb8 /libbe/storage | |
parent | 1f771c68eec0cb191bd7d82f0f08134850a88e62 (diff) | |
download | bugseverywhere-7df9852ddf77304dde98217c71910723602dbde1.tar.gz |
storage:util:upgrade: make yaml import optional (unless it isn't)
Importing `yaml` may fail (if the user doesn't have PyYAML installed),
but don't die until we need to use it. This way users without the old
YAML formats on disk can run BE without installing PyYAML.
Diffstat (limited to 'libbe/storage')
-rw-r--r-- | libbe/storage/util/upgrade.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libbe/storage/util/upgrade.py b/libbe/storage/util/upgrade.py index fdbc578..98091f2 100644 --- a/libbe/storage/util/upgrade.py +++ b/libbe/storage/util/upgrade.py @@ -27,7 +27,11 @@ import os, os.path import sys import types -import yaml +try: + import yaml +except ImportError as e: + yaml = None + _yaml_import_error = e import libbe import libbe.bug @@ -50,6 +54,8 @@ def generate_yaml_mapfile(map): >>> generate_yaml_mapfile({'q':u'hello'}) 'q: hello\\n\\n' """ + if yaml is None: + raise _yaml_import_error keys = map.keys() keys.sort() for key in keys: @@ -93,6 +99,8 @@ def parse_yaml_mapfile(contents): >>> dict['q'] u'Fran\\xe7ais' """ + if yaml is None: + raise _yaml_import_error c = yaml.safe_load(contents) if type(c) == types.StringType: raise mapfile.InvalidMapfileContents( |