[cig-commits] r15359 - in short/3D/PyLith/trunk: . applications applications/utilities playpen pylith/apps
brad at geodynamics.org
brad at geodynamics.org
Fri Jun 19 14:23:12 PDT 2009
Author: brad
Date: 2009-06-19 14:23:11 -0700 (Fri, 19 Jun 2009)
New Revision: 15359
Added:
short/3D/PyLith/trunk/applications/utilities/
short/3D/PyLith/trunk/applications/utilities/Makefile.am
short/3D/PyLith/trunk/applications/utilities/pylithinfo
Removed:
short/3D/PyLith/trunk/playpen/pylithinfo/
Modified:
short/3D/PyLith/trunk/TODO
short/3D/PyLith/trunk/applications/Makefile.am
short/3D/PyLith/trunk/configure.ac
short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
Log:
Finished implementing pylithinfo utility.
Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO 2009-06-19 19:23:45 UTC (rev 15358)
+++ short/3D/PyLith/trunk/TODO 2009-06-19 21:23:11 UTC (rev 15359)
@@ -55,6 +55,7 @@
axialtract
sheartract
dislocation2
+ fourcells_twofaults (1 proc, 2 procs)
2d/tri3
dislocation
dislocation2
Modified: short/3D/PyLith/trunk/applications/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/applications/Makefile.am 2009-06-19 19:23:45 UTC (rev 15358)
+++ short/3D/PyLith/trunk/applications/Makefile.am 2009-06-19 21:23:11 UTC (rev 15359)
@@ -10,6 +10,8 @@
# ----------------------------------------------------------------------
#
+SUBDIRS = utilities
+
INTERPRETER = $(PYTHON)
noinstINTERPRETER = $(PYTHON)
@@ -35,7 +37,5 @@
EXTRA_DIST = pylith.in
CLEANFILES = $(bin_SCRIPTS)
-# version
-# $Id$
# End of file
Added: short/3D/PyLith/trunk/applications/utilities/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/applications/utilities/Makefile.am (rev 0)
+++ short/3D/PyLith/trunk/applications/utilities/Makefile.am 2009-06-19 21:23:11 UTC (rev 15359)
@@ -0,0 +1,16 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+bin_SCRIPTS = pylithinfo
+
+
+# End of file
Added: short/3D/PyLith/trunk/applications/utilities/pylithinfo
===================================================================
--- short/3D/PyLith/trunk/applications/utilities/pylithinfo (rev 0)
+++ short/3D/PyLith/trunk/applications/utilities/pylithinfo 2009-06-19 21:23:11 UTC (rev 15359)
@@ -0,0 +1,187 @@
+#!/usr/bin/env nemesis
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+# 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]
+
+__requires__ = "PyLith"
+
+
+# ======================================================================
+class ParametersApp(object):
+ """
+ Application for printing current PyLith parameters to a text file.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="pylithinfo"):
+ """
+ Constructor.
+ """
+ self.verbose = False
+ self.filename = "pylith_parameters.txt"
+ self.pylith_args = ""
+ self._tab = " "
+ self._printPropertyFn = self._printPropertyBasic
+ self._printFacilityFn = self._printFacilityBasic
+ 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)
+
+ if self.verbose:
+ self._printPropertyFn = self._printPropertyVerbose
+ self._printFacilityFn = self._printFacilityVerbose
+ else:
+ self._printPropertyFn = self._printPropertyBasic
+ self._printFacilityFn = self._printFacilityBasic
+
+ depth = 0
+ fout = open(self.filename, "w")
+ fout.write("Application: %s %s\n" % (targetapp.name, targetapp))
+ self._printParams(fout, targetapp, depth+1)
+ fout.close()
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _printParams(self, fout, obj, depth):
+ """
+ Print objects parameters to fout.
+ """
+ propertyNames = obj.inventory.propertyNames()
+ facilityNames = obj.inventory.facilityNames()
+
+ propertiesOmit = ["help",
+ "help-components",
+ "help-persistence",
+ "help-properties",
+ "typos",
+ ]
+ facilitiesOmit = ["weaver",
+ ]
+
+ propertyNames.sort()
+ facilityNames.sort()
+
+ for name in propertyNames:
+ if name in facilityNames or name in propertiesOmit:
+ continue
+ trait = obj.inventory.getTrait(name)
+ descriptor = obj.inventory.getTraitDescriptor(name)
+ self._printPropertyFn(fout, name, trait, descriptor, depth)
+ for name in facilityNames:
+ if name in facilitiesOmit:
+ continue
+ trait = obj.inventory.getTrait(name)
+ descriptor = obj.inventory.getTraitDescriptor(name)
+ self._printFacilityFn(fout, name, trait, descriptor, depth)
+ return
+
+
+ def _printPropertyBasic(self, fout, name, trait, descriptor, depth):
+ """
+ Print property name, type, and value.
+ """
+ indent = self._tab*depth
+ fout.write("%s%s (%s) = %s\n" % \
+ (indent, name, trait.type, descriptor.value))
+ return
+
+
+ def _printFacilityBasic(self, fout, name, trait, descriptor, depth):
+ """
+ Print facility name, type, and value.
+ """
+ indent = self._tab*depth
+ fout.write("%s%s = %s (%s)\n" % \
+ (indent, name, descriptor.value.name, descriptor.value))
+ self._printParams(fout, descriptor.value, depth+1)
+ return
+
+
+ def _printPropertyVerbose(self, fout, name, trait, descriptor, depth):
+ """
+ Print property, name, type, value, description, and location set.
+ """
+ indent = self._tab*depth
+ fout.write("\n%s%s (%s) = %s\n" % \
+ (indent, name, trait.type, descriptor.value))
+
+ indent += self._tab
+ try:
+ description = trait.meta['tip']
+ except KeyError:
+ description = "No description available."
+ fout.write("%sDescription: %s\n" % (indent, description))
+ fout.write("%sSet from: %s\n" % (indent, descriptor.locator))
+ return
+
+
+ def _printFacilityVerbose(self, fout, name, trait, descriptor, depth):
+ """
+ Print facility name, type, value, description, and location set.
+ """
+ indent = self._tab*depth
+ fout.write("\n%s%s = %s (%s)\n" % \
+ (indent, name, descriptor.value.name, descriptor.value))
+
+ indent += self._tab
+ try:
+ description = trait.meta['tip']
+ except KeyError:
+ description = "No description available."
+ fout.write("%sDescription: %s\n" % (indent, description))
+ fout.write("%sSet from: %s\n" % (indent, descriptor.locator))
+ fout.write("%sConfigurable as: %s\n" % \
+ (indent, ", ".join(descriptor.value.aliases)))
+
+ self._printParams(fout, descriptor.value, depth+1)
+ return
+
+
+# ----------------------------------------------------------------------
+if __name__ == "__main__":
+
+ usage = "%prog [options] [PyLith args]"
+ from optparse import OptionParser
+ parser = OptionParser(usage=usage)
+ parser.add_option("-v", "--verbose", dest="verbose",
+ action="store_true", default=False,
+ help="Print verbose output.")
+ parser.add_option("-o", "--fileout", dest="filename",
+ type="string", metavar="FILE",
+ help="Write to FILE. [pylith_parameters.txt]",
+ default="pylith_parameters.txt")
+ (options, args) = parser.parse_args()
+
+ app = ParametersApp()
+ app.verbose = options.verbose
+ app.filename = options.filename
+ app.pylith_args = args
+ app.main()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/applications/utilities/pylithinfo
___________________________________________________________________
Name: svn:executable
+ *
Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac 2009-06-19 19:23:45 UTC (rev 15358)
+++ short/3D/PyLith/trunk/configure.ac 2009-06-19 21:23:11 UTC (rev 15359)
@@ -232,6 +232,7 @@
modulesrc/topology/Makefile
modulesrc/utils/Makefile
applications/Makefile
+ applications/utilities/Makefile
unittests/Makefile
unittests/libtests/Makefile
unittests/libtests/bc/Makefile
Modified: short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-06-19 19:23:45 UTC (rev 15358)
+++ short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-06-19 21:23:11 UTC (rev 15359)
@@ -155,21 +155,34 @@
# Note: We want --help-all to display settings before launching a
# parallel job.
class InfoApp(PyLithApp):
- def __init__(self, name="pylithapp"):
+ def __init__(self, args, name="pylithapp"):
"""
Constructor.
"""
PyLithApp.__init__(self, name)
+ self.pylithargs = args
return
- # An empty main only prevents InfoApp from doing real work.
- def main(self, *args, **kwds):
+
+ def onLoginNode(self, *args, **kwds):
+ """
+ Instead of scheduling job, do nothing.
+ """
return
- def onComputeNodes(self, *args, **kwds):
+
+ def getArgv(self, *args, **kwds):
"""
- Run the application in parallel on the compute nodes.
+ Prevent PyLith from getting all of the command line arguments. Use
+ only the ones relevant to PyLith which are specified in the arg to
+ the constructor.
"""
- self.main(*args, **kwds)
- return
+ argv = kwds.get('argv')
+ if argv is None:
+ argv = self.pylithargs
+ else:
+ self.arg0 = argv[0]
+ self._requires = kwds.get('requires')
+ argv = argv[1:]
+ return argv
More information about the CIG-COMMITS
mailing list