9 def __git_describe__():
10 return utils.callsubprocess('git_describe',
11 conf.git_describe_cmd, False, True)[0]
14 return utils.callsubprocess('git_rev_parse',
15 conf.git_commit_cmd, False, True)[0]
18 return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S')
20 Config = collections.namedtuple('Config', 'id hash cfile') # Named tuple for configuration
21 Measure = collections.namedtuple('Measure', 'id conf_id mfile value') # Named tuple for measurement
24 "Class used for accessing PostgreSQL project database."
26 self.db = postgresql.open(database = conf.db_database,
28 password = conf.db_password,
32 # check if tables are present
33 tables = ('toolsgit', 'configurations', 'measure')
35 val = self.db.prepare("""SELECT COUNT(*) FROM pg_class
36 WHERE relname = $1""")(tab)[0][0]
38 raise exceptions.DatabaseUninitialized()
40 def check_toolsgit(self):
41 "Return id of toolsgit row. If missing, it is inserted"
42 ds = __git_describe__()
44 ps = self.db.prepare("""SELECT id FROM toolsgit
45 WHERE git_describe = $1 AND git_commit = $2
50 ps = self.db.prepare("""INSERT INTO toolsgit
51 (git_describe, git_commit)
56 return self.check_toolsgit()
58 def add_configuration(self, hash, cfile):
59 "Add configuration to database."
60 ps = self.db.prepare("""INSERT INTO configurations
61 (hash, cfile, gtime, toolgit)
65 gt = self.check_toolsgit()
66 tm = datetime.datetime.now()
67 ps(hash, cfile, tm, gt)
69 def get_configration(self, hash):
70 "Return configration id for inserted hash."
71 ps = self.db.prepare("""SELECT id, cfile FROM configurations
75 rtn.append(Config(dt[0], hash, dt[1]))
78 def add_measure(self, mfile, conf_id, value = None):
80 ps = self.db.prepare("""INSERT INTO measure
81 (conf, mfile, value, mtime, toolgit)
85 gt = self.check_toolsgit()
86 tm = datetime.datetime.now()
87 ps(conf_id, mfile, value, tm, gt)
89 def update_measure(self, measure_id, value):
90 "Update measured value"
91 ps = self.db.prepare("""UPDATE measure SET
98 def get_measures(self, conf_id):
99 "Get measures for configuration with conf_id id"
100 ps = self.db.prepare("""SELECT id, mfile, value FROM measure
104 for dt in ps(conf_id):
105 rtn.append(Measure(dt[0], conf_id, dt[1], dt[2]))
108 def get_unmeasured(self):
109 "Returns list of all unmeasured configurations."
110 ps = self.db.prepare("""SELECT c.id, c.hash, c.cfile
111 FROM configurations AS c, measure AS m
112 WHERE c.id NOT IN m.conf;
116 rtn.append(Config(dt[0], dt[1], dt[2]))