From: W. Trevor King Date: Fri, 26 Oct 2012 17:18:21 +0000 (-0400) Subject: storage:util:upgrade: make yaml import optional (unless it isn't) X-Git-Tag: 1.1.0~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7df9852ddf77304dde98217c71910723602dbde1;p=be.git 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. --- 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(