Lint: app.py
This commit is contained in:
parent
ac0e4e8237
commit
4b04ef19a0
@ -1,27 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# import sys
|
||||
# sys.path.append("/home/jez/prj/bell/training/tiger-ansible/ext/ansible-tree")
|
||||
|
||||
"""Kheops App interface"""
|
||||
|
||||
import sys
|
||||
import yaml
|
||||
import anyconfig
|
||||
from pprint import pprint
|
||||
|
||||
from kheops.query import Query
|
||||
from kheops.utils import schema_validate
|
||||
import anyconfig
|
||||
|
||||
# from box import Box
|
||||
import logging
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import logging
|
||||
import anyconfig
|
||||
|
||||
from kheops.utils import schema_validate
|
||||
from kheops.query import Query
|
||||
import kheops.plugin as KheopsPlugins
|
||||
from kheops.managers import BackendsManager, RulesManager
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class App:
|
||||
"""Main Kheops Application Instance"""
|
||||
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
@ -61,7 +56,7 @@ class App:
|
||||
"type": "string",
|
||||
"description": "Application working directory. If a relative path is used, it will be depending on `kheops.yml` directory",
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -81,9 +76,9 @@ class App:
|
||||
"type": "string",
|
||||
"description": "Add a path prefix before all paths. This is quite useful to store your YAML data in a dedicated tree.",
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"type": "object",
|
||||
@ -118,7 +113,7 @@ class App:
|
||||
try:
|
||||
conf2 = conf2[namespace]
|
||||
except KeyError:
|
||||
log.error(f"Can't find namespace '{namespace}' in config '{config}'")
|
||||
log.error("Can't find namespace '%s' in config '%s'", namespace, config)
|
||||
sys.exit(1)
|
||||
|
||||
# Get application paths
|
||||
@ -146,12 +141,11 @@ class App:
|
||||
path_cwd = str(Path.cwd().resolve())
|
||||
path_root = str(path_root.resolve())
|
||||
|
||||
self.run['path_cwd'] = path_cwd
|
||||
self.run['path_root'] = path_root
|
||||
self.run["path_cwd"] = path_cwd
|
||||
self.run["path_root"] = path_root
|
||||
|
||||
# self.run['path_prefix'] = str(p.resolve())
|
||||
log.debug (f"Working directory is {path_root} while cwd is: {path_cwd}")
|
||||
|
||||
log.debug("Working directory is %s, cwd is: %s", path_root, path_cwd)
|
||||
|
||||
# path_root = path_root.resolve().relative_to(Path.cwd())
|
||||
|
||||
@ -164,41 +158,32 @@ class App:
|
||||
log.debug("Root directory is: %s", path_root)
|
||||
|
||||
def lookup(self, key=None, policy=None, scope=None, trace=False, explain=False):
|
||||
log.debug(f"Lookup key {key} with scope: {scope}")
|
||||
q = Query(app=self)
|
||||
r = q.exec(key=key, scope=scope, policy=policy, trace=trace, explain=explain)
|
||||
|
||||
return r
|
||||
|
||||
#print("=== Query Result ===")
|
||||
print(anyconfig.dumps(r, ac_parser=fmt))
|
||||
#print("=== Query Result ===")
|
||||
"""Lookup a key in hierarchy"""
|
||||
log.debug("Lookup key %s with scope: %s", key, scope)
|
||||
query = Query(app=self)
|
||||
ret = query.exec(key=key, scope=scope, policy=policy, trace=trace, explain=explain)
|
||||
return ret
|
||||
|
||||
def dump_schema(self):
|
||||
"""Dump configuration schema"""
|
||||
|
||||
import json
|
||||
import kheops.plugin as KheopsPlugins
|
||||
from kheops.managers import BackendsManager, RulesManager
|
||||
|
||||
r1 = BackendsManager.get_schema(KheopsPlugins, mode='parts')
|
||||
r2 = RulesManager.get_schema(KheopsPlugins)
|
||||
#pprint (r1)
|
||||
print(json.dumps(r1, indent=2))
|
||||
ret1 = BackendsManager.get_schema(KheopsPlugins, mode="parts")
|
||||
ret2 = RulesManager.get_schema(KheopsPlugins)
|
||||
print(json.dumps(ret1, indent=2))
|
||||
return
|
||||
|
||||
d = self.schema
|
||||
d["patternProperties"][".*"]["properties"]["tree"]["items"]["properties"] = r1
|
||||
d["patternProperties"][".*"]["properties"]["tree"]["items"] = r2
|
||||
|
||||
print(json.dumps(d, indent=2))
|
||||
# ret = self.schema
|
||||
# ret["patternProperties"][".*"]["properties"]["tree"]["items"]["properties"] = ret1
|
||||
# ret["patternProperties"][".*"]["properties"]["tree"]["items"] = ret2
|
||||
|
||||
# print(json.dumps(ret, indent=2))
|
||||
|
||||
def gen_docs(self):
|
||||
""" Generate documentation"""
|
||||
|
||||
|
||||
import json
|
||||
import kheops.plugin as KheopsPlugins
|
||||
from kheops.managers import BackendsManager, RulesManager
|
||||
print("WIP")
|
||||
return None
|
||||
|
||||
# src = {
|
||||
# "app": {
|
||||
@ -211,7 +196,6 @@ class App:
|
||||
#
|
||||
# r1 = BackendsManager.get_schema(KheopsPlugins, mode='parts')
|
||||
|
||||
|
||||
# print (json.dumps(r1, indent=2))
|
||||
|
||||
# ret = {
|
||||
@ -226,7 +210,3 @@ class App:
|
||||
|
||||
# for plugin_name, schema in plugins.items():
|
||||
# part_item_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user