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,
30 password = conf.db_password,
34 # check if tables are present
35 tables = ('toolsgit', 'configurations', 'measure')
37 val = self.db.prepare("""SELECT COUNT(*) FROM pg_class
38 WHERE relname = $1""")(tab)[0][0]
40 raise exceptions.DatabaseUninitialized()
42 def check_toolsgit(self):
43 "Return id of toolsgit row. If missing, it is inserted"
44 ds = __git_describe__()
46 ps = self.db.prepare("""SELECT id FROM toolsgit
47 WHERE git_describe = $1 AND git_commit = $2
52 ps = self.db.prepare("""INSERT INTO toolsgit
53 (git_describe, git_commit)
58 return self.check_toolsgit()
60 def check_linuxgit(self):
61 "Return id of linuxgit row. If missing, it is inserted."
63 os.chdir(sf(conf.linux_sources))
64 ds = __git_describe__()
67 ps = self.db.prepare("""SELECT id FROM linuxgit
68 WHERE git_describe = $1 AND git_commit = $2
73 ps = self.db.prepare("""INSERT INTO linuxgit
74 (git_describe, git_commit)
79 return self.check_linuxgit()
81 def add_configuration(self, hash, txtconfig, generator):
82 "Add configuration to database."
83 ps = self.db.prepare("""INSERT INTO configurations
84 (hash, config, gtime, toolgit, linuxgit, generator)
86 ($1, $2, $3, $4, $5, $6);
88 gt = self.check_toolsgit()
89 lgt = self.check_linuxgit()
90 tm = datetime.datetime.now()
91 ps(hash, '\n'.join(txtconfig), tm, gt, lgt, generator)
93 def get_configration(self, hash):
94 "Return configration id for inserted hash."
95 ps = self.db.prepare("""SELECT id, config FROM configurations
99 rtn.append(Config(dt[0], hash, dt[1].split('\n')))
102 def add_measure(self, output, result, conf_id, value = None):
104 ps = self.db.prepare("""INSERT INTO measure
105 (conf, output, value, mtime, toolgit,
106 linuxgit, measurement, result)
108 ($1, $2, $3, $4, $5, $6, $7, $8);
110 gt = self.check_toolsgit()
111 lgt = self.check_linuxgit()
112 tm = datetime.datetime.now()
113 ps(conf_id, output, value, tm, gt, lgt, conf.measure_identifier, result)
115 def update_measure(self, measure_id, value):
116 "Update measured value"
117 ps = self.db.prepare("""UPDATE measure SET
122 ps(measure_id, value)
124 def get_measures(self, conf_id):
125 "Get measures for configuration with conf_id id"
126 ps = self.db.prepare("""SELECT id, output, value FROM measure
130 for dt in ps(conf_id):
131 rtn.append(Measure(dt[0], conf_id, dt[1], dt[2]))
134 def get_unmeasured(self):
135 "Returns list of all unmeasured configurations."
136 ps = self.db.prepare("""SELECT id, hash, config FROM configurations
138 (SELECT conf FROM measure)
142 rtn.append(Config(dt[0], dt[1], dt[2].split('\n')))
145 def add_configsort(self, configopt):
146 "Add configuration option to sorted list"
147 ps = self.db.prepare("""INSERT INTO configopt
148 (configopt) VALUES ($1)
152 def get_configsort(self):
153 "Returns sorted list of all configuration options"
154 ps = self.db.prepare("""SELECT id, configopt FROM configopt
159 for id, config in itms: