Commit 44b00dd9 authored by Lutra Conseil's avatar Lutra Conseil Committed by Rafael Monnerat

[slapos.collect] Introduce getTableList on database

parent bf1908bb
......@@ -144,7 +144,13 @@ class Database:
self._execute(insertion_sql)
return insertion_sql
def getDataScopeList(self, ignore_date=None, reported=0):
def getTableList(self):
""" Get the list of tables from the database
"""
return [i[0] for i in self._execute(
"SELECT name FROM sqlite_master WHERE type='table'")]
def getDateScopeList(self, ignore_date=None, reported=0):
""" Get from the present unique dates from the system
Use a smaller table to sabe time.
"""
......
......@@ -53,11 +53,14 @@ class RawDumper(Dumper):
def dump(self, folder):
date = strftime("%Y-%m-%d")
self.db.connect()
for date_scope, amount in self.db.getDataScopeList(ignore_date=date):
self.writeFile("system", folder, date_scope, self.db.select("system", date_scope))
self.writeFile("user", folder, date_scope, self.db.select("user", date_scope))
self.writeFile("disk", folder, date_scope, self.db.select("disk", date_scope))
self.db.markDayAsReported(date_scope, table_list = ["system", "user", "disk"])
table_list = self.db.getTableList()
for date_scope, amount in self.db.getDateScopeList(ignore_date=date):
for table in table_list:
self.writeFile(table, folder, date_scope,
self.db.select(table, date_scope))
self.db.markDayAsReported(date_scope,
table_list=table_list)
self.db.commit()
self.db.close()
......
......@@ -79,11 +79,9 @@ class TestCollectDatabase(unittest.TestCase):
database = db.Database(self.instance_root)
database.connect()
try:
table_list = database._execute(
"SELECT name FROM sqlite_master WHERE type='table'")
self.assertEquals(
[(u'user',), (u'computer',), (u'system',), (u'disk',)],
[i for i in table_list])
[u'user', u'computer', u'system', u'disk'],
database.getTableList())
finally:
database.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment