def getProcessCommand(self, directory, customBrowser=None): """ This method gets process command. :param directory: Directory to explore. ( String ) :param customBrowser: Custom browser. ( String ) :return: Process command. ( String ) """ processCommand = None directory = os.path.normpath(directory) if platform.system() == "Windows" or platform.system() == "Microsoft": if customBrowser: processCommand = "\"{0}\" \"{1}\"".format( customBrowser, directory) else: processCommand = "explorer.exe \"{0}\"".format(directory) elif platform.system() == "Darwin": if customBrowser: processCommand = "open -a \"{0}\" \"{1}\"".format( customBrowser, directory) else: processCommand = "open \"{0}\"".format(directory) elif platform.system() == "Linux": if customBrowser: processCommand = "\"{0}\" \"{1}\"".format( customBrowser, directory) else: environmentVariable = Environment("PATH") paths = environmentVariable.getValue().split(":") browserFound = False for browser in self.__linuxBrowsers: if browserFound: break try: for path in paths: if foundations.common.pathExists( os.path.join(path, browser)): processCommand = "\"{0}\" \"{1}\"".format( browser, directory) browserFound = True raise StopIteration except StopIteration: pass if not browserFound: raise Exception( "{0} | Exception raised: No suitable Linux browser found!" .format(self.__class__.__name__)) return processCommand
def getProcessCommand(self, directory, customBrowser=None): """ Gets process command. :param directory: Directory to explore. :type directory: unicode :param customBrowser: Custom browser. :type customBrowser: unicode :return: Process command. :rtype: unicode """ processCommand = None directory = os.path.normpath(directory) if platform.system() == "Windows" or platform.system() == "Microsoft": if customBrowser: processCommand = "\"{0}\" \"{1}\"".format(customBrowser, directory) else: processCommand = "explorer.exe \"{0}\"".format(directory) elif platform.system() == "Darwin": if customBrowser: processCommand = "open -a \"{0}\" \"{1}\"".format(customBrowser, directory) else: processCommand = "open \"{0}\"".format(directory) elif platform.system() == "Linux": if customBrowser: processCommand = "\"{0}\" \"{1}\"".format(customBrowser, directory) else: environmentVariable = Environment("PATH") paths = environmentVariable.getValue().split(":") browserFound = False for browser in self.__linuxBrowsers: if browserFound: break try: for path in paths: if foundations.common.pathExists(os.path.join(path, browser)): processCommand = "\"{0}\" \"{1}\"".format(browser, directory) browserFound = True raise StopIteration except StopIteration: pass if not browserFound: raise Exception("{0} | Exception raised: No suitable Linux browser found!".format( self.__class__.__name__)) return processCommand
def exploreDirectory(self, directory): """ Provides directory exploring capability. :param directory: Folder to explore. :type directory: str :return: Method success. :rtype: bool """ browserCommand = None directory = os.path.normpath(directory) if platform.system() == "Windows" or platform.system() == "Microsoft": LOGGER.info("{0} | Launching 'explorer.exe' with '{1}'.".format(self.__class__.__name__, directory)) browserCommand = "explorer.exe \"{0}\"".format(directory) elif platform.system() == "Darwin": LOGGER.info("{0} | Launching 'Finder' with '{1}'.".format(self.__class__.__name__, directory)) browserCommand = "open \"{0}\"".format(directory) elif platform.system() == "Linux": environmentVariable = Environment("PATH") paths = environmentVariable.getValue().split(":") browserFound = False for browser in self.__linuxBrowsers: if not browserFound: try: for path in paths: if os.path.exists(os.path.join(path, browser)): LOGGER.info("{0} | Launching '{1}' file browser with '{1}'.".format(self.__class__.__name__, browser, directory)) browserCommand = "\"{0}\" \"{1}\"".format(browser, directory) browserFound = True raise StopIteration except StopIteration: pass else: break if browserCommand: LOGGER.debug("> Current browser command: '{0}'.".format(browserCommand)) browserProcess = QProcess() browserProcess.startDetached(browserCommand) return True
def editFile(self, file): """ Provides editing capability. :param file: File to edit. :type file: str :return: Method success. :rtype: bool """ editCommand = None file = os.path.normpath(file) if platform.system() == "Windows" or platform.system() == "Microsoft": LOGGER.info("{0} | Launching 'notepad.exe' with '{1}'.".format(self.__class__.__name__, file)) editCommand = "notepad.exe \"{0}\"".format(file) elif platform.system() == "Darwin": LOGGER.info("{0} | Launching default text editor with '{1}'.".format(self.__class__.__name__, file)) editCommand = "open -e \"{0}\"".format(file) elif platform.system() == "Linux": environmentVariable = Environment("PATH") paths = environmentVariable.getValue().split(":") editorFound = False for editor in self.__linuxTextEditors: if not editorFound: try: for path in paths: if os.path.exists(os.path.join(path, editor)): LOGGER.info("{0} | Launching '{1}' text editor with '{2}'.".format(self.__class__.__name__, editor, file)) editCommand = "\"{0}\" \"{1}\"".format(editor, file) editorFound = True raise StopIteration except StopIteration: pass else: break if editCommand: LOGGER.debug("> Current edit command: '{0}'.".format(editCommand)) editProcess = QProcess() editProcess.startDetached(editCommand) return True