forked from ImperialCollegeLondon/multifluids_icferst
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_options.py
executable file
·86 lines (70 loc) · 2.65 KB
/
update_options.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
import getopt
import glob
import os
import sys
import diamond.debug as debug
import diamond.schema as schema
def Help():
debug.dprint("Usage: update_options [OPTIONS] ... [FILES]\n" + \
"\n" + \
"Updates flml, and adml files. If FILES is not specified, all .flml, and .adml files in\n" + \
"tests/*/., tests/*/*/., longtests/*/., longtests/*/*/. and examples/*/. will be updated. Options:\n" + \
"\n" + \
"-h Display this help\n" + \
"-v Verbose mode", 0)
return
try:
opts, args = getopt.getopt(sys.argv[1:], "hv")
except getopt.getoptError:
Help()
sys.exit(-1)
if ("-h", "") in opts:
Help()
sys.exit(0)
if not ("-v", "") in opts:
debug.SetDebugLevel(0)
rootDir = os.path.join(os.path.dirname(__file__), os.path.pardir)
testDir = os.path.join(rootDir, "tests")
longtestDir = os.path.join(rootDir, "longtests")
examplesDir = os.path.join(rootDir, "examples")
extdict = {"flml" : "fluidity_options.rng",
"adml" : "test_advection_diffusion_options.rng"}
# cache parsed schema files
schemadict = {}
for k,v in extdict.items():
schemadict[k] = schema.Schema(os.path.join(rootDir, "schemas", v))
filenames = args
if len(filenames) == 0:
filenames = []
for k,v in extdict.items():
filenames += glob.glob(os.path.join(testDir, "*", "*."+k))
filenames += glob.glob(os.path.join(testDir, "*", "*", "*."+k))
filenames += glob.glob(os.path.join(longtestDir, "*", "*."+k))
filenames += glob.glob(os.path.join(longtestDir, "*", "*", "*."+k))
filenames += glob.glob(os.path.join(examplesDir, "*", "*."+k))
invalidFiles = []
updated = 0
for filename in filenames:
debug.dprint("Processing " + str(filename), 1)
ext = filename.split(".")[-1]
sch = schemadict[ext]
# Read the file and check that either the file is valid, or diamond.schema
# can make the file valid by adding in the missing elements
optionsTree = sch.read(filename)
lost_eles, added_eles, lost_attrs, added_attrs = sch.read_errors()
if len(lost_eles) + len(lost_attrs) > 0 or not optionsTree.valid:
debug.deprint(str(filename) + ": Invalid", 0)
debug.deprint(str(filename) + " errors: " + str((lost_eles, added_eles, lost_attrs, added_attrs)), 1)
invalidFiles.append(filename)
continue
# Write out the updated options file
optionsTree.write(filename)
debug.dprint(str(filename) + ": Updated", 0)
updated += 1
debug.dprint("Summary:", 0)
debug.dprint("Invalid options files:", 0)
for filename in invalidFiles:
debug.dprint(filename, 0)
debug.dprint("Invalid: " + str(len(invalidFiles)), 0)
debug.dprint("Updated: " + str(updated), 0)