-
Notifications
You must be signed in to change notification settings - Fork 96
/
pylithinfo.in
90 lines (76 loc) · 3.07 KB
/
pylithinfo.in
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
87
88
89
90
#!@INTERPRETER@
# -*- Python -*-
#
# ======================================================================
#
# Brad T. Aagaard, U.S. Geological Survey
# Charles A. Williams, GNS Science
# Matthew G. Knepley, University of Chicago
#
# This code was developed as part of the Computational Infrastructure
# for Geodynamics (http://geodynamics.org).
#
# Copyright (c) 2010-2017 University of California, Davis
#
# See COPYING for license information.
#
# ======================================================================
#
# This script dumps all PyLith parameters (defaults plus those
# specified by the user to a text file. The default name of the output
# file is 'pylith_parameters.txt'. Verbose output includes a
# description of the parameter along with where it's current value was
# set.
#
# Usage: pylithinfo.py [--verbose] [--fileout=FILE] [PyLith args]
# ======================================================================
class ParametersApp(object):
"""
Application for printing current PyLith parameters to a text file.
"""
# PUBLIC METHODS /////////////////////////////////////////////////////
def __init__(self, name="pylithinfo"):
"""
Constructor.
"""
self.format = "json"
self.verbose = False
self.filename = "pylith_parameters.json"
self.pylith_args = ""
return
def main(self, *args, **kwds):
"""
Main entry point for application.
"""
from pylith.apps.PyLithApp import InfoApp
targetapp = InfoApp(self.pylith_args)
targetapp.run(*args, **kwds)
dumper = None
if self.format == "json":
from pylith.utils.DumpParametersJson import DumpParametersJson
dumper = DumpParametersJson()
elif self.format == "ascii":
from pylith.utils.DumpParametersAscii import DumpParametersAscii
dumper = DumpParametersAscii()
dumper.inventory.verbose = self.verbose
dumper.inventory.filename = self.filename
dumper._configure()
dumper.write(targetapp)
return
# ----------------------------------------------------------------------
if __name__ == "__main__":
description = "Configure PyLith simulation and dump parameters to a file."
addInfo = "Also include any normal PyLith command line arguments, like .cfg files."
import argparse
parser = argparse.ArgumentParser(description=description, epilog=addInfo)
parser.add_argument("--verbose-false", action="store_false", dest="verbose", help="Don't include description, location, and aliases in output.")
parser.add_argument("--format", action="store", dest="format", default="json", help="Format of output file.", choices=("ascii", "json"))
parser.add_argument("--filename", action="store", dest="filename", default="pylith_parameters.json", help="Name of output file")
args, extraArgs = parser.parse_known_args()
app = ParametersApp()
app.format = args.format
app.verbose = args.verbose
app.filename = args.filename
app.pylith_args = extraArgs
app.main()
# End of file