Skip to content

Commit c237777

Browse files
committed
Add first aproach to the validator
1 parent 3e0450c commit c237777

7 files changed

Lines changed: 121 additions & 0 deletions

File tree

tasks/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
3+
4+
class TaskBase(object):
5+
def __init__(self, **kwargs):
6+
print('####################################')
7+
print(self.__class__.__name__)
8+
print(kwargs)
9+
print('####################################')
10+
self.config = kwargs['config']
11+
self.logger = kwargs['logger']
12+
13+
def run(self):
14+
raise NotImplementedError
15+
16+
17+
class TaskVector(TaskBase):
18+
def __init__(self, **kwargs):
19+
super().__init__(**kwargs)
20+
21+
def run(self):
22+
geo_path = self.config['geo_path']
23+
res = os.path.exists(geo_path)
24+
self.logger.info('File exist? {}'.format('yes' if res else 'no'))
25+
return res
26+
27+
28+
class TaskVectorTables(TaskVector):
29+
def __init__(self, **kwargs):
30+
super().__init__(**kwargs)
31+
32+
def run(self):
33+
import fiona
34+
geo_path = self.config['geo_path']
35+
layers = fiona.listlayers(geo_path)
36+
layers_in_config = self.config['geopackage_tables']
37+
res = all([layer in layers_in_config for layer in layers])
38+
self.logger.info(f'Do we have the layers? {res!r}')
39+
return res
40+
41+
# class TaskVectorTableColumns(TaskBase):
42+
# def __init__(self, **kwargs):
43+
# super().__init__(**kwargs)
44+
#
45+
#
46+
# class TaskVectorTableColumnsUnits(TaskBase):
47+
# table = 'units'
48+
# def __init__(self, **kwargs):
49+
# super().__init__(**kwargs)
50+
#

tmp/PM-MAR-MS-Arsinoes_01.zip

3.94 MB
Binary file not shown.

validate.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import sys
3+
4+
_here = os.path.abspath(__file__)
5+
sys.path.insert(0, _here)
6+
7+
8+
config = {
9+
'geo_path': 'tmp/PM-MAR-MS-Arsinoes_01/vector/PM-MAR-MS-Arsinoes_01.gpkg',
10+
'geopackage_tables': ['units', 'contacts']
11+
}
12+
13+
from validator import Validator
14+
15+
def run(config, log_path):
16+
validator = Validator(config, log_path)
17+
res = validator.run()
18+
return res
19+
20+
21+
if __name__ == '__main__':
22+
from argparse import ArgumentParser
23+
24+
parser = ArgumentParser()
25+
parser.add_argument('--log', default=None, type=str)
26+
parser.add_argument('--cfg', default=None, type=str)
27+
28+
args = parser.parse_args()
29+
# res = run(args.cfg, args.log)
30+
res = run(config, 'log.log')

validator/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .validator import Validator

validator/document/validator.py

Whitespace-only changes.

validator/validator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
from tasks import *
4+
5+
class Validator(object):
6+
tasks = None
7+
8+
def __init__(self, config, log_path):
9+
"""
10+
* 'config' is a python dict
11+
* 'context' is something(?) bringing global info
12+
"""
13+
import logging
14+
logger = logging.getLogger('planmap')
15+
logger.setLevel('INFO')
16+
logger.addHandler(logging.FileHandler(log_path))
17+
self.log = logger
18+
19+
self.config = config
20+
21+
tasks = [TaskVector, TaskVectorTables]
22+
self.tasks = self.set_tasks(tasks)
23+
24+
def set_tasks(self, tasks):
25+
return [t(config=self.config, logger=self.log) for t in tasks]
26+
27+
def run(self):
28+
ok = True
29+
for task in self.tasks:
30+
res = task.run()
31+
if not res:
32+
self.log.error(f'Task {task} failed')
33+
ok = False
34+
break
35+
return ok
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name"= String,
3+
"rgb"= String,
4+
"geometry"= Polygon
5+
}

0 commit comments

Comments
 (0)