8 def __git_describe__():
9 return utils.callsubprocess('git_describe',
10 conf.git_describe_cmd, False).rstrip()
13 return utils.callsubprocess('git_rev_parse',
14 conf.git_commit_cmd, False).rstrip()
17 return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S')
19 Config = collections.namedtuple('Config', 'id hash cfile') # Named tuple for configuration
20 Measure = collections.namedtuple('Measure', 'id conf_id mfile value') # Named tuple for measurement
23 "Class used for accessing PostgreSQL project database."
25 self.db = postgresql.open(database = conf.db_database,
27 password = conf.db_password,
32 def check_toolsgit(self):
33 "Return id of toolsgit row. If missing, it is inserted"
34 ds = __git_describe__()
36 ps = self.db.prepare("""SELECT id FROM toolsgit
37 WHERE git_describe = $1 AND git_commit = $2
42 ps = self.db.prepare("""INSERT INTO toolsgit
43 (git_describe, git_commit)
48 return self.check_toolsgit()
50 def add_configuration(self, hash, cfile):
51 "Add configuration to database."
52 ps = self.db.prepare("""INSERT INTO configurations
53 (hash, cfile, gtime, toolgit)
57 gt = self.check_toolsgit()
58 tm = datetime.datetime.now()
59 ps(hash, cfile, tm, gt)
61 def get_configration(self, hash):
62 "Return configration id for inserted hash."
63 ps = self.db.prepare("""SELECT id, cfile FROM configurations
67 rtn.append(Config(dt[0], hash, dt[1]))
70 def add_measure(self, mfile, conf_id, value = None):
72 ps = self.db.prepare("""INSERT INTO measure
73 (conf, mfile, value, mtime, toolgit)
77 gt = self.check_toolsgit()
78 tm = datetime.datetime.now()
79 ps(conf_id, mfile, value, tm, gt)
81 def update_measure(self, measure_id, value):
82 "Update measured value"
83 ps = self.db.prepare("""UPDATE measure SET
90 def get_measures(self, conf_id):
91 "Get measures for configuration with conf_id id"
92 ps = self.db.prepare("""SELECT id, mfile, value FROM measure
96 for dt in ps(conf_id):
97 rtn.append(Measure(dt[0], conf_id, dt[1], dt[2]))
100 def get_unmeasured(self):
101 "Returns list of all unmeasured configurations."
102 ps = self.db.prepare("""SELECT c.id, c.hash, c.cfile
103 FROM configurations AS c, measure AS m
104 WHERE c.id NOT IN m.conf;
108 rtn.append(Config(dt[0], dt[1], dt[2]))