[cig-commits] r15185 - in short/3D/PyLith/trunk: playpen playpen/pylithinfo pylith/apps
brad at geodynamics.org
brad at geodynamics.org
Wed Jun 10 15:28:35 PDT 2009
Author: brad
Date: 2009-06-10 15:28:35 -0700 (Wed, 10 Jun 2009)
New Revision: 15185
Added:
short/3D/PyLith/trunk/playpen/pylithinfo/
short/3D/PyLith/trunk/playpen/pylithinfo/pylithinfo.py
Modified:
short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
Log:
Added temporary pylithinfo application in playpen/pylithinfo that recursively dumps all parameters.
Added: short/3D/PyLith/trunk/playpen/pylithinfo/pylithinfo.py
===================================================================
--- short/3D/PyLith/trunk/playpen/pylithinfo/pylithinfo.py (rev 0)
+++ short/3D/PyLith/trunk/playpen/pylithinfo/pylithinfo.py 2009-06-10 22:28:35 UTC (rev 15185)
@@ -0,0 +1,202 @@
+#!/usr/bin/env nemesis
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+__requires__ = "PyLith"
+
+
+# ======================================================================
+from pyre.applications.Script import Script
+class ParametersApp(Script):
+ """
+ Application for printing current PyLith parameters to a text file.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Script.Inventory):
+ """
+ Python object for managing ParametersApp facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing ParametersApp facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Filename for output.
+ ## @li \b verbose Set to true to print location where each
+ ## parameter is set.
+ ##
+ ## \b Facilities
+ ## @li none
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="parameters.txt")
+ filename.meta['tip'] = "Filename for output."
+
+ verbose = pyre.inventory.bool("verbose", default=False)
+ verbose.meta['tip'] = "Set to true to print location where " \
+ "each parameter is set."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="pylithinfo"):
+ """
+ Constructor.
+ """
+ Script.__init__(self, name)
+ 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()
+ targetapp.run()
+
+ 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 _configure(self):
+ """
+ Set members using inventory.
+ """
+ Script._configure(self)
+ self.filename = self.inventory.filename
+ self.verbose = self.inventory.verbose
+ return
+
+
+ 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__":
+
+ app = ParametersApp()
+ app.run()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/playpen/pylithinfo/pylithinfo.py
___________________________________________________________________
Name: svn:executable
+ *
Modified: short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-06-10 21:59:02 UTC (rev 15184)
+++ short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-06-10 22:28:35 UTC (rev 15185)
@@ -148,4 +148,30 @@
return
+# ======================================================================
+# Local version of InfoApp that only configures itself. Workaround for
+# not adding --help-all (or similar property) in Pyre Application.
+#
+# Note: We want --help-all to display settings before launching a
+# parallel job.
+class InfoApp(PyLithApp):
+ def __init__(self, name="pylithapp"):
+ """
+ Constructor.
+ """
+ PyLithApp.__init__(self, name)
+ return
+ # An empty main only prevents InfoApp from doing real work.
+ def main(self, *args, **kwds):
+ return
+ def onComputeNodes(self, *args, **kwds):
+ """
+ Run the application in parallel on the compute nodes.
+ """
+ self.main(*args, **kwds)
+ return
+
+
+
+
# End of file
More information about the CIG-COMMITS
mailing list