1
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
15 '''
16 This is the tempalte class for components
17 '''
19 self.default = ''
20 self.wrapped = sys.modules[__name__]
21
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
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
57 vars(main)[self.name+'log'].info(main.logHeader)
58
59 self.logfile_handler = open(session_file,"a")
60
61 return "Dummy"
62
65
66
67
70
73
74
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
86 vars(main)[self.name+'log'].removeHandler(self.log_handler)
87 if self.logfile_handler:
88 self.logfile_handler.close()
89
91 return "Version unknown"
92
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