Skip to content

Commit

Permalink
hxlm(#11), hxl-processing-specs (#14): Added HDP.HDP_JSON_EXTENSIONS …
Browse files Browse the repository at this point in the history
…& HDP.HDP_YML_EXTENSIONS
  • Loading branch information
fititnt committed Mar 13, 2021
1 parent 10c7df8 commit cc5462f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 13 deletions.
9 changes: 7 additions & 2 deletions hxlm/core/bin/hdpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
75 changes: 64 additions & 11 deletions hxlm/core/model/hdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
SPDX-License-Identifier: Unlicense OR 0BSD
"""

import os

from typing import (
Union
)
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit cc5462f

Please sign in to comment.