00001
00002 """
00003
00004
00005 Driver function tracks dependencies and
00006 parses slimlib objects
00007
00008
00009 """
00010 __copyright__ = """
00011 Copyright 2008 Sean Ross-Ross
00012 """
00013 __license__ = """
00014 This file is part of SLIMpy .
00015
00016 SLIMpy is free software: you can redistribute it and/or modify
00017 it under the terms of the GNU Lesser General Public License as published by
00018 the Free Software Foundation, either version 3 of the License, or
00019 (at your option) any later version.
00020
00021 SLIMpy is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024 GNU Lesser General Public License for more details.
00025
00026 You should have received a copy of the GNU Lesser General Public License
00027 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00028 """
00029
00030
00031 from slimpy_base.Core.Interface.node import Node
00032
00033
00034 from slimpy_base.Environment.InstanceManager import InstanceManager
00035
00036 from os import system
00037
00038
00039
00040 class OutOfCoreDriver( object ):
00041 """
00042 takes a command string of an executable file as
00043 an argument and then can be used as a callable
00044 function with the 'Command' class
00045 """
00046
00047
00048 def __init__( self, cmndstr ):
00049 self.__comndstr = cmndstr
00050
00051 return
00052
00053 def __str__( self ):
00054 return self.__comndstr
00055
00056 def __repr__( self ):
00057 return self.__comndstr
00058
00059 def getCmnd( self ):
00060 return self.__comndstr
00061
00062 def __call__( self, *p, **k ):
00063 """
00064 call performs a system call and execute the file
00065 given by self.getCmnd() passed all of args and kargs as
00066 string parameters on the command line
00067 """
00068 print self.format( p, k )
00069 return system( self.format( p, k ) )
00070
00071 def format( self, nodename, params, kparams ):
00072 """
00073 creates a dictionary with the key "cmnd"
00074 which is a string of all the
00075 """
00076 env = InstanceManager()
00077
00078 table = env['table']
00079 l = lambda a, b : str( a )+'="'+str( b )+'"'
00080
00081 cs = [ self.getCmnd() ]
00082 push = cs.append
00083
00084 for par in params:
00085 if isinstance( par, Node ):
00086 src = table[par.getID()]
00087 par = src.get_data( nodename )
00088 push( par )
00089
00090 for key, val in kparams.items():
00091 if isinstance( val, Node ):
00092 val = val.get_data( nodename )
00093 push( l( key, val ) )
00094
00095
00096
00097
00098 return " ".join( map(str,cs) )
00099
00100