def changeCoverValues(self, _image=None, _valueType="file"): self.zoomValue = 1.0 if _image is not None and _valueType == "file": _image = fu.checkSource(_image, "file", False) if _image is None: if self.isCorrectedWhenNotExist: _image = fu.joinPath(fu.themePath, "Images", "ok.png") else: _image = fu.joinPath(fu.themePath, "Images", "notExist.png") elif _valueType == "file": _image = fu.joinPath(fu.themePath, "Images", "notExist.png") self.pmapImage.detach() if _valueType == "data": self.pmapImage.loadFromData(_image) else: self.pmapImage.load(str(_image)) self.lblImage.setPixmap(self.pmapImage) self.width = self.pmapImage.width() self.height = self.pmapImage.height() while 1 == 1: if self.width > self.defaultMaxSize[ 0] or self.height > self.defaultMaxSize[1]: self.width *= 0.9 self.height *= 0.9 else: break self.lblImage.resize(int(self.width), int(self.height))
def emendDirectoryWithContents(self): try: _path = self.checkSource(str(QuickMakeParameters[1]), "directory") if _path is not None: if uni.getBoolValue("isShowQuickMakeWindow"): newEmendedName = str(self.leNewValue.text()) else: newEmendedName = Organizer.emend(_path, fu.getObjectType(_path)) fu.activateSmartCheckIcon() oldFileName = _path newDirName = fu.moveOrChange(oldFileName, newEmendedName, "directory") if newDirName != oldFileName: fileAndDirectoryNames = fu.readDirectory(newDirName, "fileAndDirectory") for fileAndDirs in fileAndDirectoryNames: objectType = fu.getObjectType(fu.joinPath(newDirName, fileAndDirs)) fu.moveOrChange(fu.joinPath(newDirName, fileAndDirs), fu.joinPath(newDirName, Organizer.emend(fileAndDirs, objectType)), objectType) if uni.isActiveDirectoryCover and uni.getBoolValue( "isActiveAutoMakeIconToDirectory") and uni.getBoolValue( "isAutoMakeIconToDirectoryWhenFileMove"): fu.checkIcon(newDirName) if fu.isDir(newDirName): fu.completeSmartCheckIcon() Dialogs.show(translate("QuickMake", "Directory And Contents Emended"), str(translate("QuickMake", "\"%s\" is emended based on the criteria you set.This directory is \"%s\" now.")) % (Organizer.getLink(_path), Organizer.getLink(newDirName))) self.close() except: ReportBug.ReportBug()
def save(self): try: codes = Scripts.getScript(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)) Scripts.saveScript(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName), str(self.sciCommand.text())) except: ReportBug.ReportBug()
def refreshTable(self, _path): self.values = [] fileAndDirectoryNames = fu.readDirectory(_path, "fileAndDirectory", uni.getBoolValue("isShowHiddensInFolderTable")) allItemNumber = len(fileAndDirectoryNames) uni.startThreadAction() baseNameOfDirectory = fu.getBaseName(_path) rowNo = 0 self.setRowCount(allItemNumber) for baseName in fileAndDirectoryNames: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(fu.joinPath(_path, baseName), False, True): details = fu.getExtendedDetails(fu.joinPath(_path, baseName)) content = {} content["path"] = fu.joinPath(_path, baseName) content["baseNameOfDirectory"] = baseNameOfDirectory content["baseName"] = baseName content.update(details) self.values.append(content) newBaseNameOfDirectory = Organizer.emend(content["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, content["baseNameOfDirectory"]) newBaseName = Organizer.emend(content["baseName"], fu.getObjectType(self.values[rowNo]["path"])) self.createItem(rowNo, "baseName", newBaseName, content["baseName"]) self.createItem(rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem(rowNo, "lastAccessed", Organizer.getCorrectedTime(content["lastAccessed"])) self.createItem(rowNo, "lastModified", Organizer.getCorrectedTime(content["lastModified"])) self.createItem(rowNo, "lastMetadataChanged", Organizer.getCorrectedTime(content["lastMetadataChanged"])) if not uni.isWindows: self.createItem(rowNo, "accessRights", content["accessRights"]) self.createItem(rowNo, "userIDOfOwner", content["userIDOfOwner"]) self.createItem(rowNo, "groupIDOfOwner", content["groupIDOfOwner"]) self.createItem(rowNo, "numberOfHardLinks", content["numberOfHardLinks"]) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def willDownload(self, _request): try: defaultFileName = str(MFileInfo(str(trStr(_request.url()))).fileName()) fileDialogTitle = translate("UpdateControl", "You Can Click Cancel To Update Without Saving The Package.") if self.isNotInstall: fileDialogTitle = translate("UpdateControl", "Save New Version Of Hamsi Manager") fileName = Dialogs.getSaveFileName(fileDialogTitle, fu.joinPath(fu.getDirName(fu.HamsiManagerDirectory), defaultFileName)) if self.isNotInstall is False or fileName is not None: if fileName is None: import random fileName = fu.joinPath(fu.getTempDir(), defaultFileName[:-7] + "-" + str( random.randrange(0, 1000000)) + defaultFileName[-7:]) self.pbtnDownloadAndInstall.setEnabled(False) newRequest = _request newRequest.setAttribute(MNetworkRequest.User, trQVariant(fileName)) networkManager = self.wvWeb.page().networkAccessManager() reply = networkManager.get(newRequest) self.isFileExist = True self.connect(reply, SIGNAL("downloadProgress(qint64,qint64)"), self.downloading) self.connect(reply, SIGNAL("finished()"), self.downloaded) self.connect(reply, SIGNAL("error(QNetworkReply::NetworkError)"), self.errorOccurred) except: ReportBug.ReportBug()
def uninstallPlugin(self, _pluginName, _isQuiet=False): isUninstalled = False pluginModule = __import__("MyPlugins." + _pluginName, globals(), locals(), ["pluginName", "pluginFiles", "pluginDirectory", "uninstallThisPlugin", "setupDirectory", "pluginVersion"], 0) if pluginModule.uninstallThisPlugin is None: if pluginModule.pluginDirectory == "": for pluginFile in pluginModule.pluginFiles: if fu.isFile(fu.joinPath(pluginModule.setupDirectory, pluginFile)): fu.removeFileOrDir(fu.joinPath(pluginModule.setupDirectory, pluginFile)) isUninstalled = True else: if fu.isDir(fu.joinPath(pluginModule.setupDirectory, pluginModule.pluginDirectory)): fu.removeFileOrDir(fu.joinPath(pluginModule.setupDirectory, pluginModule.pluginDirectory)) isUninstalled = True else: isUninstalled = pluginModule.uninstallThisPlugin() if isUninstalled: Settings.setUniversalSetting(str(pluginModule.pluginName), str("")) if _isQuiet is False: Dialogs.show(translate("MyPlugins", "Plug-in Uninstallation Is Complete"), str(translate("MyPlugins", "\"%s\" is uninstalled on your system.")) % ( pluginModule.pluginName)) elif isUninstalled == "AlreadyUninstalled": if _isQuiet is False: Dialogs.show(translate("MyPlugins", "Plug-in Already Uninstalled"), str(translate("MyPlugins", "\"%s\" already uninstalled on your system.")) % ( pluginModule.pluginName)) else: if _isQuiet is False: Dialogs.showError(translate("MyPlugins", "Plug-in Uninstallation Failed"), str(translate("MyPlugins", "\"%s\" failed to uninstall on your system.")) % ( pluginModule.pluginName))
def getInstalledThemes(): themes = [] for name in fu.readDirectoryAll(fu.joinPath(fu.HamsiManagerDirectory, "Themes")): try: if (name[:1] != "." and name[:2] != "__" and name[-2:] != "__" and fu.isDir(fu.joinPath(fu.HamsiManagerDirectory, "Themes", name))): themes.append(name) except: pass return themes
def getMyPluginsNames(): plugins = [] for name in fu.readDirectoryAll(fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins")): try: if (name[:1] != "." and name[:2] != "__" and name[-2:] != "__" and fu.isDir(fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins", name))): plugins.append(name) except: pass return plugins
def uninstallPlugin(self, _pluginName, _isQuiet=False): isUninstalled = False pluginModule = __import__( "MyPlugins." + _pluginName, globals(), locals(), [ "pluginName", "pluginFiles", "pluginDirectory", "uninstallThisPlugin", "setupDirectory", "pluginVersion" ], 0) if pluginModule.uninstallThisPlugin is None: if pluginModule.pluginDirectory == "": for pluginFile in pluginModule.pluginFiles: if fu.isFile( fu.joinPath(pluginModule.setupDirectory, pluginFile)): fu.removeFileOrDir( fu.joinPath(pluginModule.setupDirectory, pluginFile)) isUninstalled = True else: if fu.isDir( fu.joinPath(pluginModule.setupDirectory, pluginModule.pluginDirectory)): fu.removeFileOrDir( fu.joinPath(pluginModule.setupDirectory, pluginModule.pluginDirectory)) isUninstalled = True else: isUninstalled = pluginModule.uninstallThisPlugin() if isUninstalled: Settings.setUniversalSetting(str(pluginModule.pluginName), str("")) if _isQuiet is False: Dialogs.show( translate("MyPlugins", "Plug-in Uninstallation Is Complete"), str( translate("MyPlugins", "\"%s\" is uninstalled on your system.")) % (pluginModule.pluginName)) elif isUninstalled == "AlreadyUninstalled": if _isQuiet is False: Dialogs.show( translate("MyPlugins", "Plug-in Already Uninstalled"), str( translate( "MyPlugins", "\"%s\" already uninstalled on your system.")) % (pluginModule.pluginName)) else: if _isQuiet is False: Dialogs.showError( translate("MyPlugins", "Plug-in Uninstallation Failed"), str( translate( "MyPlugins", "\"%s\" failed to uninstall on your system.")) % (pluginModule.pluginName))
def checkSettings(): if fu.isDir(fu.pathOfSettingsDirectory) is False: fu.makeDirs(fu.pathOfSettingsDirectory) reFillSettings() reFillDatabases() else: if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) is False: reFillDatabases() if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, uni.fileOfSettings)) is False: reFillSettings() checkDatabases()
def getTaggersMachineNames(): taggers = [] for name in fu.readDirectoryAll(fu.joinPath(fu.HamsiManagerDirectory, "Taggers")): try: moduleName = name.split(".")[0] moduleNameExt = name.split(".")[1] if taggers.count(moduleName) == 0: if (name[:1] != "." and moduleName != "__init__" and ["py", "pyc", "pyd"].count(moduleNameExt) == 1 and fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "Taggers", name))): taggers.append(moduleName) except: pass return taggers
def getInstalledLanguagesNames(): global installedLanguagesNames if installedLanguagesNames is None: languages = [] for name in fu.readDirectoryAll(fu.joinPath(fu.HamsiManagerDirectory, "Languages")): if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "Languages", name)) and name[-3:] == ".qm": langCode = name[-8:-3] if languages.count(str(MQtCore.QLocale.languageToString(MQtCore.QLocale(langCode).language()))) == 0: languages.append(str(MQtCore.QLocale.languageToString(MQtCore.QLocale(langCode).language()))) if languages.count("English") == 0: languages.append("English") installedLanguagesNames = languages return installedLanguagesNames
def getInstalledLanguagesCodes(): global installedLanguagesCodes if installedLanguagesCodes is None: languages = [] for name in fu.readDirectoryAll(fu.joinPath(fu.HamsiManagerDirectory, "Languages")): if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "Languages", name)) and name[-3:] == ".qm": langCode = name[-8:-3] if languages.count(langCode) == 0: languages.append(langCode) if languages.count("en_GB") == 0: languages.append("en_GB") installedLanguagesCodes = languages return installedLanguagesCodes
def getInstalledThemes(): themes = [] for name in fu.readDirectoryAll( fu.joinPath(fu.HamsiManagerDirectory, "Themes")): try: if (name[:1] != "." and name[:2] != "__" and name[-2:] != "__" and fu.isDir( fu.joinPath(fu.HamsiManagerDirectory, "Themes", name))): themes.append(name) except: pass return themes
def getMyPluginsNames(): plugins = [] for name in fu.readDirectoryAll( fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins")): try: if (name[:1] != "." and name[:2] != "__" and name[-2:] != "__" and fu.isDir( fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins", name))): plugins.append(name) except: pass return plugins
def checkSettings(): if fu.isDir(fu.pathOfSettingsDirectory) is False: fu.makeDirs(fu.pathOfSettingsDirectory) reFillSettings() reFillDatabases() else: if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, "database.sqlite")) is False: reFillDatabases() if fu.isFile( fu.joinPath(fu.pathOfSettingsDirectory, uni.fileOfSettings)) is False: reFillSettings() checkDatabases()
def installKDE4Language(_language="tr_TR"): if uni.isAvailableKDE4(): KDELocalateDir = fu.joinPath(uni.getKDE4HomePath(), "share", "locale", str(_language[:2]), "LC_MESSAGES") if uni.isRunningAsRoot(): KDELocalateDir = fu.joinPath("/usr", "share", "locale", str(_language[:2]), "LC_MESSAGES") KDELocalateDir = str(KDELocalateDir) langFile = fu.joinPath(fu.HamsiManagerDirectory, "Languages", "DontTranslate", str(_language), "HamsiManager.mo") if fu.isFile(fu.joinPath(KDELocalateDir, "HamsiManager.mo")) is False: if fu.isFile(langFile): if fu.isDir(KDELocalateDir) is False: fu.makeDirs(KDELocalateDir) fu.copyFileOrDir(langFile, fu.joinPath(KDELocalateDir, "HamsiManager.mo")) return True return False
def changeFile(self, _filePath, _isNew=False): self.fileValues = fu.readTextFile(_filePath, uni.MySettings["fileSystemEncoding"]) self.setWindowTitle(str(fu.getBaseName(self.fileValues["path"]))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.infoLabels["path"] = MLabel(self.labels[0]) self.infoLabels["content"] = MLabel(self.labels[1]) dirPath = fu.getDirName(self.fileValues["path"]) baseName = fu.getBaseName(self.fileValues["path"]) self.infoValues["path"] = MLineEdit(str(fu.joinPath(dirPath, Organizer.emend(baseName, "file")))) self.infoValues["content"] = MPlainTextEdit( str(Organizer.emend(self.fileValues["content"], "text", False, True))) self.infoValues["content"].setLineWrapMode(MPlainTextEdit.NoWrap) self.sourceCharSet = MComboBox() self.sourceCharSet.addItems(uni.getCharSets()) self.sourceCharSet.setCurrentIndex(self.sourceCharSet.findText(uni.MySettings["fileSystemEncoding"])) MObject.connect(self.sourceCharSet, SIGNAL("currentIndexChanged(int)"), self.sourceCharSetChanged) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["path"]) HBOXs[-1].addWidget(self.infoValues["path"]) HBOXs[-1].addWidget(self.sourceCharSet) for hbox in HBOXs: vblClearable.addLayout(hbox) vblClearable.addWidget(self.infoLabels["content"]) vblClearable.addWidget(self.infoValues["content"])
def getFromAmarok(self): try: import Amarok Dialogs.showState(translate("CoverTable", "Checking For Amarok..."), 0, 1) if Amarok.checkAmarok(): from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues() Dialogs.showState(translate("CoverTable", "Values Are Being Processed"), 1, 1) if directoriesAndValues is not None: for rowNo in range(self.rowCount()): if (getMainWindow().checkHiddenColumn("sourceCover") and getMainWindow().checkHiddenColumn("destinationCover")): if self.isChangeableItem(rowNo, "sourceCover"): directoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), str(self.item(rowNo, 0).text()), str(self.item(rowNo, 1).text())) if directoryPath in directoriesAndValues: directoryAndValues = directoriesAndValues[directoryPath] self.item(rowNo, 3).setText( directoryAndValues["coverPath"][0].replace(directoryPath, ".")) self.item(rowNo, 4).setText("./" + Organizer.getIconName( directoryAndValues["artist"][0], directoryAndValues["album"][0], directoryAndValues["genre"][0], directoryAndValues["year"][0])) except: ReportBug.ReportBug()
def checkSize(): setRecordType(1) if fu.isFile(fu.recordFilePath): if fu.getSize(fu.recordFilePath) > (int(uni.MySettings["maxRecordFileSize"]) * 1024): fu.moveFileOrDir(fu.recordFilePath, fu.joinPath(fu.oldRecordsDirectoryPath, str(time.strftime("%Y%m%d_%H%M%S")) + ".txt")) restoreRecordType()
def fillMySettings(_setAgain=False, _isCheckUpdate=True): global MySettings, isShowVerifySettings, changedDefaultValuesKeys, newSettingsKeys, tableType from Core import Settings sets = Settings.setting() currentSettingVersion = trStr(sets.value("settingsVersion")) defaultValues = Settings.getDefaultValues() valueTypesAndValues = Settings.getValueTypesAndValues() for keyValue in Settings.getKeysOfSettings(): value = trStr(sets.value(keyValue, trQVariant(defaultValues[keyValue]))) if keyValue not in MySettings.keys() or _setAgain: MySettings[keyValue] = str( Settings.emendValue(keyValue, value, defaultValues[keyValue], valueTypesAndValues[keyValue])) for keyValue in sets.allKeys(): keyValue = str(keyValue) if keyValue not in MySettings.keys(): value = trStr(sets.value(keyValue, trQVariant(""))) MySettings[keyValue] = str(Settings.emendValue(keyValue, value, "", "str")) newSettingVersion = str(MySettings["settingsVersion"]) if _isCheckUpdate: if str(currentSettingVersion) is not "" and newSettingVersion != currentSettingVersion: newSettingsKeys, changedDefaultValuesKeys = Settings.updateOldSettings(currentSettingVersion, newSettingVersion) isShowVerifySettings = True fu.fileSystemEncoding = MySettings["fileSystemEncoding"] fu.themePath = fu.joinPath(fu.HamsiManagerDirectory, "Themes", MySettings["themeName"]) if tableType is None: tableType = MySettings["tableType"] if tableType not in getTableTypesNames(): tableType = "1" if getBoolValue("isInstalledKDE4Language") is False: from Core import MyConfigure MyConfigure.installKDE4Languages()
def getInstalledLanguagesCodes(): global installedLanguagesCodes if installedLanguagesCodes is None: languages = [] for name in fu.readDirectoryAll( fu.joinPath(fu.HamsiManagerDirectory, "Languages")): if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", name)) and name[-3:] == ".qm": langCode = name[-8:-3] if languages.count(langCode) == 0: languages.append(langCode) if languages.count("en_GB") == 0: languages.append("en_GB") installedLanguagesCodes = languages return installedLanguagesCodes
def getFromScriptList(self, _index=None): try: if self.checkForSave(): self.currentScriptFileName = self.scriptList[self.lwScriptList.currentRow()] codes = Scripts.getScript(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)) self.sciCommand.setText(str(codes)) except: ReportBug.ReportBug()
def getTaggersMachineNames(): taggers = [] for name in fu.readDirectoryAll( fu.joinPath(fu.HamsiManagerDirectory, "Taggers")): try: moduleName = name.split(".")[0] moduleNameExt = name.split(".")[1] if taggers.count(moduleName) == 0: if (name[:1] != "." and moduleName != "__init__" and ["py", "pyc", "pyd"].count(moduleNameExt) == 1 and fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "Taggers", name))): taggers.append(moduleName) except: pass return taggers
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 executeAsRoot(_command=[], _executableName=None): if uni.isRunableAsRoot(): pathOfExecutable = None if _executableName in ["HamsiManager", "HamsiManagerInstaller"]: pathOfExecutable = findExecutablePath(_executableName) if pathOfExecutable is not None: _command = [pathOfExecutable] + _command return execute([fu.joinPath(uni.getLibraryDirectoryPath(), "kde4", "libexec", "kdesu")] + _command) return False
def getNextScriptFilePath(): i = 1 while True: nextScriptFilePath = fu.joinPath( pathOfScripsDirectory, translate("Scripts", "Script") + "-" + str(i) + ".py") if fu.isFile(nextScriptFilePath) is False: return nextScriptFilePath i += 1
def clear(self): try: answer = Dialogs.ask(translate("ScriptManager", "Your Codes Will Be Deleted!.."), translate("ScriptManager", "Your codes will be deleted and the default codes will be installed. Do you wish to clear the current codes?")) if answer == Dialogs.Yes: Scripts.clearScript(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)) except: ReportBug.ReportBug()
def getBuildType(): if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManagerHasBeenBuilt")): firstRow = fu.readLinesFromFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManagerHasBeenBuilt"))[0] if firstRow.find("bdist_rpm") > -1: return "rpm" elif firstRow.find("bdist_msi") > -1: return "msi" elif firstRow.find("bdist") > -1: return "bdist" elif firstRow.find("install_exe") > -1: return "install_exe" elif firstRow.find("install") > -1: return "install" elif firstRow.find("build_exe") > -1: return "build_exe" elif firstRow.find("build") > -1: return "build" return str(None)
def isRunableAsRoot(): try: if fu.isFile(fu.joinPath(getLibraryDirectoryPath(), "kde4", "libexec", "kdesu")): if isRunningAsRoot(): return False return True return False except: return False
def getConfiguredContent(_content, _executeCommandOfHamsiManager=None): if _executeCommandOfHamsiManager is None: from Core import Execute _executeCommandOfHamsiManager = Execute.getExecuteCommandOfHamsiManager() return _content.replace("~InstallationDirectory~", fu.HamsiManagerDirectory).replace( "~ExecuteCommandOfHamsiManager~", _executeCommandOfHamsiManager).replace("~IconPath~", fu.joinPath(fu.themePath, "Images", "hamsi.png")).replace( "~ThemePath~", fu.themePath)
def getKDE4HomePath(): if isAvailableKDE4(): try: if isActivePyKDE4: from PyKDE4.kdecore import KStandardDirs kdedirPath = str(KStandardDirs().localkdedir()) if kdedirPath[-1] == os.sep: kdedirPath = kdedirPath[:-1] else: from Core import Execute kdedirPath = Execute.getCommandResult(["kde4-config", "--localprefix"])[:-2] return kdedirPath except: pass if fu.isDir(fu.joinPath(fu.userDirectoryPath, ".kde4", "share", "config")): return fu.joinPath(fu.userDirectoryPath, ".kde4") else: return fu.joinPath(fu.userDirectoryPath, ".kde")
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 checkSize(): setRecordType(1) if fu.isFile(fu.recordFilePath): if fu.getSize(fu.recordFilePath) > ( int(uni.MySettings["maxRecordFileSize"]) * 1024): fu.moveFileOrDir( fu.recordFilePath, fu.joinPath(fu.oldRecordsDirectoryPath, str(time.strftime("%Y%m%d_%H%M%S")) + ".txt")) restoreRecordType()
def findExecutablePath(_executableName, _isAlertIfNotFound=True): executableBaseName = findExecutableBaseName(_executableName) if executableBaseName is not None: return fu.joinPath(fu.HamsiManagerDirectory, executableBaseName) if _isAlertIfNotFound: from Core import Dialogs Dialogs.showError(translate("Execute", "Cannot Find Executable File"), str(translate("Execute", "\"%s\" : cannot find an executable file matched this name in directory of Hamsi Manager.<br>Please make sure that it exists and retry.")) % _executableName) return None
def isRunableAsRoot(): try: if fu.isFile( fu.joinPath(getLibraryDirectoryPath(), "kde4", "libexec", "kdesu")): if isRunningAsRoot(): return False return True return False except: return False
def getFromRecordList(self, _index=None): try: if self.cbRecordsList.currentIndex() == 0: self.setRecordsFile() else: recordFilePath = self.recordsList[ self.cbRecordsList.currentIndex()] self.setRecordsFile( fu.joinPath(fu.oldRecordsDirectoryPath, recordFilePath)) except: ReportBug.ReportBug()
def checkForSave(self): try: if self.currentScriptFileName is not None: if fu.isFile(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)): codes = Scripts.getScript(fu.joinPath(Scripts.pathOfScripsDirectory, self.currentScriptFileName)) if str(codes) != str(self.sciCommand.text()): if self.cckbIsAutoSaveScripts.checkState() == Mt.Checked: self.save() else: answer = Dialogs.ask(translate("ScriptManager", "Do You Wish To Save Your Codes?"), translate("ScriptManager", "Do you wish to save your codes so that you can continue later?"), True) if answer == Dialogs.Yes: self.save() elif answer == Dialogs.Cancel: return False return True 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 executeAsRoot(_command=[], _executableName=None): if uni.isRunableAsRoot(): pathOfExecutable = None if _executableName in ["HamsiManager", "HamsiManagerInstaller"]: pathOfExecutable = findExecutablePath(_executableName) if pathOfExecutable is not None: _command = [pathOfExecutable] + _command return execute([ fu.joinPath(uni.getLibraryDirectoryPath(), "kde4", "libexec", "kdesu") ] + _command) return False
def uninstallThisPlugin(): isAlreadyuninstalled = True if uni.isRunningAsRoot(): destinationPath = "/usr/share/apps/krusader/" else: destinationPath = uni.getKDE4HomePath() + "/share/apps/krusader/" if fu.isFile(fu.joinPath(destinationPath, "useractions.xml")): import xml.etree.ElementTree as ET doc = ET.parse(fu.joinPath(destinationPath, "useractions.xml")) KrusaderUserActions = doc.getroot() actions = doc.findall("action") for act in doc.findall("action"): if act.get("name").find("hamsimanager") != -1: KrusaderUserActions.remove(act) isAlreadyuninstalled = False actions = doc.findall("action") doc.write(fu.joinPath(destinationPath, "useractions.xml")) if isAlreadyuninstalled: return "AlreadyUninstalled" return True
def getBuildType(): if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "HamsiManagerHasBeenBuilt")): firstRow = fu.readLinesFromFile( fu.joinPath(fu.HamsiManagerDirectory, "HamsiManagerHasBeenBuilt"))[0] if firstRow.find("bdist_rpm") > -1: return "rpm" elif firstRow.find("bdist_msi") > -1: return "msi" elif firstRow.find("bdist") > -1: return "bdist" elif firstRow.find("install_exe") > -1: return "install_exe" elif firstRow.find("install") > -1: return "install" elif firstRow.find("build_exe") > -1: return "build_exe" elif firstRow.find("build") > -1: return "build" return str(None)
def getKDE4HomePath(): if isAvailableKDE4(): try: if isActivePyKDE4: from PyKDE4.kdecore import KStandardDirs kdedirPath = str(KStandardDirs().localkdedir()) if kdedirPath[-1] == os.sep: kdedirPath = kdedirPath[:-1] else: from Core import Execute kdedirPath = Execute.getCommandResult( ["kde4-config", "--localprefix"])[:-2] return kdedirPath except: pass if fu.isDir(fu.joinPath(fu.userDirectoryPath, ".kde4", "share", "config")): return fu.joinPath(fu.userDirectoryPath, ".kde4") else: return fu.joinPath(fu.userDirectoryPath, ".kde")
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 installPlugin(self, _pluginName, _isQuiet=False): isInstalled = False pluginModule = __import__("MyPlugins." + _pluginName, globals(), locals(), ["pluginName", "pluginFiles", "pluginDirectory", "installThisPlugin", "setupDirectory", "pluginVersion"], 0) if pluginModule.installThisPlugin is None: if pluginModule.pluginDirectory == "": try: fu.makeDirs(pluginModule.setupDirectory) except: pass for pluginFile in pluginModule.pluginFiles: fu.copyOrChange(fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins", _pluginName, pluginFile), fu.joinPath(pluginModule.setupDirectory, pluginFile), "file", "only", True) MyConfigure.reConfigureFile(fu.joinPath(pluginModule.setupDirectory, pluginFile)) isInstalled = True else: oldFilePath = fu.joinPath(fu.HamsiManagerDirectory, "MyPlugins", _pluginName, pluginModule.pluginDirectory) newFilePath = fu.copyOrChange(oldFilePath, fu.joinPath(pluginModule.setupDirectory, pluginModule.pluginDirectory), "directory", "only", True) if newFilePath != oldFilePath: isInstalled = True else: isInstalled = pluginModule.installThisPlugin() if isInstalled: Settings.setUniversalSetting(str(pluginModule.pluginName), str(pluginModule.pluginVersion)) if _isQuiet is False: Dialogs.show(translate("MyPlugins", "Plug-in Installation Is Complete"), str(translate("MyPlugins", "\"%s\" is installed on your system.")) % ( pluginModule.pluginName)) elif isInstalled == "AlreadyInstalled": if _isQuiet is False: Dialogs.show(translate("MyPlugins", "Plug-in Already Installed"), str(translate("MyPlugins", "\"%s\" already installed on your system.")) % ( pluginModule.pluginName)) else: if _isQuiet is False: Dialogs.showError(translate("MyPlugins", "Plug-in Installation Failed"), str(translate("MyPlugins", "\"%s\" failed to install on your system.")) % ( pluginModule.pluginName))
def getInstalledLanguagesNames(): global installedLanguagesNames if installedLanguagesNames is None: languages = [] for name in fu.readDirectoryAll( fu.joinPath(fu.HamsiManagerDirectory, "Languages")): if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", name)) and name[-3:] == ".qm": langCode = name[-8:-3] if languages.count( str( MQtCore.QLocale.languageToString( MQtCore.QLocale(langCode).language()))) == 0: languages.append( str( MQtCore.QLocale.languageToString( MQtCore.QLocale(langCode).language()))) if languages.count("English") == 0: languages.append("English") installedLanguagesNames = languages return installedLanguagesNames
def willDownload(self, _request): try: defaultFileName = str( MFileInfo(str(trStr(_request.url()))).fileName()) fileDialogTitle = translate( "UpdateControl", "You Can Click Cancel To Update Without Saving The Package.") if self.isNotInstall: fileDialogTitle = translate( "UpdateControl", "Save New Version Of Hamsi Manager") fileName = Dialogs.getSaveFileName( fileDialogTitle, fu.joinPath(fu.getDirName(fu.HamsiManagerDirectory), defaultFileName)) if self.isNotInstall is False or fileName is not None: if fileName is None: import random fileName = fu.joinPath( fu.getTempDir(), defaultFileName[:-7] + "-" + str(random.randrange(0, 1000000)) + defaultFileName[-7:]) self.pbtnDownloadAndInstall.setEnabled(False) newRequest = _request newRequest.setAttribute(MNetworkRequest.User, trQVariant(fileName)) networkManager = self.wvWeb.page().networkAccessManager() reply = networkManager.get(newRequest) self.isFileExist = True self.connect(reply, SIGNAL("downloadProgress(qint64,qint64)"), self.downloading) self.connect(reply, SIGNAL("finished()"), self.downloaded) self.connect(reply, SIGNAL("error(QNetworkReply::NetworkError)"), self.errorOccurred) except: ReportBug.ReportBug()
def findExecutablePath(_executableName, _isAlertIfNotFound=True): executableBaseName = findExecutableBaseName(_executableName) if executableBaseName is not None: return fu.joinPath(fu.HamsiManagerDirectory, executableBaseName) if _isAlertIfNotFound: from Core import Dialogs Dialogs.showError( translate("Execute", "Cannot Find Executable File"), str( translate( "Execute", "\"%s\" : cannot find an executable file matched this name in directory of Hamsi Manager.<br>Please make sure that it exists and retry." )) % _executableName) return None
def getUserDesktopPath(): desktopPath = None if isActivePyKDE4: from PyKDE4.kdeui import KGlobalSettings desktopPath = str(KGlobalSettings.desktopPath()) elif isAvailableKDE4(): from Core import Execute desktopPath = Execute.getCommandResult( ["kde4-config", "--userpath", "desktop"])[:-2] elif isWindows: from win32com.shell import shell, shellcon desktopPath = shell.SHGetFolderPath(0, shellcon.CSIDL_DESKTOP, 0, 0) else: desktopNames = [str(translate("Variables", "Desktop")), "Desktop"] for dirName in desktopNames: if fu.isDir(fu.joinPath(fu.userDirectoryPath, dirName)): desktopPath = fu.joinPath(fu.userDirectoryPath, dirName) break else: desktopPath = fu.userDirectoryPath return desktopPath
def writeMusicFile(_oldMusicTagsValues, _newMusicTagsValues, _isImageAction=False, _ImageType=False, _ImagePath=False, _imageDescription=u""): if fu.isWritableFileOrDir(_oldMusicTagsValues["path"]): baseNameOfDirectory = _oldMusicTagsValues["baseNameOfDirectory"] baseName = _oldMusicTagsValues["baseName"] tagger = Taggers.getTagger() tagger.loadFileForWrite(_oldMusicTagsValues["path"]) if _isImageAction is False: if _newMusicTagsValues["artist"] != _oldMusicTagsValues["artist"]: tagger.setArtist(str(_newMusicTagsValues["artist"])) if _newMusicTagsValues["title"] != _oldMusicTagsValues["title"]: tagger.setTitle(str(_newMusicTagsValues["title"])) if _newMusicTagsValues["album"] != _oldMusicTagsValues["album"]: tagger.setAlbum(str(_newMusicTagsValues["album"])) if _newMusicTagsValues["albumArtist"] != _oldMusicTagsValues["albumArtist"]: tagger.setAlbumArtist(str(_newMusicTagsValues["albumArtist"])) if _newMusicTagsValues["trackNum"] != _oldMusicTagsValues["trackNum"]: tagger.setTrackNum(_newMusicTagsValues["trackNum"]) if _newMusicTagsValues["year"] != _oldMusicTagsValues["year"]: tagger.setDate(str(_newMusicTagsValues["year"])) if _newMusicTagsValues["genre"] != _oldMusicTagsValues["genre"]: tagger.setGenre(str(_newMusicTagsValues["genre"])) if _newMusicTagsValues["firstComment"] != _oldMusicTagsValues["firstComment"]: tagger.setFirstComment(str(_newMusicTagsValues["firstComment"])) if _newMusicTagsValues["firstLyrics"] != _oldMusicTagsValues["firstLyrics"]: tagger.setFirstLyrics(str(_newMusicTagsValues["firstLyrics"])) tagger.update() if _newMusicTagsValues["baseNameOfDirectory"] != _oldMusicTagsValues["baseNameOfDirectory"]: baseNameOfDirectory = str(_newMusicTagsValues["baseNameOfDirectory"]) if _newMusicTagsValues["baseName"] != _oldMusicTagsValues["baseName"]: baseName = str(_newMusicTagsValues["baseName"]) newFilePath = fu.joinPath(fu.getDirName(fu.getDirName(_oldMusicTagsValues["path"])), baseNameOfDirectory, baseName) if fu.getRealPath(_oldMusicTagsValues["path"]) != fu.getRealPath(newFilePath): return fu.moveOrChange(_oldMusicTagsValues["path"], newFilePath, fu.getObjectType(_oldMusicTagsValues["path"])) #Making changes on image files else: if _ImagePath is False: tagger.removeImage(_imageDescription) else: tagger.addImage(_ImageType, _ImagePath, _imageDescription) tagger.update() return None return _oldMusicTagsValues["path"]