-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_config_file.py
executable file
·73 lines (61 loc) · 4.15 KB
/
build_config_file.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
#!/usr/bin/env python
# derived from https://gist.github.com/douglasjacobsen/0ddcf9529f462dc6ca7c
import argparse
import ConfigParser
import os
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--file", dest="filename", help="Path to config file", metavar="FILE", required=True)
parser.add_argument("-t", "--type", dest="type", help="Type of config file to setup", metavar="TYPE", required=True)
parser.add_argument("-b", "--branch", dest="branch", help="Path to setup directory", metavar="PATH", required=True)
args = parser.parse_args()
if not args.filename:
parser.error("A config file is required")
if not args.type:
parser.error("A type is required")
if not args.branch:
parser.error("A branch is required")
configParser = ConfigParser.RawConfigParser()
try:
configParser.read(args.filename)
except:
print "Error while trying to read file %s\n"%(args.filename)
exit()
if args.type == "ocean":
configParser.set("namelists", "forward", "%s/default_inputs/namelist.ocean.forward"%(args.branch))
configParser.set("namelists", "init", "%s/default_inputs/namelist.ocean.init"%(args.branch))
configParser.set("streams", "forward", "%s/default_inputs/streams.ocean.forward"%(args.branch))
configParser.set("streams", "init", "%s/default_inputs/streams.ocean.init"%(args.branch))
configParser.set("executables", "model", "%s/ocean_model"%(args.branch))
configParser.set("executables", "mesh_converter", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasMeshConverter.x")
configParser.set("executables", "cell_culler", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasCellCuller.x")
configParser.set("executables", "mask_creator", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasMaskCreator.x")
configParser.set("executables", "metis", "/usr/local/bin/gpmetis")
configParser.set("paths", "mesh_database", "/Users/pwolfram/Documents/MPAS-MeshDatabase")
configParser.set("paths", "initial_condition_database", "/Users/pwolfram/Documents/MPAS-InitCondDatabase")
configParser.set("paths", "gemoetric_features", "/Users/pwolfram/Documents/MPAS-geometric_features")
elif args.type == "test":
configParser.set("namelists", "forward", "%s/default_inputs/namelist.test"%(args.branch))
configParser.set("streams", "forward", "%s/default_inputs/streams.test"%(args.branch))
configParser.set("executables", "model", "%s/test_model"%(args.branch))
configParser.set("executables", "mesh_converter", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasMeshConverter.x")
configParser.set("executables", "cell_culler", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasCellCuller.x")
configParser.set("executables", "metis", "/usr/local/bin/gpmetis")
configParser.set("paths", "mesh_database", "/Users/pwolfram/Documents/MPAS-MeshDatabase")
elif args.type == "landice":
configParser.set("namelists", "forward", "%s/default_inputs/namelist.landice"%(args.branch))
configParser.set("streams", "forward", "%s/default_inputs/streams.landice"%(args.branch))
configParser.set("executables", "grid_to_li_grid", "/usr/local/bin/create_landice_grid_from_generic_MPAS_grid.py")
configParser.set("executables", "model", "%s/landice_model"%(args.branch))
configParser.set("executables", "mesh_converter", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasMeshConverter.x")
configParser.set("executables", "cell_culler", "/Users/pwolfram/Documents/MPAS-Tools/grid_gen/mesh_conversion_tools/MpasCellCuller.x")
configParser.set("executables", "metis", "/usr/local/bin/gpmetis")
configParser.set("paths", "mesh_database", "/Users/pwolfram/Documents/MPAS-MeshDatabase")
configParser.set("paths", "initial_condition_database", "/Users/pwolfram/Documents/MPAS-InitCondDatabase")
config_file = open("/tmp/%s.config"%(args.type), "w+")
try:
configParser.write(config_file)
print "wrote file: /tmp/%s.config"%(args.type)
except:
print "Error trying to write file %s\n"%(args.filename)
exit()
config_file.close()