initial commit for code clean up
diff --git a/TestON/drivers/component.py.fixed b/TestON/drivers/component.py.fixed
new file mode 100644
index 0000000..1e87d03
--- /dev/null
+++ b/TestON/drivers/component.py.fixed
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+import logging
+"""
+Created on 24-Oct-2012
+
+author:s: Anil Kumar ( anilkumar.s@paxterrasolutions.com ),
+ Raghav Kashyap( raghavkashyap@paxterrasolutions.com )
+
+
+ TestON is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ ( at your option ) any later version.
+
+ TestON is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+
+
+"""
+import re
+from logging import Logger
+
+
+class Component( object ):
+
+ """
+ This is the tempalte class for components
+ """
+ def __init__( self ):
+ self.default = ''
+ self.wrapped = sys.modules[ __name__ ]
+
+ def __getattr__( self, name ):
+ """
+ This will invoke, if the attribute wasn't found the usual ways.
+ Here it will look for assert_attribute and will execute when AttributeError occurs.
+ It will return the result of the assert_attribute.
+ """
+ try:
+ return getattr( self.wrapped, name )
+ except AttributeError:
+ try:
+ def experimentHandling( **kwargs ):
+ if main.EXPERIMENTAL_MODE == main.TRUE:
+ result = self.experimentRun( **kwargs )
+ main.log.info( "EXPERIMENTAL MODE. API " + str(
+ name ) + " not yet implemented. Returning dummy values" )
+ return result
+ else:
+ return main.FALSE
+ return experimentHandling
+ except TypeError as e:
+ main.log.error(
+ "Arguments for experimental mode does not have key 'retruns'" +
+ e )
+
+ def connect( self ):
+
+ vars( main )[ self.name + 'log' ] = logging.getLogger( self.name )
+
+ session_file = main.logdir + "/" + self.name + ".session"
+ self.log_handler = logging.FileHandler( session_file )
+ self.log_handler.setLevel( logging.DEBUG )
+
+ vars( main )[ self.name + 'log' ].setLevel( logging.DEBUG )
+ _formatter = logging.Formatter(
+ "%(asctime)s %(name)-10s: %(levelname)-8s: %(message)s" )
+ self.log_handler.setFormatter( _formatter )
+ vars( main )[ self.name + 'log' ].addHandler( self.log_handler )
+ # Adding header for the component log
+ vars( main )[ self.name + 'log' ].info( main.logHeader )
+ # Opening the session log to append command's execution output
+ self.logfile_handler = open( session_file, "a" )
+
+ return "Dummy"
+
+ def execute( self, cmd ):
+ return main.TRUE
+ # import commands
+ # return commands.getoutput( cmd )
+
+ def disconnect( self ):
+ return main.TRUE
+
+ def config( self ):
+ self = self
+ # Need to update the configuration code
+
+ def cleanup( self ):
+ return main.TRUE
+
+ def log( self, message ):
+ """
+ Here finding the for the component to which the
+ log message based on the called child object.
+ """
+ vars( main )[ self.name + 'log' ].info( "\n" + message + "\n" )
+
+ def close_log_handles( self ):
+ vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
+ if self.logfile_handler:
+ self.logfile_handler.close()
+
+ def get_version( self ):
+ return "Version unknown"
+
+ def experimentRun( self, **kwargs ):
+ args = utilities.parse_args( [ "RETURNS" ], **kwargs )
+ return args[ "RETURNS" ]
+
+
+if __name__ != "__main__":
+ import sys
+ sys.modules[ __name__ ] = Component()
+