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 cfile') # Named tuple for configuration
23 Measure = collections.namedtuple('Measure', 'id conf_id mfile 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, cfile, generator):
82 "Add configuration to database."
83 ps = self.db.prepare("""INSERT INTO configurations
84 (hash, cfile, 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, cfile, tm, gt, lgt, generator)
93 def get_configration(self, hash):
94 "Return configration id for inserted hash."
95 ps = self.db.prepare("""SELECT id, cfile FROM configurations
99 rtn.append(Config(dt[0], hash, dt[1]))
102 def add_measure(self, mfile, conf_id, value = None):
104 ps = self.db.prepare("""INSERT INTO measure
105 (conf, mfile, value, mtime, toolgit, linuxgit, measurement)
107 ($1, $2, $3, $4, $5, $6, $7);
109 gt = self.check_toolsgit()
110 lgt = self.check_linuxgit()
111 tm = datetime.datetime.now()
112 ps(conf_id, mfile, value, tm, gt, lgt, conf.measure_identifier)
114 def update_measure(self, measure_id, value):
115 "Update measured value"
116 ps = self.db.prepare("""UPDATE measure SET
121 ps(measure_id, value)
123 def get_measures(self, conf_id):
124 "Get measures for configuration with conf_id id"
125 ps = self.db.prepare("""SELECT id, mfile, value FROM measure
129 for dt in ps(conf_id):
130 rtn.append(Measure(dt[0], conf_id, dt[1], dt[2]))
133 def get_unmeasured(self):
134 "Returns list of all unmeasured configurations."
135 ps = self.db.prepare("""SELECT * FROM configurations
137 (SELECT conf FROM measure)
141 rtn.append(Config(dt[0], dt[1], dt[2]))