[cig-commits] r13413 - in seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness: bin chino

leif at geodynamics.org leif at geodynamics.org
Wed Nov 26 13:47:49 PST 2008


Author: leif
Date: 2008-11-26 13:47:49 -0800 (Wed, 26 Nov 2008)
New Revision: 13413

Added:
   seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/config.py
Modified:
   seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/bin/chino
   seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/harness.py
Log:
Implemented harness config file.


Modified: seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/bin/chino
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/bin/chino	2008-11-26 05:45:54 UTC (rev 13412)
+++ seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/bin/chino	2008-11-26 21:47:49 UTC (rev 13413)
@@ -1,6 +1,18 @@
 #!/usr/bin/env python
 
 from chino.harness import Harness
+from chino.config import Config
 
-h = Harness("g95", "s20rts/")
-h.run()
+def main():
+    try:
+        config = Config.fromFile()
+    except IOError:
+        Config.configure()
+        print "chino: generated config file '%s'" % Config.filename
+        print "chino: edit '%s', then run 'chino' again" % Config.filename
+        return
+    
+    harness = Harness(config)
+    harness.run()
+
+main()

Added: seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/config.py
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/config.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/config.py	2008-11-26 21:47:49 UTC (rev 13413)
@@ -0,0 +1,43 @@
+
+from ConfigParser import ConfigParser, NoOptionError
+
+
+class Config(object):
+
+    filename = "chino.cfg"
+    
+    #@classmethod
+    def fromFile(cls):
+        parser = ConfigParser()
+        parser.readfp(open(cls.filename))
+        
+        modelDir = parser.get("general", "model-dir")
+        fc = parser.get("make", "FC")
+        try:
+            fcflags_f90 = parser.get("make", "FCFLAGS_f90")
+        except NoOptionError:
+            fcflags_f90 = ""
+
+        return Config(modelDir = modelDir, fc = fc, fcflags_f90 = fcflags_f90)
+    fromFile = classmethod(fromFile)
+
+    #@classmethod
+    def configure(cls):
+        s = open(cls.filename, "w")
+        print >>s
+        print >>s, "[general]"
+        print >>s, "model-dir = mymodel  ; path to model directory"
+        print >>s
+        print >>s, "[make]"
+        print >>s, "FC = f90       ; Fortran-90 compiler command"
+        print >>s
+        print >>s, "# flag to recognize .f90 files as source (if needed); e.g.:"
+        print >>s, "#FCFLAGS_f90 = -qsuffix=f=f90"
+        print >>s, "#FCFLAGS_f90 = -Tf"
+        print >>s
+        s.close()
+        return cls.fromFile()
+    configure = classmethod(configure)
+
+    def __init__(self, **kwds):
+        self.__dict__.update(kwds)

Modified: seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/harness.py
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/harness.py	2008-11-26 05:45:54 UTC (rev 13412)
+++ seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/MODELS/harness/chino/harness.py	2008-11-26 21:47:49 UTC (rev 13413)
@@ -17,10 +17,9 @@
 
 class Harness(object):
 
-    def __init__(self, fc, modelDir):
+    def __init__(self, config):
         from os.path import abspath
-        self.fc = fc
-        self.modelDir = abspath(modelDir)
+        self.config = config
 
     def tarUp(self):
         import tarfile
@@ -100,8 +99,8 @@
         modelSourceFiles = self.modelSourceFiles
         s = open("Makefile", "w")
         print >>s
-        print >>s, "FC = %s" % self.fc
-        print >>s, "FCFLAGS_f90 ="
+        print >>s, "FC = %s" % self.config.fc
+        print >>s, "FCFLAGS_f90 = %s" % self.config.fcflags_f90
         print >>s
         print >>s, "model_OBJECTS = \\"
         for sourceFile in modelSourceFiles:
@@ -161,12 +160,12 @@
         output, exitStatus = self.ospawn("../modeltest")
         if exitStatus != 0:
             for line in output:
-                print line
+                print line,
             sys.exit("chino: model test failed")
         
         for line in output:
             if line.find("Luchooz0") != -1:
-                print line
+                print line,
                 return
         
         sys.exit("chino: model test failed")
@@ -174,26 +173,37 @@
     def run(self):
         from tempfile import mkdtemp
         from os import chdir, getcwd, mkdir
-        from os.path import abspath, join
-        from shutil import rmtree
+        from os.path import abspath, basename, join, isdir
+        from shutil import move, rmtree
+        import sys
 
+        self.modelDir = abspath(self.config.modelDir)
+        if not isdir(self.modelDir):
+            sys.exit("chino: '%s' does not exist or is not a directory" % self.config.modelDir)
         oldWd = getcwd()
         
         tempDir = mkdtemp()
-        self.model = abspath(join(tempDir, "model.tgz"))
+        try:
+            modelFilename = "%s.tgz" % basename(self.modelDir)
+            self.model = abspath(join(tempDir, modelFilename))
 
-        self.tarUp()
+            self.tarUp()
 
-        chdir(tempDir)
-        self.extractModel()
-        self.copyHarnessSourceFiles()
-        self.generateMakefile()
-        self.build()
+            chdir(tempDir)
+            self.extractModel()
+            self.copyHarnessSourceFiles()
+            self.generateMakefile()
+            self.build()
 
-        chdir("model")
-        self.execute()
+            chdir("model")
+            self.execute()
 
-        chdir(oldWd)
-        rmtree(tempDir)
+            chdir(oldWd)
 
+            move(self.model, modelFilename)
+            print "chino: model file for upload is '%s'" % modelFilename
+            
+        finally:
+            rmtree(tempDir)
+
         return



More information about the CIG-COMMITS mailing list