[cig-commits] r6369 - in short/3D/PyLith/branches/pylith-0.8: . pylith3d/pylith3d

leif at geodynamics.org leif at geodynamics.org
Fri Mar 23 10:42:22 PDT 2007


Author: leif
Date: 2007-03-23 10:42:22 -0700 (Fri, 23 Mar 2007)
New Revision: 6369

Modified:
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
   short/3D/PyLith/branches/pylith-0.8/setup.py
Log:
Utilize the new _validate() hook in pythia v0.8.1.3b2, which
PyLith-0.8 now requires.  Help and command-completion now works.



Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-03-23 17:31:52 UTC (rev 6368)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-03-23 17:42:22 UTC (rev 6369)
@@ -55,8 +55,8 @@
 
         scanner = self.inventory.scanner
 
-        mesh = pylith3d.processMesh(scanner.macroString(scanner.Inventory.bcInputFile),
-                                    scanner.macroString(scanner.Inventory.inputFileRoot),
+        mesh = pylith3d.processMesh(scanner.macroString(scanner.metainventory.bcInputFile),
+                                    scanner.macroString(scanner.metainventory.inputFileRoot),
                                     scanner.inventory.interpolateMesh,
                                     scanner.inventory.partitioner)
 

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py	2007-03-23 17:31:52 UTC (rev 6368)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py	2007-03-23 17:42:22 UTC (rev 6369)
@@ -49,33 +49,24 @@
         return
 
 
-    def _configure(self):
+    def _validate(self, context):
 
-        super(Pylith3d_scan, self)._configure()
+        super(Pylith3d_scan, self)._validate(context)
 
-        # Help is currently broken.  With this ugly hack, it at least
-        # works for the scanner.
-        if self._helpRequested:
-            return
-        # This method also breaks tab completion :-(
-
         #
         # Open input files.  Log I/O errors.
         #
         
-        self._summaryIOError = self.CanNotOpenInputOutputFilesError()
-
-        inputFile = self.inputFile
-        inputFileStream = self.inputFileStream
-        outputFile = self.outputFile
+        inputFile = lambda item, category: self.inputFile(item, category, context)
+        outputFile = lambda item, category:  self.outputFile(item, category, context)
         macroString = self.macroString
 
         #                              open?   fatal?  label
-        optional = self.IOFileCategory(True,   0,      "optional")
-        unused   = self.IOFileCategory(False,  0,      "unused")
-        required = self.IOFileCategory(True,   1,       None)
+        optional = self.IOFileCategory(True,   False,  "optional")
+        unused   = self.IOFileCategory(False,  False,  "unused")
+        required = self.IOFileCategory(True,   True,    None)
         
-        Inventory = Pylith3d_scan.Inventory
+        Inventory = self.metainventory
 
         analysisType = self.inventory.analysisType
 
@@ -104,31 +95,26 @@
         # The call to glob() is somewhat crude -- basically, determine
         # if any files might be in the way.
         self._ucdOutputRoot               = macroString(Inventory.ucdOutputRoot)
-        from glob import glob
-        ucdFiles = ([self._ucdOutputRoot + ".mesh.inp",
-                     self._ucdOutputRoot + ".gmesh.inp",
-                     self._ucdOutputRoot + ".mesh.time.prest.inp",
-                     self._ucdOutputRoot + ".gmesh.time.prest.inp"]
-                    + glob(self._ucdOutputRoot + ".mesh.time.[0-9][0-9][0-9][0-9][0-9].inp")
-                    + glob(self._ucdOutputRoot + ".gmesh.time.[0-9][0-9][0-9][0-9][0-9].inp"))
-        trait = Inventory.ucdOutputRoot
-        for ucdFile in ucdFiles:
-            try:
-                stream = os.fdopen(os.open(ucdFile, os.O_WRONLY|os.O_CREAT|os.O_EXCL), "w")
-            except (OSError, IOError), error:
-                descriptor = self.inventory.getTraitDescriptor(trait.name)
-                self._summaryIOError.openFailed(trait, descriptor,self._ucdOutputRoot + ".*mesh*.inp", error, required)
-                break
-            else:
-                stream.close()
-                os.remove(ucdFile)
 
-        if self._summaryIOError.fatalIOErrors():
-            self._summaryIOError.log(self._error)
-            import sys
-            sys.exit("%s: configuration error(s)" % self.name)
+        if False: # broken
+            from glob import glob
+            ucdFiles = ([self._ucdOutputRoot + ".mesh.inp",
+                         self._ucdOutputRoot + ".gmesh.inp",
+                         self._ucdOutputRoot + ".mesh.time.prest.inp",
+                         self._ucdOutputRoot + ".gmesh.time.prest.inp"]
+                        + glob(self._ucdOutputRoot + ".mesh.time.[0-9][0-9][0-9][0-9][0-9].inp")
+                        + glob(self._ucdOutputRoot + ".gmesh.time.[0-9][0-9][0-9][0-9][0-9].inp"))
+            item = Inventory.ucdOutputRoot
+            for ucdFile in ucdFiles:
+                try:
+                    stream = os.fdopen(os.open(ucdFile, os.O_WRONLY|os.O_CREAT|os.O_EXCL), "w")
+                except (OSError, IOError), error:
+                    context.error(error, items=[item])
+                    break
+                else:
+                    stream.close()
+                    os.remove(ucdFile)
 
-
         # get values for extra input (category 2)
 
         self.winklerScaleX = self.inventory.winklerScaleX
@@ -184,10 +170,10 @@
         from mpi import MPI_Comm_rank, MPI_COMM_WORLD
         
         self.rank = MPI_Comm_rank(MPI_COMM_WORLD)
-        outputFile = self.outputFile
-        inputFile = self.inputFile
+        inputFile = lambda item, category: self.inputFile(item, category, None)
+        outputFile = lambda item, category:  self.outputFile(item, category, None)
         macroString = self.macroString
-        Inventory = Pylith3d_scan.Inventory
+        Inventory = self.metainventory
         optional = self.IOFileCategory(True,   0,      "optional")
         required = self.IOFileCategory(True,   1,       None)
 
@@ -202,8 +188,8 @@
         self._coordinateInputFile         = inputFile(Inventory.coordinateInputFile,         required)
         self._connectivityInputFile       = inputFile(Inventory.connectivityInputFile,       required)
         self._bcInputFile                 = inputFile(Inventory.bcInputFile,                 required)
-        self._splitNodeInputFile          = inputFile(Inventory.splitNodeInputFile,          required)
-        self._tractionInputFile           = inputFile(Inventory.tractionInputFile,           required)
+        self._splitNodeInputFile          = inputFile(Inventory.splitNodeInputFile,          optional)
+        self._tractionInputFile           = inputFile(Inventory.tractionInputFile,           optional)
 
         # Create filenames for each process
         for attr in ['_asciiOutputFile',
@@ -578,81 +564,13 @@
         return
 
 
-    class CanNotOpenInputOutputFilesError(Exception):
-        
-        def __init__(self):
-            self._ioErrors = {}
-            self._ioErrorProtos = {}
-            self._fatalIOErrors = 0
-        
-        def openFailed(self, trait, descriptor, value, error, category):
-            """Open failed for an I/O file property."""
-            errno = error[0]
-            if not self._ioErrors.has_key(errno):
-                self._ioErrors[errno] = {}
-                proto = IOError(error[0], error[1]) # omit filename
-                self._ioErrorProtos[errno] = proto
-            from copy import copy
-            descriptor = copy(descriptor)
-            descriptor.origValue = descriptor.value
-            descriptor.value = value
-            self._ioErrors[errno][trait.name] = (error, descriptor, category)
-            self._fatalIOErrors = self._fatalIOErrors + category.fatalPoints
-            return
-
-        def fatalIOErrors(self): return self._fatalIOErrors
-
-        def log(self, diag):
-            from StringIO import StringIO
-            diag.line("error(s) opening input/output file(s)")
-            diag.line("")
-            errnos = self._ioErrors.keys()
-            errnos.sort()
-            cw = [4, 4, 30, 15, 10, 10] # column widths
-            ch = ("", "", "property", "value", "from", "") # column headers
-            for errno in errnos:
-                propertyNames = self._ioErrors[errno].keys()
-                for name in propertyNames:
-                    error, descriptor, category = self._ioErrors[errno][name]
-                    valueLen = len(descriptor.value)
-                    if valueLen > cw[3]:
-                        cw[3] = valueLen
-            for errno in errnos:
-                stream = StringIO()
-                print >> stream, "".ljust(cw[0]), self._ioErrorProtos[errno],
-                diag.line(stream.getvalue())
-                stream = StringIO()
-                for column in xrange(0, len(ch)):
-                    print >> stream, ch[column].ljust(cw[column]),
-                diag.line(stream.getvalue())
-                stream = StringIO()
-                for column in xrange(0, len(ch)):
-                    print >> stream, ("-" * len(ch[column])).ljust(cw[column]),
-                diag.line(stream.getvalue())
-                propertyNames = self._ioErrors[errno].keys()
-                propertyNames.sort()
-                for name in propertyNames:
-                    error, descriptor, category = self._ioErrors[errno][name]
-                    stream = StringIO()
-                    print >> stream, \
-                          "".ljust(cw[0]), \
-                          "".ljust(cw[1]), \
-                          name.ljust(cw[2]), \
-                          descriptor.value.ljust(cw[3]), \
-                          str(descriptor.locator).ljust(cw[4]), \
-                          (category.label and ("(%s)" % category.label).ljust(cw[5]) or ""),
-                    diag.line(stream.getvalue())
-                diag.line("")
-            diag.log()
-            return
-
     class IOFileCategory(object):
-        def __init__(self, tryOpen, fatalPoints, label):
+        def __init__(self, tryOpen, isFatal, label):
             self.tryOpen = tryOpen
-            self.fatalPoints = fatalPoints
+            self.isFatal = isFatal
             self.label = label
     
-    def macroString(self, trait):
+    def macroString(self, item):
         from pyre.util import expandMacros
         class InventoryAdapter(object):
             def __init__(self, inventory, builtins):
@@ -663,34 +581,38 @@
                 if builtin is None:
                     return expandMacros(str(self.inventory.getTraitValue(key)), self)
                 return builtin
-        descriptor = self.inventory.getTraitDescriptor(trait.name)
         builtins = {
             'rank': str(self.rank),
             }
-        return expandMacros(descriptor.value, InventoryAdapter(self.inventory, builtins))
+        return expandMacros(item.value, InventoryAdapter(self.inventory, builtins))
 
-    def ioFileStream(self, trait, flags, mode, category):
-        value = self.macroString(trait)
+    def ioFileStream(self, item, flags, mode, category, context):
+        value = self.macroString(item)
         stream = None
         if category.tryOpen:
             try:
                 stream = os.fdopen(os.open(value, flags), mode)
             except (OSError, IOError), error:
-                descriptor = self.inventory.getTraitDescriptor(trait.name)
-                self._summaryIOError.openFailed(trait, descriptor, value, error, category)
+                if context is None:
+                    if category.isFatal:
+                        raise
+                elif category.isFatal:
+                    context.error(error, items=[item])
+                else:
+                    pass # warning?
         return value, stream
 
-    def inputFile(self, trait, category):
-        value, stream = self.ioFileStream(trait,os. O_RDONLY, "r", category)
+    def inputFile(self, item, category, context):
+        value, stream = self.ioFileStream(item, os.O_RDONLY, "r", category, context)
         if stream is not None:
             stream.close()
         return value
     
-    def inputFileStream(self, trait, category):
-        return self.ioFileStream(trait, os.O_RDONLY, "r", category)[1]
+    def inputFileStream(self, item, category, context):
+        return self.ioFileStream(item, os.O_RDONLY, "r", category, context)[1]
     
-    def outputFile(self, trait, category):
-        value, stream = self.ioFileStream(trait, os.O_WRONLY|os.O_CREAT|os.O_EXCL, "w", category)
+    def outputFile(self, item, category, context):
+        value, stream = self.ioFileStream(item, os.O_WRONLY|os.O_CREAT|os.O_EXCL, "w", category, context)
         if stream is not None:
             stream.close()
             os.remove(value)

Modified: short/3D/PyLith/branches/pylith-0.8/setup.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/setup.py	2007-03-23 17:31:52 UTC (rev 6368)
+++ short/3D/PyLith/branches/pylith-0.8/setup.py	2007-03-23 17:42:22 UTC (rev 6369)
@@ -14,7 +14,7 @@
     packages = find_packages("pylith3d"),
     
     install_requires = [
-    'pythia[mpi] >= 0.8.1.3b1, < 0.8.2a',
+    'pythia[mpi] >= 0.8.1.3b2, < 0.8.2a',
     ],
 
     author = 'Charles A. Williams, Brad Aagaard, and Matt Knepley',



More information about the cig-commits mailing list