00001 """ 00002 rsfAddCommands class to chain together commands into a pipe 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.Command.Command import Command 00027 from slimpy_base.Core.Command.Drivers.remote_pipe import RemoteDriver 00028 from slimpy_base.Core.Interface.ContainerBase import DataContainer 00029 00030 class rsfAddCommands( object ): 00031 """ 00032 class to add two commands together 00033 """ 00034 ERRORMSG1 = ( "add commands must recieve " 00035 "either a datacontainer or a Command" 00036 "\ngot a %s" ) 00037 00038 ERRORMSG2 = "add commands must recieve either a DataContainer or a Command" 00039 00040 def __init__( self ): 00041 pass 00042 00043 00044 def __call__( self, c1, c2 ): 00045 """ 00046 add c1 and c2 together to form a pipe command 00047 @return: a multiDriver instance 00048 """ 00049 if isinstance( c1, DataContainer ): 00050 driver = RemoteDriver() 00051 00052 if isinstance( c2, Command ): 00053 driver.setSource( c1 ) 00054 driver.addCommand( c2 ) 00055 00056 else: 00057 00058 raise TypeError(self.ERRORMSG2) 00059 00060 elif isinstance( c1, Command ): 00061 00062 00063 if isinstance( c1.func, RemoteDriver ): 00064 driver = c1.func 00065 else : 00066 driver = RemoteDriver() 00067 driver.addCommand( c1 ) 00068 00069 if isinstance( c2, DataContainer ): 00070 driver.setTarget( c2 ) 00071 00072 elif isinstance( c2, Command ): 00073 driver.addCommand( c2 ) 00074 00075 elif c2 is None: 00076 pass 00077 else: 00078 raise TypeError( self.ERRORMSG1 % type( c2 ) ) 00079 else: 00080 00081 raise TypeError( self.ERRORMSG1 % type( c2 ) ) 00082 00083 com = Command( "_multi_", self ) 00084 com.func = driver 00085 00086 return com 00087 00088 00089 00090 00091