forked from nmohr/pyxar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyXar
executable file
·106 lines (96 loc) · 4.08 KB
/
pyXar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
import sys
import os
import logging
import logging.config
import optparse
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
from python import *
from gui import PxarGui
import inspect
__version__ = "pyXar: 0.2"
class Pyxar(PyCmd):
def __init__(self, a_workdir):
# dinamicaly generate list of cls inhertiting from Test base cls
self.tests = [e[0].__name__ for e in [inspect.getmro(eval(a[0])) for a in inspect.getmembers(sys.modules[__name__], inspect.isclass)] if e[1].__name__=='Test' and not e[0].__name__=='HRTest']
self.tests.extend([e[0].__name__ for e in [inspect.getmro(eval(a[0])) for a in inspect.getmembers(sys.modules[__name__], inspect.isclass)] if e[1].__name__=='HRTest'])
super(Pyxar, self).__init__()
self.workdir = os.path.dirname(os.path.realpath(sys.argv[0]))
logging.ColorFormatter = ColorFormatter
logging.config.fileConfig('%s/config/logging.conf'%self.workdir)
self.directory = a_workdir
self.logger = logging.getLogger(self.__class__.__name__)
self.window = None
self.api = False
def do_init(self, line, trimVcal = ''):
configs = ['%s/module'%(self.directory), '%s/tb'%(self.directory), '%s/test.cfg'%(self.directory)]
self.config = BetterConfigParser()
self.config.read(configs)
self.config.add_section('General')
self.config.set('General', 'work_dir', self.directory)
if self.config.has_option('configParameters','trimParameters') and trimVcal == '':
trimVcal = self.config.get('configParameters','trimParameters')
self.dut = DUT(self.config,trimVcal)
self.dut.activate_pixel(0,5,5)
if self.api:
from python import api
self.tb = api.api(self.config.get('Testboard','id'), "WARNING")
self.tb.startup(self.config, self.dut)
else:
self.tb = Testboard(self.config, self.dut)
self.logger.info('Initialzed DTB.')
self.tb.ia()
self.tb.id()
def do_gui(self, line):
if self.window:
return
self.window = PxarGui( ROOT.gClient.GetRoot(), 800, 800 )
def help_gui(self):
print 'open result browser'
@staticmethod
def str_to_class(str):
return reduce(getattr, str.split("."), sys.modules[__name__])
def run_test(self, line):
a_test = globals()[line](self.tb, self.config, self.window)
a_test.go(self.config)
if self.window:
self.window.histos.extend(a_test.histos)
self.window.update()
def get_help(self, line):
text = '\x1b[1m\x1b[4m\n'
text += line
text += ':\x1b[0m\n'
text += str(globals()[line].__doc__)
text += '\n\x1b[34m'
if self.config.has_section(line):
text += '\n \x1b[4mSettings:\n\x1b[24m'
for k, v in dict(self.config.items(line)).items():
text += ' %-25s%s\n' %(k, v)
#text += '\t%s:\t%s\n' %(k, v)
text += '\x1b[0m'
return text
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option("-d", "--dir", dest="work_dir", default='data',
help="Folder with DUT/DTB settings.", metavar="DIR")
parser.add_option("-n", "--nogui", dest="gui", default=True, action="store_false",
help="Run without gui.")
parser.add_option("-a", "--api", dest="api", default=False, action="store_true",
help="Use api as underlying core.")
parser.add_option("-t", "--trim", dest="trim_vcal", default='',
help="Load trimmed dacParameter file.")
(options, args) = parser.parse_args()
a_workdir = os.path.abspath(options.work_dir)
pyxar = Pyxar(a_workdir)
pyxar.logger.info('using working dir %s'%a_workdir)
pyxar.api = options.api
if options.gui:
pyxar.window = PxarGui( ROOT.gClient.GetRoot(), 800, 800 )
#TODO remove
pyxar.do_init('',trimVcal = options.trim_vcal)
try:
__version__ = open('config/logo').read()
except:
pass
pyxar.cmdloop(__version__)