def backupSavedSessions(self):
        if not QFile.exists(self._lastActiveSessionPath):
            return

        if QFile.exists(self._firstBackupSession):
            QFile.remove(self._secondBackupSession)
            QFile.copy(self._firstBackupSession, self._secondBackupSession)

        QFile.remove(self._firstBackupSession)
        QFile.copy(self._lastActiveSessionPath, self._firstBackupSession)
Beispiel #2
0
    def save (self,filename = None):
        print ("sauvegarde")
        progress = QProgressDialog ()
        progress.setWindowModality(QtCore.Qt.WindowModal)
        progress.setLabelText("Sauvegarde")
        progress.setMaximum(len(self.getWarriorList())+1)
        #db_name = self.database.database.databaseName()
        if filename == None : 
            filename = os.path.join(Config().instance.path_to_sqlite(),self.settings.value("global/current_database"))
        try :
            print ('current filename', filename)
            # backup 
            filename_bkp = filename+"_"+QtCore.QDateTime.currentDateTime().toString("yyyy-MM-dd-hh-mm-ss")
            QFile.copy(filename,filename_bkp)
            if QFile.remove(filename) == False :
                qWarning("echec suppression ")
            else:
                qWarning("reussite suppression %s"% filename)                
        except OSError :
            qWarning("echec suppression ")

        result = QFile.copy(Config().instance.model_database(),filename)
        if result == False :
            print("echec de la copy ",Config().instance.model_database(),filename)
            return
        else:
            print("copy du model reussit")
            database = DatabaseManager(filename,True)
            database.createConnection()
            database.setVerbose(True)
        for faction in self.factions.values() :
            attribs = faction.getDictAttributes ()
            database.insert("gm_faction",attribs)
            for empire in faction.empires.values():
                attribs = empire.getDictAttributes ()
                database.insert("gm_empire",attribs)
                for kingdom in empire.kingdoms.values():
                    attribs = kingdom.getDictAttributes ()
                    database.insert("gm_kingdom",attribs)
                    for temple in kingdom.temples:
                        attribs = temple.getDictAttributes ()
                        database.insert("gm_temple",attribs)                        
                    for groupe in kingdom.groupes.values():
                        attribs = groupe.getDictAttributes ()
                        database.insert("gm_groupe",attribs)
                        for sub_groupe in groupe.sub_groupes:
                            attribs = sub_groupe.getDictAttributes ()
                            database.insert("gm_groupe",attribs)
                            for perso in sub_groupe.warriors.values():
                                attribs = perso.getDictAttributes ()
                                database.insert("gm_perso",attribs)
                        for perso in groupe.warriors.values():
                            attribs = perso.getDictAttributes ()
                            database.insert("gm_perso",attribs)
                            progress.setValue(progress.value()+1)
Beispiel #3
0
 def copyRecursively(self, sourcePath, targetPath):
     srcFileInfo = QFileInfo(sourcePath)
     if srcFileInfo.isDir() and not srcFileInfo.isSymLink():
         targetDir = QDir(targetPath)
         targetDir.cdUp()
         if not targetDir.mkdir(QFileInfo(targetPath).fileName()):
             return False
         fileNames = QDir(sourcePath).entryList(QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot |
                 QDir.Hidden | QDir.System)
         for fileName in fileNames:
             newSourcePath = sourcePath + '/' + fileName
             newTargetPath = targetPath + '/' + fileName
             if not self.copyRecursively(newSourcePath, newTargetPath):
                 return False
     elif not const.OS_WIN and srcFileInfo.isSymLink():
         linkPath = readlink(sourcePath)
         return QFile.link(linkPath, targetPath)
     elif not QFile.copy(sourcePath, targetPath):
         return False
     return True
    def _renameSession(self, sessionFilePath='', flags=0):
        if not sessionFilePath:
            action = self.sender()
            if not isinstance(action, QAction):
                return

            sessionFilePath = action.data()

        suggestedName = QFileInfo(sessionFilePath).completeBaseName() + \
            (flags & self.CloneSession) and _('_cloned') or _('_renamed')

        newName, ok = QInputDialog.getText(gVar.app.activeWindow(),
            (flags & self.CloneSession) and _('Clone Session') or _('Rename Session'),
            _('Please enter a new name:'), QLineEdit.Normal, suggestedName)

        if not ok:
            return

        newSessionPath = '%s/%s.dat' % (DataPaths.path(DataPaths.Sessions), newName)
        if QFile.exists(newSessionPath):
            QMessageBox.information(gVar.app.activeWindow(), _('Error!'),
                    _('The session file "%s" exists. Please enter another name.') % newName)
            self._renameSession(sessionFilePath, flags)
            return

        if flags & self.CloneSession:
            if not QFile.copy(sessionFilePath, newSessionPath):
                QMessageBox.information(gVar.app.activeWindow(), _('Error!'),
                    _('An error occurred when cloning session file.'))
                return
        else:
            if not QFile.rename(sessionFilePath, newSessionPath):
                QMessageBox.information(gVar.app.activeWindow(), _('Error!'),
                    _('An error occurred when renaming session file.'))
                return
            if self._isActive(sessionFilePath):
                self._lastActiveSessionPath = newSessionPath
                self._sessionsMetaDataList.clear()