Skip to content

Commit

Permalink
hxlm (#11), urnresolver (#13): clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Mar 6, 2021
1 parent ba9f034 commit ad3a6a0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 257 deletions.
5 changes: 5 additions & 0 deletions hxlm/core/bin/urnresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ def execute_cli(self, args,
"""

urn_item = HUrn.cast_urn(urn=args.infile)
urn_item.prepare()
# valt = HUrnUtil.get_urn_vault_local_info('un', 'locode')
HUrnUtil.debug_local_data('un', 'locode')
HUrnUtil.get_urn_vault_local_info(urn_item)

# print('valt', valt)
print(args.infile, urn_item)
print('about', urn_item.about())
print('about base_paths', urn_item.about('base_paths'))
print('about object_names', urn_item.about('object_names'))

# print('args', args)
# print('args', args)
Expand Down
31 changes: 29 additions & 2 deletions hxlm/core/htype/urn.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,19 @@ class DataUrnHtype(GenericUrnHtype):
# - urn:data--i:
# - urn:data--p:

nid_attr: InitVar[str] = 'd' # Example: 'i' on 'urn:data--i:un:locode'
nid_attr_spliter: InitVar[str] = '--' # Example: '--' on 'urn:data--i:'
#: The default concept of 'urn:data' is about datasets (nid_attr = 'd')
nid_attr: InitVar[str] = 'd'
# nid_attr example:
# - 'i' on 'urn:data--i:un:locode' (information about how to get this)
# - 'p' on 'urn:data--i:un:locode' (acceptable-policy-usage)

# #: If more than one attribute is given
# nid_attr_all: InitVar[list] = ['d']

nid_attr_spliter: InitVar[str] = '--'
# nid_attr_spliter example
# - '--' on 'urn:data--i:'
# - '--' on 'urn:data--d--ckan:' (not implemented, may be deprecated)

#: Baseline parser global identifier (ISO 3166-1 alpha-2)
bpgp: InitVar[str] = ''
Expand Down Expand Up @@ -351,6 +362,10 @@ def about(self, key: str = None):
about['bpln'] = self.bpln
if self.bpln_isdn:
about['bpln_isdn'] = self.bpln_isdn

# if self.nid_attr_all != ['d']:
# about['nid_attr_all'] = self.nid_attr_all

about['nss'] = self.nss

# # print('_', _)
Expand Down Expand Up @@ -426,6 +441,18 @@ def prepare(self, strict: bool = True):
else:
self.nid = parts[1].lower()

# if parts[1].lower().find(self.nid_attr_spliter) != -1:
# print('')
# print('')
# parts2 = parts[1].lower().split(self.nid_attr_spliter)
# self.nid = parts2.pop()
# print('self.nidaaaaaaaaaaaaaaaaa', self.nid)
# self.nid_attr = parts2[0]
# self.nid_attr_all = parts2
# # parts[1].lower().split(self.nid_attr_spliter)
# else:
# self.nid = parts[1].lower()

self.bpgp, self.bpln, *_ = self.nss.split(":")
# print('_', _)
if self.bpln.find('__') != -1:
Expand Down
17 changes: 14 additions & 3 deletions hxlm/core/schema/urn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

import os

__all__ = ['get_urn_vault_local_info']
from typing import (
Type
)

from hxlm.core.htype.urn import (
GenericUrnHtype
)

__all__ = ['get_urn_vault_local_info', 'get_urn_vault_local_info']


# TODO: move these variables to somewere else
Expand Down Expand Up @@ -44,6 +52,9 @@
# _HXLM_BASE = str(Path.home() + "/.config/hxlm/"
# HXLM_CORE_URN_DATA_BASE_DEFAULT = str(Path.home() + "/.config/hxlm/urn/data/"

# ./hxlm/core/bin/urnresolver.py urn:data:xz:eticaai:pcode:br
# ./hxlm/core/bin/urnresolver.py urn:data:xz:hxl:std:core:hashtag

def is_urn_data_prepared(exact_path: str = None, required: bool = False):
if exact_path:
if not os.path.exists(exact_path) and required:
Expand Down Expand Up @@ -74,10 +85,10 @@ def debug_local_data(judistiction: str, organization: str):
print('TODO: get_urn_vault_local_info', judistiction, organization)


def get_urn_vault_local_info(judistiction: str, organization: str):
def get_urn_vault_local_info(urn: Type[GenericUrnHtype]):
print('HXLM_CONFIG_BASE', HXLM_CONFIG_BASE)
print('HXLM_DATA_POLICY_BASE', HXLM_DATA_POLICY_BASE)
print('HXLM_DATA_VAULT_BASE', HXLM_DATA_VAULT_BASE)
print('HXLM_DATA_VAULT_BASE_ALT', HXLM_DATA_VAULT_BASE_ALT)
print('HXLM_DATA_VAULT_BASE_ACTIVE', HXLM_DATA_VAULT_BASE_ACTIVE)
print('TODO: get_urn_vault_local_info', judistiction, organization)
print('TODO: urn', urn)
252 changes: 0 additions & 252 deletions tests/grammar/instaparse-abnf_test.cljc

This file was deleted.

11 changes: 11 additions & 0 deletions tests/test_core_urn.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ def test_core_htype_urn_cast_b():
print(urn_unicode8, urn_unicode8.about())
print(urn_unicode8.about('base_paths'), urn_locode1.about('object_names'))

# @see https://data.humdata.org/api/3/action
# /package_show?id=hxl-core-schemas
urn_hxl9 = cast_urn('urn:data:xz:hxl:std:core:hashtag').prepare()
print(urn_hxl9, urn_hxl9.about())
# Site: data.humdata.org
# Dataset id: hxl-core-schemas
# Dataset resource name: hxl-core-hashtag-schema.csv
urn_hxl10 = cast_urn('urn:data:xz:__data.humdata.org__:hxl-core-schemas:hxl-core-hashtag-schema.csv').prepare()
print(urn_hxl10, urn_hxl10.about())
urn_hxl11 = cast_urn('urn:data--d--ckan:xz:__data.humdata.org__:hxl-core-schemas:hxl-core-hashtag-schema.csv').prepare()
print(urn_hxl11, urn_hxl11.about())

assert urn_locode1.nid == 'data'
assert urn_locode2.nid == 'data'
Expand Down

0 comments on commit ad3a6a0

Please sign in to comment.