From d21e62e5eb8fdd9e97df7207e8700bcb09c3902a Mon Sep 17 00:00:00 2001 From: mrjk Date: Wed, 26 Jan 2022 15:03:46 -0500 Subject: [PATCH] Change: Rename internal code for new branding --- kheops/app.py | 24 ++++++++++++------------ kheops/cli.py | 27 ++++++++++++++------------- kheops/managers.py | 12 ++++++------ kheops/plugin/backend/hier.py | 4 ++-- kheops/plugin/backend/init.py | 2 +- kheops/plugin/backend/loop.py | 4 ++-- kheops/plugin/common.py | 2 +- kheops/plugin/engine/jerakia.py | 12 +++++++++--- kheops/plugin/strategy/last.py | 2 +- kheops/plugin/strategy/schema.py | 4 ++-- kheops/query.py | 4 ++-- kheops/utils.py | 1 + 12 files changed, 53 insertions(+), 45 deletions(-) diff --git a/kheops/app.py b/kheops/app.py index 0f618b8..398595c 100644 --- a/kheops/app.py +++ b/kheops/app.py @@ -9,8 +9,8 @@ import yaml import anyconfig from pprint import pprint -from albero.query import Query -from albero.utils import schema_validate +from kheops.query import Query +from kheops.utils import schema_validate import anyconfig # from box import Box @@ -55,11 +55,11 @@ class App: "oneOf": [ { "type": "null", - "description": "Application current working directory is the `albero.yml` directory", + "description": "Application current working directory is the `kheops.yml` directory", }, { "type": "string", - "description": "Application working directory. If a relative path is used, it will be depending on `albero.yml` directory", + "description": "Application working directory. If a relative path is used, it will be depending on `kheops.yml` directory", }, ] }, @@ -109,7 +109,7 @@ class App: }, } - def __init__(self, config="albero.yml", namespace="default"): + def __init__(self, config="kheops.yml", namespace="default"): conf2 = anyconfig.load(config) self.run = {} @@ -177,11 +177,11 @@ class App: def dump_schema(self): import json - import albero.plugin as AlberoPlugins - from albero.managers import BackendsManager, RulesManager + import kheops.plugin as KheopsPlugins + from kheops.managers import BackendsManager, RulesManager - r1 = BackendsManager.get_schema(AlberoPlugins, mode='parts') - r2 = RulesManager.get_schema(AlberoPlugins) + r1 = BackendsManager.get_schema(KheopsPlugins, mode='parts') + r2 = RulesManager.get_schema(KheopsPlugins) #pprint (r1) print(json.dumps(r1, indent=2)) return @@ -196,8 +196,8 @@ class App: def gen_docs(self): import json - import albero.plugin as AlberoPlugins - from albero.managers import BackendsManager, RulesManager + import kheops.plugin as KheopsPlugins + from kheops.managers import BackendsManager, RulesManager print ("WIP") #src = { @@ -209,7 +209,7 @@ class App: # } # } # - #r1 = BackendsManager.get_schema(AlberoPlugins, mode='parts') + #r1 = BackendsManager.get_schema(KheopsPlugins, mode='parts') #print (json.dumps(r1, indent=2)) diff --git a/kheops/cli.py b/kheops/cli.py index 71908df..e69ff5e 100644 --- a/kheops/cli.py +++ b/kheops/cli.py @@ -16,7 +16,7 @@ import sys # Devel tmp sys.path.append("/home/jez/prj/bell/training/tiger-ansible/ext/ansible-tree") -import albero.app as Albero +import kheops.app as Kheops class CmdApp: @@ -26,7 +26,7 @@ class CmdApp: """Start new App""" self.get_args() - self.get_logger(verbose=self.args.verbose, logger_name="albero") + self.get_logger(verbose=self.args.verbose, logger_name="kheops") self.cli() def get_logger(self, logger_name=None, create_file=False, verbose=0): @@ -101,16 +101,20 @@ class CmdApp: # Manage main parser parser = argparse.ArgumentParser( - description="Albero, to lookup hierarchical data" + description="Kheops, hierarchical data lookup tool", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( - "-v", "--verbose", action="count", default=0, help="Increase verbosity" + "-v", "--verbose", action="count", + default=int(os.environ.get("KHEOPS_VERBOSE", "0")), + help="Increase verbosity" ) parser.add_argument( - "-c", "--config", help="Albero configuration file", - default="albero.yml", + "-c", "--config", + default=os.environ.get("KHEOPS_CONFIG", "kheops.yml"), + help="Kheops configuration file", ) - parser.add_argument("help", action="count", default=0, help="Show usage") + parser.add_argument("help", help="Show usage") subparsers = parser.add_subparsers( title="subcommands", description="valid subcommands", dest="command" ) @@ -165,7 +169,6 @@ class CmdApp: def cli_lookup(self): """Display how to use logging""" - config = "/home/jez/prj/bell/training/tiger-ansible/tree.yml" # self.log.debug(f"Command line vars: {vars(self.args)}") keys = self.args.key or [None] @@ -184,7 +187,7 @@ class CmdApp: self.log.info(f"CLI: {keys} with env: {new_params}") - app = Albero.App(config=self.args.config, namespace=self.args.namespace) + app = Kheops.App(config=self.args.config, namespace=self.args.namespace) for key in keys: r = app.lookup( key=key, @@ -197,17 +200,15 @@ class CmdApp: def cli_schema(self): """Display configuration schema""" - config = "/home/jez/prj/bell/training/tiger-ansible/tree.yml" - app = Albero.App(config=config) # , namespace=self.args.namespace) + app = Kheops.App(config=self.args.config) # , namespace=self.args.namespace) app.dump_schema() def cli_gen_doc(self): """Generate documentation""" - config = "/home/jez/prj/bell/training/tiger-ansible/tree.yml" - app = Albero.App(config=config) # , namespace=self.args.namespace) + app = Kheops.App(config=self.args.config) # , namespace=self.args.namespace) app.gen_docs() diff --git a/kheops/managers.py b/kheops/managers.py index 6880aa2..38fc00b 100644 --- a/kheops/managers.py +++ b/kheops/managers.py @@ -4,8 +4,8 @@ import logging from pprint import pprint -from albero.utils import schema_validate -import albero.plugin as AlberoPlugins +from kheops.utils import schema_validate +import kheops.plugin as KheopsPlugins log = logging.getLogger(__name__) @@ -151,7 +151,7 @@ class BackendsManager(Manager): self.config_app = app.conf2["config"]["app"] self.config_main = app.conf2["config"]["tree"] self.config_items = list(app.conf2["tree"]) - # THIS MAKE A BUG !!!! self.plugin_loader = LoadPlugin(AlberoPlugins) + # THIS MAKE A BUG !!!! self.plugin_loader = LoadPlugin(KheopsPlugins) self.plugins = [ "init", @@ -171,7 +171,7 @@ class BackendsManager(Manager): log.debug(f"Look for candidates for key '{key}' in backend: {self.backends}") # Prepare plugins - plugin_loader = LoadPlugin(AlberoPlugins) + plugin_loader = LoadPlugin(KheopsPlugins) _run = { "key": key, "scope": scope, @@ -201,7 +201,7 @@ class BackendsManager(Manager): def get_results(self, backends, trace=False): # Prepare plugins - plugin_loader = LoadPlugin(AlberoPlugins) + plugin_loader = LoadPlugin(KheopsPlugins) new_results = [] for backend in backends: @@ -349,7 +349,7 @@ class RulesManager(Manager): # Load plugin log.debug(f"Run strategy: {strategy}") - plugin_loader = LoadPlugin(AlberoPlugins) + plugin_loader = LoadPlugin(KheopsPlugins) strategy = plugin_loader.load( "strategy", strategy, diff --git a/kheops/plugin/backend/hier.py b/kheops/plugin/backend/hier.py index 078ddc8..c4103a4 100644 --- a/kheops/plugin/backend/hier.py +++ b/kheops/plugin/backend/hier.py @@ -1,6 +1,6 @@ -from albero.plugin.common import PluginBackendClass -from albero.utils import path_assemble_hier +from kheops.plugin.common import PluginBackendClass +from kheops.utils import path_assemble_hier from pprint import pprint import logging import copy diff --git a/kheops/plugin/backend/init.py b/kheops/plugin/backend/init.py index b6a290b..eab2ee0 100644 --- a/kheops/plugin/backend/init.py +++ b/kheops/plugin/backend/init.py @@ -1,4 +1,4 @@ -from albero.plugin.common import PluginBackendClass +from kheops.plugin.common import PluginBackendClass from pprint import pprint import logging diff --git a/kheops/plugin/backend/loop.py b/kheops/plugin/backend/loop.py index 29bea04..fa87975 100644 --- a/kheops/plugin/backend/loop.py +++ b/kheops/plugin/backend/loop.py @@ -1,7 +1,7 @@ import copy from pathlib import Path -from albero.utils import render_template -from albero.plugin.common import PluginBackendClass +from kheops.utils import render_template +from kheops.plugin.common import PluginBackendClass from pprint import pprint import logging diff --git a/kheops/plugin/common.py b/kheops/plugin/common.py index cb4747f..d860468 100644 --- a/kheops/plugin/common.py +++ b/kheops/plugin/common.py @@ -11,7 +11,7 @@ import logging log = logging.getLogger(__name__) -from albero.utils import schema_validate +from kheops.utils import schema_validate import copy # Candidate Classes diff --git a/kheops/plugin/engine/jerakia.py b/kheops/plugin/engine/jerakia.py index 328e4c2..08bf1c9 100644 --- a/kheops/plugin/engine/jerakia.py +++ b/kheops/plugin/engine/jerakia.py @@ -1,6 +1,6 @@ from pathlib import Path -from albero.utils import render_template, glob_files -from albero.plugin.common import PluginEngineClass, PluginFileGlob #, Candidate +from kheops.utils import render_template, glob_files +from kheops.plugin.common import PluginEngineClass, PluginFileGlob #, Candidate from pprint import pprint import logging @@ -147,11 +147,17 @@ class Plugin(PluginEngineClass, PluginFileGlob): except Exception: pass + # Assemble relative path + try: + rel_path = Path(path).resolve().relative_to(Path.cwd()) + except ValueError: + rel_path = Path(path).resolve() + # Build result object result = {} result["run"] = { "path": path, - "rel_path": str(Path(path).relative_to(Path.cwd())), + "rel_path": str(rel_path), } result["parent"] = self.config result["data"] = data diff --git a/kheops/plugin/strategy/last.py b/kheops/plugin/strategy/last.py index 324dde5..49c6e74 100644 --- a/kheops/plugin/strategy/last.py +++ b/kheops/plugin/strategy/last.py @@ -1,5 +1,5 @@ import logging -from albero.plugin.common import PluginStrategyClass +from kheops.plugin.common import PluginStrategyClass log = logging.getLogger(__name__) diff --git a/kheops/plugin/strategy/schema.py b/kheops/plugin/strategy/schema.py index d5d7d68..4c96175 100644 --- a/kheops/plugin/strategy/schema.py +++ b/kheops/plugin/strategy/schema.py @@ -1,6 +1,6 @@ import logging -from albero.plugin.common import PluginStrategyClass -from albero.utils import schema_validate, str_ellipsis +from kheops.plugin.common import PluginStrategyClass +from kheops.utils import schema_validate, str_ellipsis log = logging.getLogger(__name__) diff --git a/kheops/query.py b/kheops/query.py index 6bb05db..bd9e27c 100644 --- a/kheops/query.py +++ b/kheops/query.py @@ -9,8 +9,8 @@ import yaml import anyconfig from pprint import pprint -from albero.managers import BackendsManager, RulesManager -from albero.utils import schema_validate +from kheops.managers import BackendsManager, RulesManager +from kheops.utils import schema_validate import anyconfig # from box import Box diff --git a/kheops/utils.py b/kheops/utils.py index d30e3be..0417e6a 100644 --- a/kheops/utils.py +++ b/kheops/utils.py @@ -55,6 +55,7 @@ def render_template(path, params): t = Template(path) return t.render(**params) + # Schema Methods # =====================