示例#1
0
	def exploreProvidedFolder( self, folder ) :
		'''
		This Method Provides Folder Exploring Capability.

		@param folder: Folder To Explore. ( String )
		'''

		browserCommand = None
		customFileBrowser = str( self.ui.Custom_File_Browser_Path_lineEdit.text() )

		folder = os.path.normpath( folder )
		if platform.system() == "Windows" or platform.system() == "Microsoft":
			if customFileBrowser :
				LOGGER.info( "{0} | Launching '{1}' Custom File Browser With '{2}'.".format( self.__class__.__name__, os.path.basename( customFileBrowser ), folder ) )
				browserCommand = "\"{0}\" \"{1}\"".format( customFileBrowser, folder )
			else:
				LOGGER.info( "{0} | Launching 'explorer.exe' With '{1}'.".format( self.__class__.__name__, folder ) )
				browserCommand = "explorer.exe \"{0}\"".format( folder )
		elif platform.system() == "Darwin" :
			if customFileBrowser :
				LOGGER.info( "{0} | Launching '{1}' Custom File Browser With '{2}'.".format( self.__class__.__name__, os.path.basename( customFileBrowser ), folder ) )
				browserCommand = "open -a \"{0}\" \"{1}\"".format( customFileBrowser, folder )
			else:
				LOGGER.info( "{0} | Launching 'Finder' With '{1}'.".format( self.__class__.__name__, folder ) )
				browserCommand = "open \"{0}\"".format( folder )
		elif platform.system() == "Linux":
			if customFileBrowser :
				LOGGER.info( "{0} | Launching '{1}' Custom File Browser With '{2}'.".format( self.__class__.__name__, os.path.basename( customFileBrowser ), folder ) )
				browserCommand = "\"{0}\" \"{1}\"".format( customFileBrowser, folder )
			else :
				environmentVariable = Environment( "PATH" )
				paths = environmentVariable.getPath().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 '{2}'.".format( self.__class__.__name__, browser, folder ) )
									browserCommand = "\"{0}\" \"{1}\"".format( browser, folder )
									browserFound = True
									raise StopIteration
						except StopIteration:
							pass
					else :
						break

		if browserCommand :
			LOGGER.debug( "> Current Browser Command : '{0}'.".format( browserCommand ) )
			browserProcess = QProcess()
			browserProcess.startDetached( browserCommand )
		else :
			messageBox.messageBox( "Warning", "Warning", "{0} | Please Define A Browser Executable In The Preferences !".format( self.__class__.__name__ ) )
示例#2
0
	def editProvidedfile( self, file ):
		'''
		This Method Provides Editing Capability.

		@param file: File To Edit. ( String )
		'''

		editCommand = None
		customTextEditor = str( self.ui.Custom_Text_Editor_Path_lineEdit.text() )

		file = os.path.normpath( file )
		if platform.system() == "Windows" or platform.system() == "Microsoft":
			if customTextEditor :
				LOGGER.info( "{0} | Launching '{1}' Custom Text Editor With '{2}'.".format( self.__class__.__name__, os.path.basename( customTextEditor ), file ) )
				editCommand = "\"{0}\" \"{1}\"".format( customTextEditor, file )
			else:
				LOGGER.info( "{0} | Launching 'notepad.exe' With '{1}'.".format( self.__class__.__name__, file ) )
				editCommand = "notepad.exe \"{0}\"".format( file )
		elif platform.system() == "Darwin" :
			if customTextEditor :
				LOGGER.info( "{0} | Launching '{1}' Custom Text Editor With '{2}'.".format( self.__class__.__name__, os.path.basename( customTextEditor ), file ) )
				editCommand = "open -a \"{0}\" \"{1}\"".format( customTextEditor, file )
			else:
				LOGGER.info( "{0} | Launching Default Text Editor With '{1}'.".format( self.__class__.__name__, file ) )
				editCommand = "open -e \"{0}\"".format( file )
		elif platform.system() == "Linux":
			if customTextEditor :
				LOGGER.info( "{0} | Launching '{1}' Custom Text Editor With '{2}'.".format( self.__class__.__name__, os.path.basename( customTextEditor ), file ) )
				editCommand = "\"{0}\" \"{1}\"".format( customTextEditor, file )
			else :
				environmentVariable = Environment( "PATH" )
				paths = environmentVariable.getPath().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 )
		else :
			messageBox.messageBox( "Warning", "Warning", "{0} | Please Define A Text Editor Executable In The Preferences !".format( self.__class__.__name__ ) )
    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
示例#4
0
	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
示例#5
0
	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 testSetValue(self):
        """
		This method tests :meth:`foundations.environment.Environment.setValue` method.
		"""

        environment = Environment()
        self.assertTrue(environment.setValue("JANE", "DOE"))
        self.assertIn("JANE", os.environ)
        self.assertEqual(environment.getValue("JANE"), "DOE")
    def testGetValue(self):
        """
		This method tests :meth:`foundations.environment.Environment.getValue` method.
		"""

        if platform.system() == "Windows" or platform.system() == "Microsoft":
            environment = Environment("APPDATA")
        elif platform.system() == "Darwin":
            environment = Environment("HOME")
        elif platform.system() == "Linux":
            environment = Environment("HOME")
        self.assertTrue(environment.getValue())
        self.assertIsInstance(environment.getValue(), str)
        environment.setValues(JOHN="DOE")
        self.assertEqual(environment.getValue("JOHN"), "DOE")
        self.assertFalse(
            environment.getValue(
                "JOHNDOE_IS_FOR_SURE_A_NON_EXISTING_SYSTEM_ENVIRONMENT_VARIABLE"
            ))
示例#8
0
	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
    def testSetValues(self):
        """
		This method tests :meth:`foundations.environment.Environment.setValues` method.
		"""

        environment = Environment()
        self.assertTrue(environment.setValues(JOHN="DOE"))
        self.assertIn("JOHN", os.environ)
        self.assertTrue(environment.setValues(JOHN="EOD", DOE="JOHN"))
        self.assertIn("DOE", os.environ)
        self.assertEqual(environment.getValues()["JOHN"], "EOD")
    def testGetValues(self):
        """
		This method tests :meth:`foundations.environment.Environment.getValues` method.
		"""

        if platform.system() == "Windows" or platform.system() == "Microsoft":
            variable = "APPDATA"
        elif platform.system() == "Darwin":
            variable = "HOME"
        elif platform.system() == "Linux":
            variable = "HOME"

        environment = Environment(variable)
        self.assertIsInstance(environment.getValues(), dict)
        self.assertIsInstance(environment.getValues(variable), dict)

        self.assertIsInstance(environment.getValues().get(variable), str)
        self.assertEqual(environment.getValues()[variable],
                         os.environ[variable])
        environment.getValues(
            "JOHNDOE_IS_FOR_SURE_A_NON_EXISTING_SYSTEM_ENVIRONMENT_VARIABLE")
        self.assertFalse(
            environment.getValues()
            ["JOHNDOE_IS_FOR_SURE_A_NON_EXISTING_SYSTEM_ENVIRONMENT_VARIABLE"])