From 3fb56b4760b0485cf0872100f04b0a5a51f52e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 17 Aug 2015 18:35:12 +0200 Subject: Generated configuration is now fully stored to database Managing configurations in files and in database could cause inconsistence. Adding all generated configurations to database allow us to clean project files without loosing data. --- scripts/database.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'scripts/database.py') diff --git a/scripts/database.py b/scripts/database.py index 6a4d0a1..c4f0a60 100644 --- a/scripts/database.py +++ b/scripts/database.py @@ -19,7 +19,7 @@ def __git_commit__(): def __timestamp__(): return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S') -Config = collections.namedtuple('Config', 'id hash cfile') # Named tuple for configuration +Config = collections.namedtuple('Config', 'id hash config') # Named tuple for configuration Measure = collections.namedtuple('Measure', 'id conf_id mfile value') # Named tuple for measurement class database: @@ -78,21 +78,21 @@ class database: ps(ds, cm) return self.check_linuxgit() - def add_configuration(self, hash, cfile, generator): + def add_configuration(self, hash, txtconfig, generator): "Add configuration to database." ps = self.db.prepare("""INSERT INTO configurations - (hash, cfile, gtime, toolgit, linuxgit, generator) + (hash, config, gtime, toolgit, linuxgit, generator) VALUES ($1, $2, $3, $4, $5, $6); """) gt = self.check_toolsgit() lgt = self.check_linuxgit() tm = datetime.datetime.now() - ps(hash, cfile, tm, gt, lgt, generator) + ps(hash, txtconfig, tm, gt, lgt, generator) def get_configration(self, hash): "Return configration id for inserted hash." - ps = self.db.prepare("""SELECT id, cfile FROM configurations + ps = self.db.prepare("""SELECT id, config FROM configurations WHERE hash = $1""") rtn = [] for dt in ps(hash): @@ -140,3 +140,17 @@ class database: for dt in ps(): rtn.append(Config(dt[0], dt[1], dt[2])) return rtn + + def add_configsort(self, configopt): + "Add configuration option to sorted list" + ps = self.db.prepare("""INSERT INTO configopt + (configopt) VALUES ($1) + """) + ps() + + def get_configsort(self): + "Returns sorted list of all configuration options" + ps = self.db.prepare("""SELECT configopt FROM configopt + ORDER BY id ASC + """) + return ps() -- cgit v1.2.3