def run(self, gui): """Given a fresh empty master database in self.dbm, fill it from the open backup database file (self.dbs). """ try: # Create tables t = u"config" gui.report(_("Creating table '%s'") % t) self.makeTable(t) self.restoreTable(t) gui.report(_("Creating table 'data'")) self.dbm.createDataTable() self.restoreDataTable() self.dbm.createInterfaceTable() gui.report(_("Created interface table")) # Copy reports gui.report(_("Creating teacher report tables ...")) t = u"reports" # Get list of teachers from configuration data for tch in self.dbs.listAllFiles(u"teachers/"): self.makeTable(teacher2user(tch[9:])) # Parse all class configuration data, to determine # ownership of reports reports = makeReportsDict(self.dbs) for id, value in self.dbs.read(u"SELECT * FROM %s" % t): table = teacher2user(reports[id]) sqlins = u"INSERT INTO %s VALUES(?, ?)" % table self.dbm.send(sqlins, (id, value)) #********* This was just an idea, but it may never be used. # # Copy comments # gui.report(_("Copying comments ...")) # t = "comments" # self.makeTable(t) # self.restoreTable(t) gui.report(_("DONE!")) except: print_exc() message(_("Couldn't restore database")) self.dbm = None self.close()
def makeReports(self): """Update the teachers' report tables, adding and removing tables and records where demanded by the configuration changes. """ # Get a list of existing teacher tables ttables = self.db.getTeacherTables() # Get an updated list of teachers from the config data teachers = self.source.listFiles("teachers") # Create any new tables needed, and check for reports which # must be added or deleted allReports = makeReportsDict(self.source) for teacher in teachers: tbname = teacher2user(teacher) if tbname in ttables: ttables.remove(tbname) for rep in self.db.listIds(tbname): if allReports.has_key(rep): # Mark this report as already existing allReports[rep] = None else: self.report(_("Deleting report %1"), (rep, )) sqldel = u"DELETE FROM %s WHERE id = ?" % tbname self.db.send(sqldel, (rep, )) else: self.db.createIVTable(tbname) self.report(_("... made %1"), (tbname, )) self.report(_("Creating initial reports")) for key, t in allReports.items(): if t: sqlins = u"INSERT INTO %s VALUES(?, ?)" % teacher2user(t) self.db.send(sqlins, (key, makeReportValue(u"", u""))) # Remove unneeded tables for tbname in ttables: self.report(_("... removing %1"), (tbname, )) self.db.send(u"DROP TABLE %s" % tbname)
def makeReports(self): """Update the teachers' report tables, adding and removing tables and records where demanded by the configuration changes. """ # Get a list of existing teacher tables ttables = self.db.getTeacherTables() # Get an updated list of teachers from the config data teachers = self.source.listFiles("teachers") # Create any new tables needed, and check for reports which # must be added or deleted allReports = makeReportsDict(self.source) for teacher in teachers: tbname = teacher2user(teacher) if tbname in ttables: ttables.remove(tbname) for rep in self.db.listIds(tbname): if allReports.has_key(rep): # Mark this report as already existing allReports[rep] = None else: self.report(_("Deleting report %1"), (rep,)) sqldel = u"DELETE FROM %s WHERE id = ?" % tbname self.db.send(sqldel, (rep,)) else: self.db.createIVTable(tbname) self.report(_("... made %1"), (tbname,)) self.report(_("Creating initial reports")) for key, t in allReports.items(): if t: sqlins = u"INSERT INTO %s VALUES(?, ?)" % teacher2user(t) self.db.send(sqlins, (key, makeReportValue(u"", u""))) # Remove unneeded tables for tbname in ttables: self.report(_("... removing %1"), (tbname,)) self.db.send(u"DROP TABLE %s" % tbname)