-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
71 lines (59 loc) · 1.64 KB
/
run.py
File metadata and controls
71 lines (59 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import subprocess
import shutil
from glob import glob
import os
import datetime
data_path = os.getenv('DATA_PATH', '/data')
inputs = os.path.join(data_path, 'inputs')
outputs = os.path.join(data_path, 'outputs')
if os.path.exists(outputs):
shutil.rmtree(outputs)
os.mkdir(outputs)
run_path = os.path.join(outputs, 'shetran')
shutil.copytree(inputs, run_path)
try:
library = glob(os.path.join(run_path, '*.xml'))[0]
except IndexError:
raise Exception('Library file missing')
subprocess.call(['./shetran-prepare-snow', library])
subprocess.call(['./shetran-linux', '-f', glob(os.path.join(run_path, 'rundata_*'))[0]])
title = os.getenv('TITLE', 'SHETran output')
description = ' '
geojson = {}
metadata = f"""{{
"@context": ["metadata-v1"],
"@type": "dcat:Dataset",
"dct:language": "en",
"dct:title": "{title}",
"dct:description": "{description}",
"dcat:keyword": [
"shetran"
],
"dct:subject": "Environment",
"dct:license": {{
"@type": "LicenseDocument",
"@id": "https://creativecommons.org/licences/by/4.0/",
"rdfs:label": null
}},
"dct:creator": [{{"@type": "foaf:Organization"}}],
"dcat:contactPoint": {{
"@type": "vcard:Organization",
"vcard:fn": "DAFNI",
"vcard:hasEmail": "support@dafni.ac.uk"
}},
"dct:created": "{datetime.datetime.now().isoformat()}Z",
"dct:PeriodOfTime": {{
"type": "dct:PeriodOfTime",
"time:hasBeginning": null,
"time:hasEnd": null
}},
"dafni_version_note": "created",
"dct:spatial": {{
"@type": "dct:Location",
"rdfs:label": null
}},
"geojson": {geojson}
}}
"""
with open(os.path.join(outputs, 'metadata.json'), 'w') as f:
f.write(metadata)