00001 """
00002 Helper Class to store values destined for the graph
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025
00026 from slimpy_base.Core.Interface.node import Node
00027
00028
00029 class CommandPack( object ):
00030 """
00031 Class to contain commands sources and targets for
00032 convenience
00033
00034 """
00035 def __init__( self, comm, in_cont=True, out_cont=True ):
00036
00037
00038
00039 self.in_cont = in_cont
00040 self.out_cont = out_cont
00041 self.commlist = comm
00042
00043 def getNodeList( self ):
00044 """
00045 returns the commands as a list of Node instances
00046 """
00047 return [ Node( node ) for node in self.commlist ]
00048
00049 def getTargets( self ):
00050 """
00051 return a list of all of the targets in the
00052 commands
00053 """
00054 targets = []
00055 for comm in self.commlist:
00056 targets.extend( comm.getTargets() )
00057 return targets
00058
00059 def getSources( self ):
00060 """
00061 return a list of all of the sources in the
00062 commands
00063 """
00064 sources = []
00065 for comm in self.commlist:
00066 sources.extend( comm.getSources() )
00067 return sources
00068
00069
00070 def getSourceNode( self ):
00071 """
00072 returns main source as a Node instance
00073 """
00074 return Node( self.in_cont )
00075
00076 def getTargetNode( self ):
00077 """
00078 returns main target as a Node instance
00079 """
00080 return Node( self.out_cont )
00081
00082 def getSource( self ):
00083 """
00084 returns stdin source
00085 """
00086 return self.in_cont
00087
00088 def setSource( self, src ):
00089 'sets stdin source'
00090 if self.source is True:
00091 self.in_cont = src
00092 elif self.source is None and src is not None:
00093 com = self.commlist[-1]
00094 if com.has_unusedsource():
00095 com.setunusedsource( src )
00096 return
00097 else:
00098 raise Exception(
00099 'CommandPack instance initialized with stdin=None.\n'
00100 'Need "Source" class object in the command as a placeholder.\n'
00101 '\t(i.e) Command["somval"] = Source ' )
00102 return
00103
00104
00105 def getTarget( self ):
00106 'returns stdout target'
00107 return self.out_cont
00108
00109 def setTarget( self, tgt ):
00110 'returns stdout target'
00111 if self.target is True:
00112 self.out_cont = tgt
00113
00114 elif self.target is None and tgt is not None:
00115 com = self.commlist[-1]
00116 if com.has_unusedtarget():
00117 com.setunusedtarget( tgt )
00118 return
00119 else:
00120 raise Exception( 'target has not been set '
00121 'could not set stdout target and \n'
00122 'no target was found in the command')
00123
00124 return
00125
00126 source_node = property( getSourceNode )
00127 target_node = property( getTargetNode )
00128 source = property( getSource, setSource )
00129 target = property( getTarget, setTarget )
00130
00131