def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName(translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName(translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show(translate("MenuBar", "Current State Saved"), translate("MenuBar", "Current state saved with preferences.<br>You can continue where you left off.")) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread(["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show(translate("ToolsBar", "Directory Icon Checked"), translate("ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed.")) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask(translate("ToolsBar", "Empty Directories Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow().FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show(translate("ToolsBar", "Directory Cleaned"), translate("ToolsBar", "The current directory is cleaned based on the criteria you set.")) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher([getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask(translate("ToolsBar", "All Files Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles(getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show(translate("ToolsBar", "Removed Only All Files"), str(translate("ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile(fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()
def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName( translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName( translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show( translate("MenuBar", "Current State Saved"), translate( "MenuBar", "Current state saved with preferences.<br>You can continue where you left off." )) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread( ["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show( translate("ToolsBar", "Directory Icon Checked"), translate( "ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed." )) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask( translate("ToolsBar", "Empty Directories Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?" )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow( ).FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show( translate("ToolsBar", "Directory Cleaned"), translate( "ToolsBar", "The current directory is cleaned based on the criteria you set." )) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher( [getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask( translate("ToolsBar", "All Files Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles( getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show( translate("ToolsBar", "Removed Only All Files"), str( translate( "ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile( fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()
self.close() except: from Core import ReportBug ReportBug.ReportBug() if uni.isRunningAsRoot() is False and uni.isRunableAsRoot(): answer = Dialogs.askSpecial( translate("Uninstall", "Are You Want To Run As Root?"), translate( "Uninstall", "Hamsi Manager Uninstaller is running with user privileges.<br>Do you want to run Hamsi Manager Uninstaller with root rights?" ), translate("Uninstall", "Yes"), translate("Uninstall", "No (Continue as is)"), None) if answer == translate("Uninstall", "Yes"): NewApp = Execute.executeAsRootWithThread([], "HamsiManagerUninstaller") sys.exit() try: MainWidget = Main() MainWidget.setWindowTitle( translate("Uninstall", "Hamsi Manager Uninstaller") + " " + uni.version) MainWidget.setGeometry(300, 300, 650, 350) MainWidget.show() uni.isStartingSuccessfully = True except: from Core import ReportBug ReportBug.ReportBug() sys.exit(HamsiManagerApp.exec_()) else:
fileContent = MyConfigure.getConfiguredDesktopFileContent(self.installationDirectory) fu.writeToFile(fu.joinPath(fu.userDirectoryPath, ".local", "applications", "HamsiManager.desktop"), fileContent) self.isInstallFinished = True self.close() except: from Core import ReportBug ReportBug.ReportBug() if uni.isRunningAsRoot() is False and uni.isRunableAsRoot(): answer = Dialogs.askSpecial(translate("Install", "Are You Want To Run As Root?"), translate("Install", "Hamsi Manager Installer is running with user privileges.<br>Do you want to run Hamsi Manager installer with root rights?<br><b>Note: </b>The other users on your system has to inherit these permissions and install the program to a location other than their /home directories."), translate("Install", "Yes"), translate("Install", "No (Continue as is)"), None) if answer == translate("Install", "Yes"): NewApp = Execute.executeAsRootWithThread([], "HamsiManagerInstaller") sys.exit() try: MainWidget = Main() MainWidget.setWindowTitle(translate("Install", "Hamsi Manager Installer") + " " + uni.version) MainWidget.setGeometry(300, 300, 650, 350) MainWidget.show() uni.isStartingSuccessfully = True except: from Core import ReportBug ReportBug.ReportBug() sys.exit(HamsiManagerApp.exec_()) else: sys.exit()
def checkCommandLineOptions(): global isQuickMake, QuickMakeParameters, myArgvs, parser, optionList myArgvs = sys.argv isDontRun = False optionList = [] parser = OptionParser( usage="%prog [options] [<arg1>...]", version="HamsiManager " + uni.version, epilog="""\ Copyright (c) 2010 - 2015 Murat Demir <*****@*****.**> , HamsiManager is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.""") parser.add_option('-d', '--debug', help='Enable debugging output. ' 'Chatty', action='store_const', const=logging.DEBUG, dest='loggingLevel') optionList.append("d") optionList.append("debug") parser.add_option('-v', '--verbose', help='Enable informative output', action='store_const', const=logging.INFO, dest='loggingLevel') optionList.append("v") optionList.append("verbose") parser.add_option('--directory', help='The current directory path. ' 'Example : /home/yourname/someDirectory ') optionList.append("directory <directory>") parser.add_option('-s', '--sFileName', help='The setting file name(or path). ' '"The settings directory path" + "/" + "YourEnteredName" ' 'Example : enteredName.ini ') optionList.append("s <settingFile>") optionList.append("sFileName <settingFile>") parser.add_option('--sDirectoryPath', help='The settings directory path. ' 'Example : /home/yourname/.HamsiApps/HamsiManager ') optionList.append("sDirectoryPath <settingDirectory>") parser.add_option('-t', '--tableType', help='Table Type Name. ' 'Example : "0" for Folder Table ' 'Example : "1" for File Table ' 'Example : "2" for Music Table ' 'Example : "3" for Subfolder Table ' 'Example : "4" for Cover Table ') optionList.append("t <tableTypeNo>") optionList.append("tableType <tableTypeNo>") parser.add_option('-f', '--fileReNamerType', help='File Renamer Type. ' 'Example : "Personal Computer" ' 'Example : "Web Server" ' 'Example : "Removable Media" ') optionList.append("f <fileReNamerTypeNo>") optionList.append("fileReNamerType <fileReNamerTypeNo>") qmgroup = OptionGroup(parser, "Quick Make Options", "You can make quickly what are you want.") qmgroup.add_option('--qmw', help='Are you want to show Quick Make Window. ' 'Example : "1" or "True" for Yes ' 'Example : "0" or "False" for No ') optionList.append("qmw <o>") qmgroup.add_option('--qm', help='Are you want to run Quick Make by some parameters?', action='store_const', const=True) optionList.append("qm") qmgroup.add_option('--configurator', help='Open Hamsi Manager Configurator', action='store_const', const=True) optionList.append("configurator") qmgroup.add_option('--plugins', help='Show plugins', action='store_const', const=True) optionList.append("plugins") qmgroup.add_option('--pack', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("pack <directory>") qmgroup.add_option('--hash', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("hash <file>") qmgroup.add_option('--checkIcon', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("checkIcon <directory>") qmgroup.add_option('--clearEmptyDirectories', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearEmptyDirectories <directory>") qmgroup.add_option('--clearUnneededs', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearUnneededs <directory>") qmgroup.add_option('--clearIgnoreds', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearIgnoreds <directory>") qmgroup.add_option('--emendFile', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("emendFile <file>") qmgroup.add_option('--emendDirectory', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("emendDirectory <directory>") qmgroup.add_option('--emendDirectoryWithContents', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("emendDirectoryWithContents <directory>") qmgroup.add_option('--copyPath', help='The file/directory path. ' 'Example : /home/yourname/somePath') optionList.append("copyPath <fileOrDirectory>") qmgroup.add_option('--fileTree', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("fileTree <directory>") qmgroup.add_option('--removeOnlySubFiles', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("removeOnlySubFiles <directory>") qmgroup.add_option('--clear', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clear <directory>") qmgroup.add_option('--textCorrector', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("textCorrector <file>") qmgroup.add_option('--search', help='The file/directory path. ' 'Example : /home/yourname/somePath') optionList.append("search <fileOrDirectory>") dgroup = OptionGroup(parser, "Dangerous Options", "Caution: use these options at your own risk. " "It is believed that some of them bite.") dgroup.add_option('--runAsRoot', help='Are you want to run as root?', action='store_const', const=True) optionList.append("runAsRoot") optionList.append("+[optionalFileOrDirectory]") parser.add_option_group(qmgroup) parser.add_option_group(dgroup) parser.set_defaults(loggingLevel=logging.WARNING, runAsRoot=False, qm=False, plugins=False) options, remainderParameters = parser.parse_args() if len(remainderParameters) == 1: try: uni.setMySetting("lastDirectory", uni.trDecode(str(remainderParameters[0]), fu.defaultFileSystemEncoding)) except: uni.setMySetting("lastDirectory", str(remainderParameters[0])) if options.directory: try: uni.setMySetting("lastDirectory", uni.trDecode(str(options.directory), fu.defaultFileSystemEncoding)) except: uni.setMySetting("lastDirectory", str(options.directory)) if options.loggingLevel: uni.loggingLevel = options.loggingLevel if options.sFileName: uni.fileOfSettings = options.sFileName if options.sDirectoryPath: uni.setPathOfSettingsDirectory(options.sDirectoryPath) if options.tableType: import Tables uni.setMySetting("tableType", Tables.Tables.getThisTableType(options.tableType)) if options.fileReNamerType: uni.setMySetting("fileReNamerType", options.fileReNamerType) if options.qm: if options.qmw: if options.qmw.lower() == "false" or options.qmw == "0": uni.setMySetting("isShowQuickMakeWindow", False) else: uni.setMySetting("isShowQuickMakeWindow", True) if options.configurator: QuickMakeParameters.append("configurator") isQuickMake = True elif options.plugins: QuickMakeParameters.append("plugins") isQuickMake = True elif options.pack: QuickMakeParameters.append("pack") QuickMakeParameters.append(options.pack) isQuickMake = True elif options.hash: QuickMakeParameters.append("hash") QuickMakeParameters.append(options.hash) isQuickMake = True elif options.checkIcon: QuickMakeParameters.append("checkIcon") QuickMakeParameters.append(options.checkIcon) isQuickMake = True elif options.clearEmptyDirectories: QuickMakeParameters.append("clearEmptyDirectories") QuickMakeParameters.append(options.clearEmptyDirectories) isQuickMake = True elif options.clearUnneededs: QuickMakeParameters.append("clearUnneededs") QuickMakeParameters.append(options.clearUnneededs) isQuickMake = True elif options.clearIgnoreds: QuickMakeParameters.append("clearIgnoreds") QuickMakeParameters.append(options.clearIgnoreds) isQuickMake = True elif options.emendFile: QuickMakeParameters.append("emendFile") QuickMakeParameters.append(options.emendFile) isQuickMake = True elif options.emendDirectory: QuickMakeParameters.append("emendDirectory") QuickMakeParameters.append(options.emendDirectory) isQuickMake = True elif options.emendDirectoryWithContents: QuickMakeParameters.append("emendDirectoryWithContents") QuickMakeParameters.append(options.emendDirectoryWithContents) isQuickMake = True elif options.copyPath: QuickMakeParameters.append("copyPath") QuickMakeParameters.append(options.copyPath) isQuickMake = True elif options.fileTree: QuickMakeParameters.append("fileTree") QuickMakeParameters.append(options.fileTree) isQuickMake = True elif options.removeOnlySubFiles: QuickMakeParameters.append("removeOnlySubFiles") QuickMakeParameters.append(options.removeOnlySubFiles) isQuickMake = True elif options.clear: QuickMakeParameters.append("clear") QuickMakeParameters.append(options.clear) isQuickMake = True elif options.textCorrector: QuickMakeParameters.append("textCorrector") QuickMakeParameters.append(options.textCorrector) isQuickMake = True elif options.search: QuickMakeParameters.append("search") QuickMakeParameters.append(options.search) isQuickMake = True QuickMakeParameters.append(remainderParameters) if options.runAsRoot: from Core import Execute if uni.isRunningAsRoot() is False: strArgvs = [] for tempArg in sys.argv: if (tempArg.find("-runAsRoot") == -1 and tempArg.find(Execute.findExecutablePath("HamsiManager")) == -1 and tempArg != "./" + Execute.findExecutableBaseName("HamsiManager") and tempArg != Execute.findExecutableBaseName("HamsiManager")): strArgvs.append(tempArg) if Execute.executeAsRootWithThread(strArgvs, "HamsiManager"): isDontRun = True if isDontRun: return False return True
def checkCommandLineOptions(): global isQuickMake, QuickMakeParameters, myArgvs, parser, optionList myArgvs = sys.argv isDontRun = False optionList = [] parser = OptionParser(usage="%prog [options] [<arg1>...]", version="HamsiManager " + uni.version, epilog="""\ Copyright (c) 2010 - 2015 Murat Demir <*****@*****.**> , HamsiManager is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.""") parser.add_option('-d', '--debug', help='Enable debugging output. ' 'Chatty', action='store_const', const=logging.DEBUG, dest='loggingLevel') optionList.append("d") optionList.append("debug") parser.add_option('-v', '--verbose', help='Enable informative output', action='store_const', const=logging.INFO, dest='loggingLevel') optionList.append("v") optionList.append("verbose") parser.add_option('--directory', help='The current directory path. ' 'Example : /home/yourname/someDirectory ') optionList.append("directory <directory>") parser.add_option( '-s', '--sFileName', help='The setting file name(or path). ' '"The settings directory path" + "/" + "YourEnteredName" ' 'Example : enteredName.ini ') optionList.append("s <settingFile>") optionList.append("sFileName <settingFile>") parser.add_option('--sDirectoryPath', help='The settings directory path. ' 'Example : /home/yourname/.HamsiApps/HamsiManager ') optionList.append("sDirectoryPath <settingDirectory>") parser.add_option('-t', '--tableType', help='Table Type Name. ' 'Example : "0" for Folder Table ' 'Example : "1" for File Table ' 'Example : "2" for Music Table ' 'Example : "3" for Subfolder Table ' 'Example : "4" for Cover Table ') optionList.append("t <tableTypeNo>") optionList.append("tableType <tableTypeNo>") parser.add_option('-f', '--fileReNamerType', help='File Renamer Type. ' 'Example : "Personal Computer" ' 'Example : "Web Server" ' 'Example : "Removable Media" ') optionList.append("f <fileReNamerTypeNo>") optionList.append("fileReNamerType <fileReNamerTypeNo>") qmgroup = OptionGroup(parser, "Quick Make Options", "You can make quickly what are you want.") qmgroup.add_option('--qmw', help='Are you want to show Quick Make Window. ' 'Example : "1" or "True" for Yes ' 'Example : "0" or "False" for No ') optionList.append("qmw <o>") qmgroup.add_option( '--qm', help='Are you want to run Quick Make by some parameters?', action='store_const', const=True) optionList.append("qm") qmgroup.add_option('--configurator', help='Open Hamsi Manager Configurator', action='store_const', const=True) optionList.append("configurator") qmgroup.add_option('--plugins', help='Show plugins', action='store_const', const=True) optionList.append("plugins") qmgroup.add_option('--pack', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("pack <directory>") qmgroup.add_option('--hash', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("hash <file>") qmgroup.add_option('--checkIcon', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("checkIcon <directory>") qmgroup.add_option('--clearEmptyDirectories', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearEmptyDirectories <directory>") qmgroup.add_option('--clearUnneededs', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearUnneededs <directory>") qmgroup.add_option('--clearIgnoreds', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clearIgnoreds <directory>") qmgroup.add_option('--emendFile', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("emendFile <file>") qmgroup.add_option('--emendDirectory', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("emendDirectory <directory>") qmgroup.add_option('--emendDirectoryWithContents', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("emendDirectoryWithContents <directory>") qmgroup.add_option('--copyPath', help='The file/directory path. ' 'Example : /home/yourname/somePath') optionList.append("copyPath <fileOrDirectory>") qmgroup.add_option('--fileTree', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("fileTree <directory>") qmgroup.add_option('--removeOnlySubFiles', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("removeOnlySubFiles <directory>") qmgroup.add_option('--clear', help='The directory path. ' 'Example : /home/yourname/someDirectory') optionList.append("clear <directory>") qmgroup.add_option('--textCorrector', help='The file path. ' 'Example : /home/yourname/someFile') optionList.append("textCorrector <file>") qmgroup.add_option('--search', help='The file/directory path. ' 'Example : /home/yourname/somePath') optionList.append("search <fileOrDirectory>") dgroup = OptionGroup( parser, "Dangerous Options", "Caution: use these options at your own risk. " "It is believed that some of them bite.") dgroup.add_option('--runAsRoot', help='Are you want to run as root?', action='store_const', const=True) optionList.append("runAsRoot") optionList.append("+[optionalFileOrDirectory]") parser.add_option_group(qmgroup) parser.add_option_group(dgroup) parser.set_defaults(loggingLevel=logging.WARNING, runAsRoot=False, qm=False, plugins=False) options, remainderParameters = parser.parse_args() if len(remainderParameters) == 1: try: uni.setMySetting( "lastDirectory", uni.trDecode(str(remainderParameters[0]), fu.defaultFileSystemEncoding)) except: uni.setMySetting("lastDirectory", str(remainderParameters[0])) if options.directory: try: uni.setMySetting( "lastDirectory", uni.trDecode(str(options.directory), fu.defaultFileSystemEncoding)) except: uni.setMySetting("lastDirectory", str(options.directory)) if options.loggingLevel: uni.loggingLevel = options.loggingLevel if options.sFileName: uni.fileOfSettings = options.sFileName if options.sDirectoryPath: uni.setPathOfSettingsDirectory(options.sDirectoryPath) if options.tableType: import Tables uni.setMySetting("tableType", Tables.Tables.getThisTableType(options.tableType)) if options.fileReNamerType: uni.setMySetting("fileReNamerType", options.fileReNamerType) if options.qm: if options.qmw: if options.qmw.lower() == "false" or options.qmw == "0": uni.setMySetting("isShowQuickMakeWindow", False) else: uni.setMySetting("isShowQuickMakeWindow", True) if options.configurator: QuickMakeParameters.append("configurator") isQuickMake = True elif options.plugins: QuickMakeParameters.append("plugins") isQuickMake = True elif options.pack: QuickMakeParameters.append("pack") QuickMakeParameters.append(options.pack) isQuickMake = True elif options.hash: QuickMakeParameters.append("hash") QuickMakeParameters.append(options.hash) isQuickMake = True elif options.checkIcon: QuickMakeParameters.append("checkIcon") QuickMakeParameters.append(options.checkIcon) isQuickMake = True elif options.clearEmptyDirectories: QuickMakeParameters.append("clearEmptyDirectories") QuickMakeParameters.append(options.clearEmptyDirectories) isQuickMake = True elif options.clearUnneededs: QuickMakeParameters.append("clearUnneededs") QuickMakeParameters.append(options.clearUnneededs) isQuickMake = True elif options.clearIgnoreds: QuickMakeParameters.append("clearIgnoreds") QuickMakeParameters.append(options.clearIgnoreds) isQuickMake = True elif options.emendFile: QuickMakeParameters.append("emendFile") QuickMakeParameters.append(options.emendFile) isQuickMake = True elif options.emendDirectory: QuickMakeParameters.append("emendDirectory") QuickMakeParameters.append(options.emendDirectory) isQuickMake = True elif options.emendDirectoryWithContents: QuickMakeParameters.append("emendDirectoryWithContents") QuickMakeParameters.append(options.emendDirectoryWithContents) isQuickMake = True elif options.copyPath: QuickMakeParameters.append("copyPath") QuickMakeParameters.append(options.copyPath) isQuickMake = True elif options.fileTree: QuickMakeParameters.append("fileTree") QuickMakeParameters.append(options.fileTree) isQuickMake = True elif options.removeOnlySubFiles: QuickMakeParameters.append("removeOnlySubFiles") QuickMakeParameters.append(options.removeOnlySubFiles) isQuickMake = True elif options.clear: QuickMakeParameters.append("clear") QuickMakeParameters.append(options.clear) isQuickMake = True elif options.textCorrector: QuickMakeParameters.append("textCorrector") QuickMakeParameters.append(options.textCorrector) isQuickMake = True elif options.search: QuickMakeParameters.append("search") QuickMakeParameters.append(options.search) isQuickMake = True QuickMakeParameters.append(remainderParameters) if options.runAsRoot: from Core import Execute if uni.isRunningAsRoot() is False: strArgvs = [] for tempArg in sys.argv: if (tempArg.find("-runAsRoot") == -1 and tempArg.find( Execute.findExecutablePath("HamsiManager")) == -1 and tempArg != "./" + Execute.findExecutableBaseName("HamsiManager") and tempArg != Execute.findExecutableBaseName("HamsiManager")): strArgvs.append(tempArg) if Execute.executeAsRootWithThread(strArgvs, "HamsiManager"): isDontRun = True if isDontRun: return False return True