|
| 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 | +""" |
1 | 9 | import os |
2 | 10 | import sys |
3 | 11 |
|
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 |
6 | 24 |
|
7 | | -from validator import Validator |
| 25 | +def parse_package_name(pkgname): |
| 26 | + tokens = pkgname.split('-') |
8 | 27 |
|
| 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 | + ) |
9 | 43 |
|
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 |
14 | 47 |
|
15 | 48 |
|
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 |
20 | 55 |
|
21 | 56 |
|
22 | 57 | if __name__ == '__main__': |
23 | 58 | from argparse import ArgumentParser |
24 | 59 |
|
25 | 60 | parser = ArgumentParser() |
26 | 61 | 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") |
28 | 65 |
|
29 | 66 | args = parser.parse_args() |
| 67 | + pkg_path = args.path |
| 68 | + |
30 | 69 | # res = run(args.cfg, args.log) |
31 | | - res = run(config, 'log.log') |
| 70 | + |
| 71 | + res = run(pkg_path, 'validator.log') |
0 commit comments