def makeBackUp(_settingType="All", _backUpDirectory="BackUps", _newFileName="mirror"): files = [] if _settingType == "database" or _settingType == "All": files.append("database.sqlite") if _settingType == "Settings" or _settingType == "All": files.append(uni.fileOfSettings) if fu.isDir(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory)) is False: fu.makeDirs(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory)) isReturn = False for backupFile in files: if _newFileName == "mirror": newFileName = backupFile elif _newFileName == "random": isReturn = True import random while 1 == 1: newFileName = (backupFile[:backupFile.find(".")] + "_" + str(random.randrange(0, 100000000)) + backupFile[backupFile.find("."):]) if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) is False: break else: newFileName = _newFileName if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)): fu.removeFile(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) try: fu.copyFileOrDir(fu.joinPath(fu.pathOfSettingsDirectory, backupFile), fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) if isReturn: return newFileName except: pass
def restoreBackUp(_settingType="All", _isMakeBackUp=True): files = [] isSuccessfully = True if _settingType == "database" or _settingType == "All": files.append("database.sqlite") if _settingType == "Settings" or _settingType == "All": files.append(uni.fileOfSettings) for backupFile in files: oldInfo = "" if _isMakeBackUp: oldInfo = fu.readFromFile(fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) else: try: fu.removeFile(fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) except: pass try: if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile)): fu.moveFileOrDir(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile), fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) else: isSuccessfully = False except: pass if _isMakeBackUp: fu.writeToFile(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile), oldInfo) return isSuccessfully
def restoreBackUp(_settingType="All", _isMakeBackUp=True): files = [] isSuccessfully = True if _settingType == "database" or _settingType == "All": files.append("database.sqlite") if _settingType == "Settings" or _settingType == "All": files.append(uni.fileOfSettings) for backupFile in files: oldInfo = "" if _isMakeBackUp: oldInfo = fu.readFromFile( fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) else: try: fu.removeFile( fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) except: pass try: if fu.isFile( fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile)): fu.moveFileOrDir( fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile), fu.joinPath(fu.pathOfSettingsDirectory, backupFile)) else: isSuccessfully = False except: pass if _isMakeBackUp: fu.writeToFile( fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile), oldInfo) return isSuccessfully
def delete(self): try: answer = Dialogs.ask(translate("ScriptManager", "Your Script Will Be Deleted!.."), translate("ScriptManager", "Your script will be deleted. Are you sure you want to delete current script?")) if answer == Dialogs.Yes: fu.removeFile(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)) self.refreshScriptList() except: ReportBug.ReportBug()
def reConfigure(self): try: oldPathOfExecutableHamsi = Settings.getUniversalSetting("HamsiManagerExecutableLinkPath", "/usr/bin/hamsi") if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")): if fu.isWritableFileOrDir(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")): MyConfigure.reConfigureFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")) if self.isCreateDesktopShortcut is not None: if self.isCreateDesktopShortcut.checkState() == Mt.Checked: desktopPath = uni.getUserDesktopPath() if uni.isWindows: MyConfigure.createShortCutFile(fu.joinPath(desktopPath, "Hamsi Manager.lnk")) else: fileContent = MyConfigure.getConfiguredDesktopFileContent() fu.writeToFile(fu.joinPath(desktopPath, "HamsiManager.desktop"), fileContent) if uni.isRunningAsRoot(): executableLink = str(self.leExecutableLink.text()) if self.isCreateExecutableLink is not None: if self.isCreateExecutableLink.checkState() == Mt.Checked: if executableLink.strip() != "": HamsiManagerFileName = Execute.findExecutableBaseName("HamsiManager") if fu.isFile(executableLink): fu.removeFileOrDir(executableLink) fu.createSymLink(fu.joinPath(fu.HamsiManagerDirectory, HamsiManagerFileName), executableLink) Settings.setUniversalSetting("HamsiManagerExecutableLinkPath", executableLink) if oldPathOfExecutableHamsi != executableLink: if fu.isFile(oldPathOfExecutableHamsi): answer = Dialogs.ask(translate("Reconfigure", "Other Hamsi Manager Was Detected"), str(translate("Reconfigure", "Other Hamsi Manager executable file was detected. Are you want to delete old executable file? You can delete this old executable file : \"%s\"")) % ( oldPathOfExecutableHamsi)) if answer != Dialogs.Yes: fu.removeFile(oldPathOfExecutableHamsi) if fu.isDir("/usr/share/applications/"): fileContent = MyConfigure.getConfiguredDesktopFileContent() fu.writeToFile("/usr/share/applications/HamsiManager.desktop", fileContent) if uni.isRunningAsRoot() is False: if fu.isDir(fu.joinPath(fu.userDirectoryPath, ".local", "applications")) is False: fu.makeDirs(fu.joinPath(fu.userDirectoryPath, ".local", "applications")) fileContent = MyConfigure.getConfiguredDesktopFileContent() fu.writeToFile(fu.joinPath(fu.userDirectoryPath, ".local", "applications", "HamsiManager.desktop"), fileContent) MyConfigure.installKDE4Languages() self.isInstallFinished = True except: ReportBug.ReportBug()
def makeBackUp(_settingType="All", _backUpDirectory="BackUps", _newFileName="mirror"): files = [] if _settingType == "database" or _settingType == "All": files.append("database.sqlite") if _settingType == "Settings" or _settingType == "All": files.append(uni.fileOfSettings) if fu.isDir(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory)) is False: fu.makeDirs(fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory)) isReturn = False for backupFile in files: if _newFileName == "mirror": newFileName = backupFile elif _newFileName == "random": isReturn = True import random while 1 == 1: newFileName = (backupFile[:backupFile.find(".")] + "_" + str(random.randrange(0, 100000000)) + backupFile[backupFile.find("."):]) if fu.isFile( fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) is False: break else: newFileName = _newFileName if fu.isFile( fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)): fu.removeFile( fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) try: fu.copyFileOrDir( fu.joinPath(fu.pathOfSettingsDirectory, backupFile), fu.joinPath(fu.pathOfSettingsDirectory, _backUpDirectory, newFileName)) if isReturn: return newFileName except: pass
def clear(self): try: answer = Dialogs.ask( translate("RecordsForm", "Are You Sure?"), translate("RecordsForm", "Are you sure you want to remove this record file?")) if answer == Dialogs.Yes: if self.cbRecordsList.currentIndex() == 0: Records.clearRecords() else: recordFilePath = self.recordsList[ self.cbRecordsList.currentIndex()] fu.removeFile( fu.joinPath(fu.oldRecordsDirectoryPath, recordFilePath)) self.recordsList = [ translate("RecordsForm", "Current Records") ] + Records.getBackupRecordsList() self.cbRecordsList.clear() self.cbRecordsList.addItems(self.recordsList) self.setRecordsFile() except: ReportBug.ReportBug()
def updateOldSettings(_oldVersion, _newVersion): newSettingsKeys, changedDefaultValuesKeys = [], [] try: oldVersion = int(_oldVersion) except: oldVersion = _newVersion if oldVersion < 1000: reFillAll(True) return newSettingsKeys, changedDefaultValuesKeys if oldVersion < 1081: newSettingsKeys = newSettingsKeys + ["isCheckUnSavedValues"] if oldVersion < 1082: con = sqlite.connect(fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute(str("ALTER TABLE searchAndReplaceTable RENAME TO tmpSearchAndReplaceTable;")) cur.execute(str( "CREATE TABLE searchAndReplaceTable ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'label' TEXT,'searching' TEXT,'replacing' TEXT,'intIsActive' INTEGER,'intIsCaseSensitive' INTEGER,'intIsRegExp' INTEGER);")) cur.execute(str( "INSERT INTO searchAndReplaceTable(label,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp) SELECT searching,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp FROM tmpSearchAndReplaceTable;")) cur.execute(str("DROP TABLE tmpSearchAndReplaceTable;")) con.commit() newSettingsKeys += ["isCorrectValueWithSearchAndReplaceTable"] if oldVersion < 1170: newSettingsKeys += ["maxDeletedDirectorySize"] if oldVersion < 1190: changedDefaultValuesKeys += ["applicationStyle", "fileExtensionIs"] if oldVersion < 1371: changedDefaultValuesKeys += ["fileExtensionIs"] if oldVersion < 1372: changedDefaultValuesKeys += ["packagerUnneededDirectories", "cleanerUnneededDirectories"] if oldVersion < 1373: uni.MySettings["AmarokTagSourceTypeAmarokMusicTable"] = "Amarok (Smart)" uni.MySettings["AmarokTagSourceTypeAmarokCopyTable"] = "Amarok (Smart)" if oldVersion < 1374: con = sqlite.connect(fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'File/Directory Name', 'baseName');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Directory Name', 'baseName');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Directory', 'baseNameOfDirectory');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Album Artist', 'albumArtist');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'File Name', 'baseName');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Artist', 'artist');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Title', 'title');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Album', 'album');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Track No', 'trackNum');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Year', 'year');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Genre', 'genre');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Comment', 'firstComment');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Lyrics', 'firstLyrics');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Current Cover', 'currentCover');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Source Cover', 'sourceCover');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Destination Cover', 'destinationCover');") cur.execute("UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'albumartist', 'albumArtist');") con.commit() if oldVersion < 1375: con = sqlite.connect(fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute( "DELETE FROM completerTable WHERE id NOT IN (SELECT MAX(id) FROM completerTable GROUP BY value,objectName);") cur.execute( "DELETE FROM bookmarksOfSpecialTools WHERE id NOT IN (SELECT MAX(id) FROM bookmarksOfSpecialTools GROUP BY value,type);") cur.execute( "DELETE FROM bookmarksOfDirectories WHERE id NOT IN (SELECT MAX(id) FROM bookmarksOfDirectories GROUP BY value,type,bookmark);") cur.execute( "DELETE FROM searchAndReplaceTable WHERE id NOT IN (SELECT MAX(id) FROM searchAndReplaceTable GROUP BY label,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp);") con.commit() if oldVersion < 1951: try: del uni.MySettings["eyeD3TaggerTypeNameForRead"] del uni.MySettings["eyeD3TaggerTypeNameForWrite"] except: pass setting().remove("eyeD3TaggerTypeNameForRead") setting().remove("eyeD3TaggerTypeNameForWrite") setting().sync() if oldVersion < 1952: changedDefaultValuesKeys += ["musicExtensions"] if oldVersion < 2006: try: del uni.MySettings["eyed3TaggerTypeNameForRead"] del uni.MySettings["eyed3TaggerTypeNameForWrite"] except: pass try: setting().remove("eyed3TaggerTypeNameForRead") setting().remove("eyed3TaggerTypeNameForWrite") setting().sync() except: pass if oldVersion < 2007: newSettingsKeys += ["preferedTaggerModule"] if oldVersion < 2008: for f in fu.readDirectory(fu.joinPath(fu.HamsiManagerDirectory, "Taggers"), "file"): if f.find("NewEyeD3Tagger") > -1: fu.removeFile(fu.joinPath(fu.HamsiManagerDirectory, "Taggers", f)) return newSettingsKeys, changedDefaultValuesKeys
def updateOldSettings(_oldVersion, _newVersion): newSettingsKeys, changedDefaultValuesKeys = [], [] try: oldVersion = int(_oldVersion) except: oldVersion = _newVersion if oldVersion < 1000: reFillAll(True) return newSettingsKeys, changedDefaultValuesKeys if oldVersion < 1081: newSettingsKeys = newSettingsKeys + ["isCheckUnSavedValues"] if oldVersion < 1082: con = sqlite.connect( fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute( str("ALTER TABLE searchAndReplaceTable RENAME TO tmpSearchAndReplaceTable;" )) cur.execute( str("CREATE TABLE searchAndReplaceTable ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'label' TEXT,'searching' TEXT,'replacing' TEXT,'intIsActive' INTEGER,'intIsCaseSensitive' INTEGER,'intIsRegExp' INTEGER);" )) cur.execute( str("INSERT INTO searchAndReplaceTable(label,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp) SELECT searching,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp FROM tmpSearchAndReplaceTable;" )) cur.execute(str("DROP TABLE tmpSearchAndReplaceTable;")) con.commit() newSettingsKeys += ["isCorrectValueWithSearchAndReplaceTable"] if oldVersion < 1170: newSettingsKeys += ["maxDeletedDirectorySize"] if oldVersion < 1190: changedDefaultValuesKeys += ["applicationStyle", "fileExtensionIs"] if oldVersion < 1371: changedDefaultValuesKeys += ["fileExtensionIs"] if oldVersion < 1372: changedDefaultValuesKeys += [ "packagerUnneededDirectories", "cleanerUnneededDirectories" ] if oldVersion < 1373: uni.MySettings[ "AmarokTagSourceTypeAmarokMusicTable"] = "Amarok (Smart)" uni.MySettings["AmarokTagSourceTypeAmarokCopyTable"] = "Amarok (Smart)" if oldVersion < 1374: con = sqlite.connect( fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'File/Directory Name', 'baseName');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Directory Name', 'baseName');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Directory', 'baseNameOfDirectory');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Album Artist', 'albumArtist');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'File Name', 'baseName');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Artist', 'artist');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Title', 'title');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Album', 'album');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Track No', 'trackNum');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Year', 'year');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Genre', 'genre');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Comment', 'firstComment');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Lyrics', 'firstLyrics');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Current Cover', 'currentCover');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Source Cover', 'sourceCover');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'Destination Cover', 'destinationCover');" ) cur.execute( "UPDATE bookmarksOfSpecialTools SET value=REPLACE(value,'albumartist', 'albumArtist');" ) con.commit() if oldVersion < 1375: con = sqlite.connect( fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) cur = con.cursor() cur.execute( "DELETE FROM completerTable WHERE id NOT IN (SELECT MAX(id) FROM completerTable GROUP BY value,objectName);" ) cur.execute( "DELETE FROM bookmarksOfSpecialTools WHERE id NOT IN (SELECT MAX(id) FROM bookmarksOfSpecialTools GROUP BY value,type);" ) cur.execute( "DELETE FROM bookmarksOfDirectories WHERE id NOT IN (SELECT MAX(id) FROM bookmarksOfDirectories GROUP BY value,type,bookmark);" ) cur.execute( "DELETE FROM searchAndReplaceTable WHERE id NOT IN (SELECT MAX(id) FROM searchAndReplaceTable GROUP BY label,searching,replacing,intIsActive,intIsCaseSensitive,intIsRegExp);" ) con.commit() if oldVersion < 1951: try: del uni.MySettings["eyeD3TaggerTypeNameForRead"] del uni.MySettings["eyeD3TaggerTypeNameForWrite"] except: pass setting().remove("eyeD3TaggerTypeNameForRead") setting().remove("eyeD3TaggerTypeNameForWrite") setting().sync() if oldVersion < 1952: changedDefaultValuesKeys += ["musicExtensions"] if oldVersion < 2006: try: del uni.MySettings["eyed3TaggerTypeNameForRead"] del uni.MySettings["eyed3TaggerTypeNameForWrite"] except: pass try: setting().remove("eyed3TaggerTypeNameForRead") setting().remove("eyed3TaggerTypeNameForWrite") setting().sync() except: pass if oldVersion < 2007: newSettingsKeys += ["preferedTaggerModule"] if oldVersion < 2008: for f in fu.readDirectory( fu.joinPath(fu.HamsiManagerDirectory, "Taggers"), "file"): if f.find("NewEyeD3Tagger") > -1: fu.removeFile( fu.joinPath(fu.HamsiManagerDirectory, "Taggers", f)) return newSettingsKeys, changedDefaultValuesKeys
def reConfigure(self): try: oldPathOfExecutableHamsi = Settings.getUniversalSetting( "HamsiManagerExecutableLinkPath", "/usr/bin/hamsi") if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")): if fu.isWritableFileOrDir( fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")): MyConfigure.reConfigureFile( fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")) if self.isCreateDesktopShortcut is not None: if self.isCreateDesktopShortcut.checkState() == Mt.Checked: desktopPath = uni.getUserDesktopPath() if uni.isWindows: MyConfigure.createShortCutFile( fu.joinPath(desktopPath, "Hamsi Manager.lnk")) else: fileContent = MyConfigure.getConfiguredDesktopFileContent( ) fu.writeToFile( fu.joinPath(desktopPath, "HamsiManager.desktop"), fileContent) if uni.isRunningAsRoot(): executableLink = str(self.leExecutableLink.text()) if self.isCreateExecutableLink is not None: if self.isCreateExecutableLink.checkState() == Mt.Checked: if executableLink.strip() != "": HamsiManagerFileName = Execute.findExecutableBaseName( "HamsiManager") if fu.isFile(executableLink): fu.removeFileOrDir(executableLink) fu.createSymLink( fu.joinPath(fu.HamsiManagerDirectory, HamsiManagerFileName), executableLink) Settings.setUniversalSetting( "HamsiManagerExecutableLinkPath", executableLink) if oldPathOfExecutableHamsi != executableLink: if fu.isFile(oldPathOfExecutableHamsi): answer = Dialogs.ask( translate( "Reconfigure", "Other Hamsi Manager Was Detected" ), str( translate( "Reconfigure", "Other Hamsi Manager executable file was detected. Are you want to delete old executable file? You can delete this old executable file : \"%s\"" )) % (oldPathOfExecutableHamsi)) if answer != Dialogs.Yes: fu.removeFile(oldPathOfExecutableHamsi) if fu.isDir("/usr/share/applications/"): fileContent = MyConfigure.getConfiguredDesktopFileContent( ) fu.writeToFile( "/usr/share/applications/HamsiManager.desktop", fileContent) if uni.isRunningAsRoot() is False: if fu.isDir( fu.joinPath(fu.userDirectoryPath, ".local", "applications")) is False: fu.makeDirs( fu.joinPath(fu.userDirectoryPath, ".local", "applications")) fileContent = MyConfigure.getConfiguredDesktopFileContent() fu.writeToFile( fu.joinPath(fu.userDirectoryPath, ".local", "applications", "HamsiManager.desktop"), fileContent) MyConfigure.installKDE4Languages() self.isInstallFinished = True except: ReportBug.ReportBug()