00001 """
00002
00003 This is the Runner Class. It should inherit from the PresidenceStack to allow for operators.
00004 Unless this is not in the given task.
00005
00006 """
00007
00008 __copyright__ = """
00009 Copyright 2008 Sean Ross-Ross
00010 """
00011 __license__ = """
00012 This file is part of SLIMpy .
00013
00014 SLIMpy is free software: you can redistribute it and/or modify
00015 it under the terms of the GNU Lesser General Public License as published by
00016 the Free Software Foundation, either version 3 of the License, or
00017 (at your option) any later version.
00018
00019 SLIMpy is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022 GNU Lesser General Public License for more details.
00023
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00026 """
00027
00028 from pdb import set_trace
00029
00030 from slimpy_base.Core.Runners.PresidenceStack import presStack
00031
00032 class defaultRunner( presStack ):
00033 """
00034 Runs commands from the graph. uses two stacks to keep
00035 track of dependencies and perhaps run several commands
00036 at the same time.
00037 """
00038 type = "default"
00039
00040 def __init__( self ):
00041 self.created_nodes = set()
00042 presStack.__init__( self )
00043
00044 def set_graph(self,graph):
00045 presStack.set_graph( self , graph)
00046
00047 def run( self ):
00048 """
00049 run the current graph with targets
00050 """
00051
00052
00053
00054 p1 = self.pull()
00055 numberRan = 0
00056
00057 table = self.env['table']
00058 log = self.env['record']
00059 while p1:
00060 if isinstance( p1, tuple ):
00061 items = [ table[item] for item in p1]
00062
00063
00064
00065 runnable = self.add( items )
00066
00067
00068
00069
00070 numberRan += 1
00071 log.stat_update()
00072 if self.env['slimvars']['runtype'] == 'dryrun':
00073 print >> log( 1, "cmd" ), runnable.nice_str()
00074 pass
00075
00076 else:
00077 runnable.node_name = 'localhost'
00078 runnable.run( )
00079
00080 else:
00081 self.created_nodes.add( p1 )
00082 self.pop( p1 )
00083 p1 = self.pull()
00084 return numberRan
00085