Package TestON :: Package drivers :: Module component
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.component

  1  #!/usr/bin/env python 
  2  import logging 
  3  ''' 
  4  Created on 24-Oct-2012 
  5       
  6  @authors: Anil Kumar (anilkumar.s@paxterrasolutions.com), 
  7            Raghav Kashyap(raghavkashyap@paxterrasolutions.com) 
  8             
  9  ''' 
 10   
 11  import re 
 12  from logging import Logger 
 13   
14 -class Component(object):
15 ''' 16 This is the tempalte class for components 17 '''
18 - def __init__(self):
19 self.default = '' 20 self.wrapped = sys.modules[__name__]
21
22 - def __getattr__(self, name):
23 ''' 24 This will invoke, if the attribute wasn't found the usual ways. 25 Here it will look for assert_attribute and will execute when AttributeError occurs. 26 It will return the result of the assert_attribute. 27 ''' 28 try: 29 return getattr(self.wrapped, name) 30 except AttributeError: 31 try: 32 def experimentHandling(**kwargs): 33 if main.EXPERIMENTAL_MODE == main.TRUE: 34 result = self.experimentRun(**kwargs) 35 main.log.info("EXPERIMENTAL MODE. API "+str(name)+" not yet implemented. Returning dummy values") 36 return result 37 else: 38 return main.FALSE
39 return experimentHandling 40 except TypeError,e: 41 main.log.error("Arguments for experimental mode does not have key 'retruns'" + e)
42 43
44 - def connect(self):
45 46 vars(main)[self.name+'log'] = logging.getLogger(self.name) 47 48 session_file = main.logdir+"/"+self.name+".session" 49 self.log_handler = logging.FileHandler(session_file) 50 self.log_handler.setLevel(logging.DEBUG) 51 52 vars(main)[self.name+'log'].setLevel(logging.DEBUG) 53 _formatter = logging.Formatter("%(asctime)s %(name)-10s: %(levelname)-8s: %(message)s") 54 self.log_handler.setFormatter(_formatter) 55 vars(main)[self.name+'log'].addHandler(self.log_handler) 56 # Adding header for the component log 57 vars(main)[self.name+'log'].info(main.logHeader) 58 # Opening the session log to append command's execution output 59 self.logfile_handler = open(session_file,"a") 60 61 return "Dummy"
62
63 - def execute(self,cmd):
64 return main.TRUE
65 #import commands 66 #return commands.getoutput(cmd) 67
68 - def disconnect(self):
69 return main.TRUE
70
71 - def config(self):
72 self = self
73 # Need to update the configuration code 74
75 - def cleanup(self):
76 return main.TRUE
77
78 - def log(self,message):
79 ''' 80 Here finding the for the component to which the 81 log message based on the called child object. 82 ''' 83 vars(main)[self.name+'log'].info("\n"+message+"\n")
84
85 - def close_log_handles(self) :
86 vars(main)[self.name+'log'].removeHandler(self.log_handler) 87 if self.logfile_handler: 88 self.logfile_handler.close()
89
90 - def get_version(self):
91 return "Version unknown"
92
93 - def experimentRun(self,**kwargs):
94 args = utilities.parse_args(["RETURNS"],**kwargs) 95 return args["RETURNS"]
96 97 98 if __name__ != "__main__": 99 import sys 100 sys.modules[__name__] = Component() 101