[Bio] / KahApp / KahFwk.py Repository:
ViewVC logotype

Diff of /KahApp/KahFwk.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Fri Mar 11 21:33:13 2005 UTC revision 1.2, Tue Jan 17 17:12:47 2006 UTC
# Line 1  Line 1 
 #!/usr/bin/env python  
1  import sys  import sys
2    
3    from KahOM.Model                       import Model
4  from KahApp.KahConfigMgr               import KahConfigMgr  from KahApp.KahConfigMgr               import KahConfigMgr
5  from CatalogServices.Catalog           import Catalog  from CatalogServices.Catalog           import Catalog
6    
 from KahDataServices.KahDbDataFactory  import KahDbDataFactory  
 from KahChemDb.KahChemDbDataFactory    import KahChemDbDataFactory  
 from KahDataServices.SeedDataFactory   import SeedDataFactory  
7    
8  #------------------------------------------------------------------------  #------------------------------------------------------------------------
9  def die(msg):  def die(msg):
# Line 16  Line 13 
13      return      return
14    
15    
16    #------------------------------------------------------------------------
17  class KahFwk:  class KahFwk:
18      #------------------------------------------------------------------------      #------------------------------------------------------------------------
19      def __init__(self):  
20        #------------------------------------------------------------------------
21        def __init__(self, configFileName, moduleList, model=None ):
22      #------------------------------------------------------------------------      #------------------------------------------------------------------------
23            """
24            @type configFileName: string
25            @type moduleList: list of KahModule derivative instances
26            @type model: KahOM.Model instance
27            """
28    
29          self.nameToInstance  = {}   # map instance name to instance          self.nameToInstance  = {}   # map instance name to instance
30          self.exeChain=[]            #list of modules in order to call them          self.exeChain=[]            #list of modules in order to call them
31    
32          self.configMgr = KahConfigMgr()          self.__model = model
33            if (None == model): self.__model = Model( "From KahFwk" )
34    
35          self.setupConfig()          self.configMgr = KahConfigMgr()
36    
37          self.getModules()          self.setupConfig(configFileName)
38    
39          self.configModules()          #
40            for m in moduleList:
41                self.addModuleToWeb(m.name(), "", m)
42    
         self.doDefaultDataFactories()  
         self.loadModel()  
43    
44          return          return
45    
46      #------------------------------------------------------------------------      #------------------------------------------------------------------------
47      def setupConfig( self ):      def getModel( self ):
48        #------------------------------------------------------------------------
49            return self.__model
50    
51        #------------------------------------------------------------------------
52        def setupConfig( self, configFileName ):
53      #------------------------------------------------------------------------      #------------------------------------------------------------------------
54    
55          # Config ourselves.  Unusual usage of configMgr.          # Config ourselves.  Unusual usage of configMgr.
# Line 46  Line 58 
58          cfg = self.configMgr.getSection( "KahFwk" )          cfg = self.configMgr.getSection( "KahFwk" )
59    
60          cfg.regString( "DefaultSeedInstance", "http://theSeed.uchicago.edu/FIG" )          cfg.regString( "DefaultSeedInstance", "http://theSeed.uchicago.edu/FIG" )
61          cfg.regString( "DefaultDataFactory", "kahchoo/bss@db02" )          cfg.regString( "DefaultDataFactory", "pgsql:5432:kahdb:trust:inme" )
62          cfg.regString( "DefaultDataFactoryDbType", "oracle" )          cfg.regString( "DefaultDataFactoryDbType", "postgres" )
63          cfg.regString( "DefaultChemDb", "pgsql:5432:kahdb:trust:inme" )          cfg.regString( "DefaultChemDb", "pgsql:5432:kahchemdb:trust:inme" )
64          cfg.regString( "DefaultChemDbType", "postgres" )          cfg.regString( "DefaultChemDbType", "postgres" )
65          cfg.regStringList( "ModuleList", [] )          cfg.regStringList( "ModuleList", [] )
66          cfg.regString( "InModelPath", "")          cfg.regString( "InModelPath", "")
67    
68            cfg.regInt( "verbose", 0, "Print out info.")
69    
70          # first loadConfigFile snarfs in the module list          # first loadConfigFile snarfs in the module list
71    
72          self.configMgr.loadConfigFile( "KahFwk.cfg" )          self.configMgr.loadConfigFile( configFileName )
73    
74      #------------------------------------------------------------------------      #------------------------------------------------------------------------
75      def configModules( self ):      def configModules( self ):
# Line 78  Line 92 
92      #------------------------------------------------------------------------      #------------------------------------------------------------------------
93      def doDefaultDataFactories(self):      def doDefaultDataFactories(self):
94      #------------------------------------------------------------------------      #------------------------------------------------------------------------
95            from KahDataServices.KahDbDataFactory  import KahDbDataFactory
96            from KahChemDb.KahChemDbDataFactory    import KahChemDbDataFactory
97            from KahDataServices.SeedDataFactory   import SeedDataFactory
98    
99          cfg    = self.configMgr.getSection( "KahFwk" )          cfg    = self.configMgr.getSection( "KahFwk" )
100          ddf    =  cfg.getString("DefaultDataFactory")          ddf    =  cfg.getString("DefaultDataFactory")
# Line 106  Line 123 
123          return          return
124    
125      #------------------------------------------------------------------------      #------------------------------------------------------------------------
126      def getModules(self):      def getModulesByCfg(self):
127      #------------------------------------------------------------------------      #------------------------------------------------------------------------
128    
129          cfg    = self.configMgr.getSection( "KahFwk" )          cfg    = self.configMgr.getSection( "KahFwk" )
# Line 144  Line 161 
161          return          return
162    
163    
164        def printfoo(self,  ce ):
165            print ce.path()
166    
167      #------------------------------------------------------------------------      #------------------------------------------------------------------------
168      def loadModel(self):      def loadModel(self):
169      #------------------------------------------------------------------------      #------------------------------------------------------------------------
# Line 156  Line 176 
176    
177          ce = Catalog.instance().open( inModelPath )          ce = Catalog.instance().open( inModelPath )
178          if (None == ce):          if (None == ce):
179                ctop=Catalog.instance().apply(self.printfoo)
180              die ("Provided path %s can not be read" % inModelPath )              die ("Provided path %s can not be read" % inModelPath )
181    
182    
183          self.model = ce.read()          self.__model = ce.read()
184    
185          return          return
186    
# Line 169  Line 190 
190          """          """
191          """          """
192    
193          top=self.model.getTop()          self.configModules()
194            fwkCfg =  self.configMgr.getSection( "KahFwk"  )
195            verbose = fwkCfg.getInt( "verbose" )
196    
197          for m in self.exeChain:          for m in self.exeChain:
198                if (verbose): print "Entering module ", m.name()
199    
200                # there are cases where a module will utterly replace the
201                # the top recoelem, so getTop ever time
202                top=self.__model.getTop()
203    
204              cfg =  self.configMgr.getSection( m.name() )              cfg =  self.configMgr.getSection( m.name() )
205              m.process( self.model, top, cfg)              m.process( self.__model, top, cfg)
206    
207          return          return
208    
209    
 if __name__ == "__main__":  
     print "kahfwk main"  
     f = KahFwk()  
     f.run()  
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3