11 def __git_describe__():
12 return utils.callsubprocess('git_describe',
13 conf.git_describe_cmd, False, True)[0]
16 return utils.callsubprocess('git_rev_parse',
17 conf.git_commit_cmd, False, True)[0]
20 return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S')
22 Config = collections.namedtuple('Config', 'id hash config') # Named tuple for configuration
23 Measure = collections.namedtuple('Measure', 'id conf_id output value') # Named tuple for measurement
26 "Class used for accessing PostgreSQL project database."
28 self.db = postgresql.open(database = conf.db_database,
29 unix='/var/run/postgresql/.s.PGSQL.5432',
31 # check if tables are present
32 tables = ('toolsgit', 'configurations', 'measure')
34 val = self.db.prepare("""SELECT COUNT(*) FROM pg_class
35 WHERE relname = $1""")(tab)[0][0]
37 raise exceptions.DatabaseUninitialized()
39 def check_toolsgit(self):
40 "Return id of toolsgit row. If missing, it is inserted"
41 ds = __git_describe__()
43 ps = self.db.prepare("""SELECT id FROM toolsgit
44 WHERE git_describe = $1 AND git_commit = $2
49 ps = self.db.prepare("""INSERT INTO toolsgit
50 (git_describe, git_commit)
55 return self.check_toolsgit()
57 def check_linuxgit(self):
58 "Return id of linuxgit row. If missing, it is inserted."
60 os.chdir(sf(conf.linux_sources))
61 ds = __git_describe__()
64 ps = self.db.prepare("""SELECT id FROM linuxgit
65 WHERE git_describe = $1 AND git_commit = $2
70 ps = self.db.prepare("""INSERT INTO linuxgit
71 (git_describe, git_commit)
76 return self.check_linuxgit()
78 def add_configuration(self, hash, txtconfig, generator):
79 "Add configuration to database."
80 ps = self.db.prepare("""INSERT INTO configurations
81 (hash, config, gtime, toolgit, linuxgit, generator)
83 ($1, $2, $3, $4, $5, $6);
85 gt = self.check_toolsgit()
86 lgt = self.check_linuxgit()
87 tm = datetime.datetime.now()
88 ps(hash, '\n'.join(txtconfig), tm, gt, lgt, generator)
90 def get_configration(self, hash):
91 "Return configration id for inserted hash."
92 ps = self.db.prepare("""SELECT id, config FROM configurations
96 rtn.append(Config(dt[0], hash, dt[1].split('\n')))
99 def add_measure(self, output, result, conf_id, value = None):
101 ps = self.db.prepare("""INSERT INTO measure
102 (conf, output, value, mtime, toolgit,
103 linuxgit, measurement, result)
105 ($1, $2, $3, $4, $5, $6, $7, $8);
107 gt = self.check_toolsgit()
108 lgt = self.check_linuxgit()
109 tm = datetime.datetime.now()
110 ps(conf_id, output, value, tm, gt, lgt, conf.measure_identifier, result)
112 def update_measure(self, measure_id, value):
113 "Update measured value"
114 ps = self.db.prepare("""UPDATE measure SET
119 ps(measure_id, value)
121 def get_measures(self, conf_id):
122 "Get measures for configuration with conf_id id"
123 ps = self.db.prepare("""SELECT id, output, value FROM measure
127 for dt in ps(conf_id):
128 rtn.append(Measure(dt[0], conf_id, dt[1], dt[2]))
131 def get_unmeasured(self):
132 "Returns list of all unmeasured configurations."
133 ps = self.db.prepare("""SELECT id, hash, config FROM configurations
135 (SELECT conf FROM measure)
139 rtn.append(Config(dt[0], dt[1], dt[2].split('\n')))
142 def add_configsort(self, configopt):
143 "Add configuration option to sorted list"
144 ps = self.db.prepare("""INSERT INTO configopt
145 (configopt) VALUES ($1)
149 def get_configsort(self):
150 "Returns sorted list of all configuration options"
151 ps = self.db.prepare("""SELECT id, configopt FROM configopt
156 for id, config in itms: