Skip to content

Commit 76d2e35

Browse files
committed
Define package name parser
1 parent e62df4a commit 76d2e35

1 file changed

Lines changed: 53 additions & 13 deletions

File tree

validate.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,71 @@
1+
#!/usr/bin/env python
2+
"""
3+
Get a package path and check its content.
4+
5+
The package content checking is processed by a series/pipeline of tasks
6+
on specific request or automatically (if None asked) after parsing/interpreting
7+
the package name, or greedly inpecting any of the expected directories.
8+
"""
19
import os
210
import sys
311

4-
_here = os.path.abspath(__file__)
5-
sys.path.insert(0, _here)
12+
# _here = os.path.abspath(__file__)
13+
# sys.path.insert(0, _here)
14+
#
15+
# from validator import Validator
16+
#
17+
# config = {
18+
# 'geo_path': 'tmp/PM-MAR-MS-Arsinoes_01/vector/PM-MAR-MS-Arsinoes_01.gpkg',
19+
# 'geopackage_tables': ['units', 'contacts']
20+
# }
21+
22+
23+
from itertools import zip_longest
624

7-
from validator import Validator
25+
def parse_package_name(pkgname):
26+
tokens = pkgname.split('-')
827

28+
# Define the structure and parsing functions
29+
#
30+
fields = ',body,dtype,label,sublabel'.split(',')
31+
pm_id = {f:i for i,f in enumerate(fields)}
32+
targets = {'MER':'Mercury','MAR':'Mars','MOO':'Moon'}
33+
types = dict(S = 'Stratigraphic',
34+
C = 'Compositional',
35+
M = 'Morphologic',
36+
D = 'Digital outcrop, geologic model/mesh',
37+
G = 'Geo-structural',
38+
I = 'Integrated')
39+
lookup = dict(
40+
body = lambda t:targets[t],
41+
dtype = lambda t:','.join(types[_] for _ in t)
42+
)
943

10-
config = {
11-
'geo_path': 'tmp/PM-MAR-MS-Arsinoes_01/vector/PM-MAR-MS-Arsinoes_01.gpkg',
12-
'geopackage_tables': ['units', 'contacts']
13-
}
44+
pkg_specs = {field: lookup.get(field, lambda t:t)(token)
45+
for field,token in zip_longest(fields,tokens)}
46+
return pkg_specs
1447

1548

16-
def run(config, log_path):
17-
validator = Validator(config, log_path)
18-
res = validator.run()
19-
return res
49+
def run(pkg_path, log_path):
50+
#parse package name
51+
pkg_name = os.path.basename(os.path.abspath(pkg_path))
52+
pkg_specs = parse_package_name(pkg_name)
53+
print(pkg_specs)
54+
# body,dtype,label,sublabel = pkg_specs
2055

2156

2257
if __name__ == '__main__':
2358
from argparse import ArgumentParser
2459

2560
parser = ArgumentParser()
2661
parser.add_argument('--log', default=None, type=str)
27-
parser.add_argument('--cfg', default=None, type=str)
62+
# parser.add_argument('--cfg', default=None, type=str)
63+
parser.add_argument('path', type=str,
64+
help="Path of PlanMap package")
2865

2966
args = parser.parse_args()
67+
pkg_path = args.path
68+
3069
# res = run(args.cfg, args.log)
31-
res = run(config, 'log.log')
70+
71+
res = run(pkg_path, 'validator.log')

0 commit comments

Comments
 (0)