7 changed files with 136 additions and 30 deletions
-
6config/mypy/config
-
2config/scripts/mel
-
59config/scripts/ovhcli
-
61config/vim/pluginconfig.vim
-
31config/vim/pluginlist.vim
-
1config/vim/vimconfig.vim
-
6config/vim/vimrc
@ -0,0 +1,6 @@ |
|||
[mypy] |
|||
ignore_missing_imports = True |
|||
disallow_untyped_defs = True |
|||
disallow_untyped_calls = True |
|||
disallow_incomplete_defs = True |
|||
disallow_untyped_decorators = True |
@ -0,0 +1,59 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import os |
|||
import ovh |
|||
import xdg.BaseDirectory |
|||
import urllib.request |
|||
from pprint import pprint |
|||
import json |
|||
import logging |
|||
import coloredlogs |
|||
import argparse |
|||
|
|||
coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s') |
|||
log = logging.getLogger() |
|||
|
|||
debug = None |
|||
|
|||
class OvhCli(): |
|||
ROOT = "https://api.ovh.com/1.0?null" |
|||
def __init__(self): |
|||
self.cacheDir = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'ovhcli') |
|||
# TODO Corner cases: links, cache dir not done, configurable cache |
|||
if not os.path.isdir(self.cacheDir): |
|||
assert not os.path.exists(self.cacheDir) |
|||
os.makedirs(self.cacheDir) |
|||
|
|||
def updateCache(self): |
|||
log.info("Downloading the API description") |
|||
rootJsonPath = os.path.join(self.cacheDir, 'root.json') |
|||
log.debug(f"{self.ROOT} -> {rootJsonPath}") |
|||
urllib.request.urlretrieve(self.ROOT, rootJsonPath) |
|||
with open(rootJsonPath, 'rt') as rootJson: |
|||
root = json.load(rootJson) |
|||
basePath = root['basePath'] |
|||
|
|||
for apiRoot in root['apis']: |
|||
fmt = 'json' |
|||
assert fmt in apiRoot['format'] |
|||
path = apiRoot['path'] |
|||
schema = apiRoot['schema'].format(format=fmt, path=path) |
|||
apiJsonPath = os.path.join(self.cacheDir, schema[1:]) |
|||
apiJsonUrl = basePath + schema |
|||
log.debug(f"{apiJsonUrl} -> {apiJsonPath}") |
|||
apiJsonPathDir = os.path.dirname(apiJsonPath) |
|||
if not os.path.isdir(apiJsonPathDir): |
|||
os.makedirs(apiJsonPathDir) |
|||
urllib.request.urlretrieve(apiJsonUrl, apiJsonPath) |
|||
|
|||
def createParser(self): |
|||
parser = argparse.ArgumentParser(description='Access the OVH API') |
|||
return parser |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
cli = OvhCli() |
|||
# cli.updateCache() |
|||
parser = cli.createParser() |
|||
args = parser.parse_args() |
|||
print(args) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue