summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiall Mac Innes <kiall@hp.com>2013-04-12 13:33:13 +0100
committerKiall Mac Innes <kiall@hp.com>2013-04-12 13:33:13 +0100
commitd9188704f4b1cdb015a45f70de5bb8b642917c6f (patch)
treec8445901475b88006d20b775a6080a65ed86f24b
parent84d326920fc9e6592b8fe9a56adaf6be0d9358c3 (diff)
downloadpython-designateclient-0.0.3.tar.gz
Support loading resources from 3rd party packages. E.g. client extensions0.0.3
Change-Id: I919c915802632d0c72fbec8bcb28085661334b34
-rw-r--r--monikerclient/utils.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/monikerclient/utils.py b/monikerclient/utils.py
index 5501dc9..8618a10 100644
--- a/monikerclient/utils.py
+++ b/monikerclient/utils.py
@@ -19,21 +19,27 @@ import json
from monikerclient import exceptions
-def resource_string(*args):
+def resource_string(*args, **kwargs):
if len(args) == 0:
raise ValueError()
+ package = kwargs.pop('package', None)
+
+ if not package:
+ package = 'monikerclient'
+
resource_path = os.path.join('resources', *args)
- if not pkg_resources.resource_exists('monikerclient', resource_path):
+ if not pkg_resources.resource_exists(package, resource_path):
raise exceptions.ResourceNotFound('Could not find the requested '
'resource: %s' % resource_path)
- return pkg_resources.resource_string('monikerclient', resource_path)
+ return pkg_resources.resource_string(package, resource_path)
-def load_schema(version, name):
- schema_string = resource_string('schemas', version, '%s.json' % name)
+def load_schema(version, name, package=None):
+ schema_string = resource_string('schemas', version, '%s.json' % name,
+ package=package)
return json.loads(schema_string)