Esempio n. 1
0
 def run(self, gui):
     failList = []
     for user in self.userlist:
         gui.report(u"::: " + user)
         backup = Dump(self.master, self.dbpath, user)
         if not backup.filepath:
             failList.append(user)
             continue
         backup.run(gui)
         if not backup.filepath:
             failList.append(user)
     if failList:
         gui.report(_("***************\n"
                 "Database files could not be created for:\n  %s")
                 % repr(failList))
Esempio n. 2
0
 def run(self, gui):
     failList = []
     for user in self.userlist:
         gui.report(u"::: " + user)
         backup = Dump(self.master, self.dbpath, user)
         if not backup.filepath:
             failList.append(user)
             continue
         backup.run(gui)
         if not backup.filepath:
             failList.append(user)
     if failList:
         gui.report(
             _("***************\n"
               "Database files could not be created for:\n  %s") %
             repr(failList))
Esempio n. 3
0
def recreate(dbm, filepath, user, gui):
    """Recreate the user database, taking master update lock
    into consideration. NOTE that this 'lock' is not 100%
    effective, but it is a simple method which I hope will be
    adequate for the envisaged application.
    """
    dir = os.path.dirname(filepath)
    while True:
        udt = getudtime(dbm)
        if not mUnstable(dbm):
            break
        gui.report(_("Master database is in unstable state.\n  Waiting ..."))
        sleep(10)

    # Dump the master database to the selected file
    while True:
        dump = Dump(dbm, dir, user)
        if dump.filepath:
            break
        warning(_("Couldn't create database file in folder %1,"
                " select new folder"), (dir,))
        dir = getDirectory(dir)
        if not dir:
            if confirmationDialog(_("Abandon?"),
                    _("User database not regenerated,"
                    " do you really want to abandon this operation?"), False):
                break

    if dump.filepath:
        dump.run(gui)

    fp = dump.filepath
    dump = None
    if fp:
        # Check master database hasn't been updated
        if (udt == getudtime(dbm)):
            gui.report(_("\nSUCCESS! - User database regenerated"))
        else:
            gui.report(_("Master has been updated,"
                    " need to repeat...\n"))
            recreate(dbm, filepath, user, gui)
    else:
        gui.report(_("\nFAILED! Couldn't regenerate user database.\n"
                " --- Please contact administrator!"))
Esempio n. 4
0
 def dump(self, dbpath, user, isList=False):
     if isList and user:
         backup = DumpUsers(user, self.master, dbpath)
         guimessage = _("Creating multiple user database files ...\n")
     else:
         backup = Dump(self.master, dbpath, user)
         if not backup.filepath: return None
         guimessage = argSub(
             _("Database file '%1' created, now"
               " read in the data"), (backup.filepath, ))
     if user:
         title = _("Create User Database File")
     else:
         title = _("Create Full Database Dump File")
     guiReport(title, backup, guimessage)
     return backup.filepath
Esempio n. 5
0
    def slot_dump(self, arg):
        """Generate a backup file (sqlite database).
        """
        # Get destination directory:
        dir0 = self.settings.getSetting("destDir")
        dbpath = getDirectory(_("Destination Folder"), dir0)
        if not dbpath: return
        self.settings.setSetting("destDir", dbpath)

        # Do the dump
        backup = Dump(self.master, dbpath)
        if not backup.filepath: return

        guimessage = argSub(
            _("New backup file '%1' opened, now write in the data"),
            (backup.filepath, ))
        guiReport(_("Create Backup File"), backup, guimessage)
Esempio n. 6
0
    def updateDbConfig(self, source):
        """Update the current database using the configuration file supplied
        as a CfgZip object in source.
        The selected config file must match the name of the current database.
        Before updating from this file, dump the current database state
        to a folder 'dumps' in the same folder as the config file.
        That is in case something goes wrong and the old state must be
        recovered.
        """
        if (self.dbname != source.cfgName):
            message(_("Database name does not match data folder"))
            return

        # Backup existing database state.
        sPath = self.configEd.getSourcePath()
        budir = os.path.join(os.path.dirname(sPath), 'dumps')
        if not os.path.isdir(budir):
            os.mkdir(budir)
        backup = Dump(self.master, budir)
        filepath = backup.filepath
        if not filepath: return

        guimessage = argSub(
            _("New backup file '%1' created, now read in the data"),
            (filepath, ))
        guiReport(_("Create Backup File"), backup, guimessage)

        backup = None
        if not filepath: return

        try:
            guimessage = argSub(_("Updating database '%1' from %2"),
                                (self.dbname, sPath))
            mm = MakeMaster(source, self.master)
            guiReport(_("Updating Master Database"), mm, guimessage)
            mm = None

        except:
            print_exc()
            message(_("Update failed, trying to restore from '%1'"),
                    (filepath, ))

            restore = Restore(filepath)
            dbname = restore.getDbName()
            if not dbname:
                message(_("Couldn't open database file '%1'"), (filepath, ))
                return

            # Delete all tables
            for t in self.master.getTables():
                self.master.send(u"DROP TABLE %s" % t)

            # Restore old state
            guimessage = argSub(
                _("Database '%1' cleared, now restore the data"), (dbname, ))
            restore.setMaster(self.master)
            guiReport(_("Restore Database"), restore, guimessage)

        self.usersPrivileges(self.master)

        # adjust display, select new db
        self.initDBlist()