diff --git a/hxlm/core/bin/hdpcli.py b/hxlm/core/bin/hdpcli.py index b2ed1e1..9a9b7de 100755 --- a/hxlm/core/bin/hdpcli.py +++ b/hxlm/core/bin/hdpcli.py @@ -161,7 +161,11 @@ def __init__(self): def _exec_export_to_hxl_json_processing_specs(self, hdp_entry_point: str) -> HDP: - hdp = HDP(hdp_entry_point=hdp_entry_point) + # TODO: while the default of HDP (and later also from the hdpcli) is + # not allow online initialization, at this moment, for testing, + # we're allowing here. (Emerson Rocha, 2021-03-13 01:48 UTC) + hdp = HDP(hdp_entry_point=hdp_entry_point, + online_unrestricted_init=True) return hdp @@ -530,7 +534,8 @@ def execute_cli(self, args, hdp_entry_point=args.export_to_hxl_json_processing_specs ) # print('export_to_hxl_json_processing_specs', hdp) - return str(hdp) + # return str(hdp) + return hdp.export_yml() # TODO: 'Is AI just a bunch of if and else statements?' if (args.hdp_init and (args.hdp_init_home or args.hdp_init_data)) or \ diff --git a/hxlm/core/model/hdp.py b/hxlm/core/model/hdp.py index cfefe5e..ab48972 100644 --- a/hxlm/core/model/hdp.py +++ b/hxlm/core/model/hdp.py @@ -8,6 +8,8 @@ SPDX-License-Identifier: Unlicense OR 0BSD """ +import os + from typing import ( Union ) @@ -54,6 +56,20 @@ class HDP: listed item already is compromised. """ + HDP_JSON_EXTENSIONS: list = [ + '.hdp.json', + '.hdpd.json', + '.hdpr.json', + # '.urn.json' # See urnresolver + ] + + HDP_YML_EXTENSIONS: list = [ + '.hdp.yml', + '.hdpd.yml', + '.hdpr.yml', + # '.urn.yml' # See urnresolver + ] + def __init__(self, hdp_entry_point: str = None, yml_string: str = None, json_string: str = None, @@ -73,24 +89,61 @@ def __init__(self, hdp_entry_point: str = None, self._safer_zone_list = safer_zone_list if hdp_entry_point: - self._prepare_from_entry_point(hdp_entry_point) + self._prepare(hdp_entry_point) if json_string: - self._prepare_from_json_string(json_string) + self._prepare_from_string(json_string=json_string) if yml_string: - self._prepare_from_entry_point(yml_string) + self._prepare_from_string(yml_string=yml_string) + + def _get_urnresolver_iri(self, urn: str) -> str: + return 'http://localhost/?not-implemented-yet#' + urn + + def _prepare(self, hdp_entry_point: str) -> bool: + + # First things first: try to resolve the URN. Maybe already is local + if hdp_entry_point.startswith('urn:'): + hdp_entry_point = self._get_urnresolver_iri(hdp_entry_point) + + if hdp_entry_point.startswith(['http://', 'http://']): + return self._prepare_from_remote_iri(hdp_entry_point) + + if os.path.isfile(hdp_entry_point): + return self._prepare_from_local_file(hdp_entry_point) - def _prepare_from_entry_point(self, hdp_entry_point): + if os.path.isdir(hdp_entry_point): + return self._prepare_from_local_directory(hdp_entry_point) + + raise RuntimeError('unknow entrypoint [' + hdp_entry_point + ']') + + def _prepare_from_local_directory(self, dir_path: str): pass - def _prepare_from_json_string(self, json_string): - self._hdp_raw = json_string - self._hdp = json.loads(json_string) + def _prepare_from_local_file(self, file_path: str): + pass + + def _prepare_from_remote_iri(self, iri: str): + return True + + def _prepare_from_string(self, + json_string: str = None, + yml_string: str = None): + if json_string: + self._hdp_raw = json_string + self._hdp = json.loads(json_string) + return True + + if yml_string: + self._hdp_raw = yml_string + self._hdp = yaml.safe_load(yml_string) + return True + + raise RuntimeError('json_string or yml_string are required') - def _prepare_from_yml_string(self, hdp_yml_string): - self._hdp_raw = hdp_yml_string - self._hdp = yaml.safe_load(hdp_yml_string) + # def _prepare_from_yml_string(self, hdp_yml_string): + # self._hdp_raw = hdp_yml_string + # self._hdp = yaml.safe_load(hdp_yml_string) - def export_schema_json(self) -> str: + def export_json(self) -> str: """Export the current HDP internal metadata in an YAML format Returns: