00001 """
00002 Base class for all runner subclasses
00003 needed by the GraphManager
00004 """
00005
00006 __copyright__ = """
00007 Copyright 2008 Sean Ross-Ross
00008 """
00009 __license__ = """
00010 This file is part of SLIMpy .
00011
00012 SLIMpy is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as published by
00014 the Free Software Foundation, either version 3 of the License, or
00015 (at your option) any later version.
00016
00017 SLIMpy is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021
00022 You should have received a copy of the GNU Lesser General Public License
00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00024 """
00025
00026
00027
00028
00029
00030
00031
00032
00033 from slimpy_base.Environment.InstanceManager import InstanceManager
00034 from pdb import set_trace
00035
00036 class Runner( object ):
00037 """
00038 Abstract class
00039 """
00040
00041 env = InstanceManager()
00042 cleaner = None
00043 created_nodes = None
00044
00045 def set_graph(self,graph):
00046 raise NotImplementedError("Please use a subclass of RunnerBase")
00047
00048
00049
00050
00051
00052
00053
00054 def add(self, commands):
00055 """
00056 simple helper function
00057 TODO: replace with reduce( lambda x,y:y+y,commands)
00058 """
00059 commands = list( commands )
00060 prev = commands.pop(0)
00061 if not commands:
00062 if prev.adder is None:
00063 return prev
00064 else:
00065 return prev + None
00066
00067 while commands:
00068 next = commands.pop(0)
00069 prev = prev + next
00070
00071 return prev
00072
00073 def get_new_sources(self):
00074 if self.cleaner is None:
00075 cleaned_nodes = set()
00076 else:
00077 cleaned_nodes = self.cleaner.get_cleaned_nodes()
00078
00079 if self.created_nodes is None:
00080 remaining = set()
00081 else:
00082 remaining = self.created_nodes.difference( cleaned_nodes )
00083
00084 return remaining