Skip to content
This repository was archived by the owner on May 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ovh-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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])
Expand Down
5 changes: 4 additions & 1 deletion ovhcli/formater/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# -*- encoding: utf-8 -*-

import os
import pkgutil
import imp

# HACK: ensure yaml/json lib in cache is the global one:
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)