Run black on all Python scripts!
This commit is contained in:
parent
fb6cfce656
commit
cd9cbcaa28
30 changed files with 1027 additions and 704 deletions
|
@ -10,15 +10,17 @@ import logging
|
|||
import coloredlogs
|
||||
import argparse
|
||||
|
||||
coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s')
|
||||
coloredlogs.install(level="DEBUG", fmt="%(levelname)s %(message)s")
|
||||
log = logging.getLogger()
|
||||
|
||||
debug = None
|
||||
|
||||
class OvhCli():
|
||||
|
||||
class OvhCli:
|
||||
ROOT = "https://api.ovh.com/1.0?null"
|
||||
|
||||
def __init__(self):
|
||||
self.cacheDir = os.path.join(xdg.BaseDirectory.xdg_cache_home, 'ovhcli')
|
||||
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)
|
||||
|
@ -26,18 +28,18 @@ class OvhCli():
|
|||
|
||||
def updateCache(self):
|
||||
log.info("Downloading the API description")
|
||||
rootJsonPath = os.path.join(self.cacheDir, 'root.json')
|
||||
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:
|
||||
with open(rootJsonPath, "rt") as rootJson:
|
||||
root = json.load(rootJson)
|
||||
basePath = root['basePath']
|
||||
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)
|
||||
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}")
|
||||
|
@ -47,11 +49,11 @@ class OvhCli():
|
|||
urllib.request.urlretrieve(apiJsonUrl, apiJsonPath)
|
||||
|
||||
def createParser(self):
|
||||
parser = argparse.ArgumentParser(description='Access the OVH API')
|
||||
parser = argparse.ArgumentParser(description="Access the OVH API")
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
cli = OvhCli()
|
||||
# cli.updateCache()
|
||||
parser = cli.createParser()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue