From 779f6508c1d5512457f25cad4905aa6e5cd5d2be Mon Sep 17 00:00:00 2001 From: Mathieu Clabaut Date: Wed, 30 Nov 2016 14:40:28 +0100 Subject: [PATCH] Makes ovh-cli working when called outside of the repo. close #9 --- ovh-cli.py | 10 +++++++--- ovhcli/formater/__init__.py | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ovh-cli.py b/ovh-cli.py index 6a4fbf8..1a202bb 100755 --- a/ovh-cli.py +++ b/ovh-cli.py @@ -42,6 +42,9 @@ import sys import ovh +OVHCLIDIR = os.path.split(os.path.realpath(__file__))[0] +sys.path.insert(0, OVHCLIDIR) + from ovhcli.utils import camel_to_snake from ovhcli.schema import load_schemas, SCHEMAS_BASE_PATH, SCHEMAS from ovhcli.formater import formaters, get_formater @@ -93,7 +96,8 @@ def init_arg_parser(endpoint, refresh=False): :param boolean refresh: when ``True``, bypass cache, no matter its state. ''' - cache_file = SCHEMAS_BASE_PATH+endpoint + schemas_base_path = os.path.join(OVHCLIDIR, SCHEMAS_BASE_PATH) + cache_file = os.path.join( schemas_base_path, endpoint) # First attempt to load parser from cache try: @@ -104,8 +108,8 @@ def init_arg_parser(endpoint, refresh=False): pass # cache dir exists ? - if not os.path.exists(SCHEMAS_BASE_PATH): - os.makedirs(SCHEMAS_BASE_PATH) + if not os.path.exists(schemas_base_path): + os.makedirs(schemas_base_path) # get schemas load_schemas(ENDPOINTS[endpoint]) diff --git a/ovhcli/formater/__init__.py b/ovhcli/formater/__init__.py index 1ae1cc0..59397a6 100644 --- a/ovhcli/formater/__init__.py +++ b/ovhcli/formater/__init__.py @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- +import os import pkgutil import imp @@ -7,7 +8,9 @@ import yaml import json -formaters = dict([(name, importer) for importer, name, _ in pkgutil.iter_modules(['ovhcli/formater'])]) +FORMATERDIR = os.path.split(os.path.realpath(__file__))[0] + +formaters = dict([(name, importer) for importer, name, _ in pkgutil.iter_modules([FORMATERDIR])]) def get_formater(name): return formaters[name].find_module(name).load_module(name)