Esempio n. 1
0
	def edit_file(self, selection):
		"""Edit selected filename"""
		section = self._application.options.section('editor')
		command = section.get('default_editor')

		exec_string = self.__format_command_string(selection, command)

		# open selected file(s)
		split_command = shlex.split(exec_string)
		test_command = split_command[0] if len(split_command) > 1 else exec_string

		if (section.get('terminal_command') and section.get('type') == 1) \
		or not is_x_app(test_command):
			active_object = self._application.get_active_object()

			options = Parameters()
			options.set('close_with_child', True)
			options.set('shell_command', split_command[0])
			options.set('arguments', split_command)
			options.set('path', os.path.dirname(selection[0]))

			self._application.create_terminal_tab(active_object._notebook, options)

		else:
			os.system('{0} &'.format(exec_string))
Esempio n. 2
0
	def edit_file(self, selection):
		"""Edit selected filename"""
		section = self._application.options.section('editor')
		command = section.get('default_editor')

		exec_string = self.__format_command_string(selection, command)

		# open selected file(s)
		split_command = shlex.split(exec_string)
		test_command = split_command[0] if len(split_command) > 1 else exec_string

		if (section.get('terminal_command') and section.get('type') == 1) \
		or not is_x_app(test_command):
			active_object = self._application.get_active_object()

			options = Parameters()
			options.set('close_with_child', True)
			options.set('shell_command', split_command[0])
			options.set('arguments', split_command)
			options.set('path', os.path.dirname(selection[0]))

			self._application.create_terminal_tab(active_object._notebook, options)

		else:
			os.system('{0} &'.format(exec_string))
Esempio n. 3
0
	def open_file(self, selection, application_info=None, exec_command=None):
		"""Open filename using config file or specified execute command"""
		if application_info is not None:
			# get command from config file
			command = application_info.command_line
			
		elif exec_command is not None:
			# use specified command
			command = exec_command
		
		else:
			# raise exception, we need at least one argument
			raise AttributeError('Error opening file. We need command or application to be specified.')
		
		exec_string = self.__format_command_string(selection, command)

		# open selected file(s)
		split_command = shlex.split(exec_string)
		test_command = split_command[0] if len(split_command) > 1 else exec_string

		if is_x_app(test_command):
			os.system('{0} &'.format(exec_string))

		else:
			active_object = self._application.get_active_object()

			options = Parameters()
			options.set('close_with_child', True)
			options.set('shell_command', split_command[0])
			options.set('arguments', split_command)
			options.set('path', os.path.dirname(selection[0]))

			self._application.create_terminal_tab(active_object._notebook, options)
Esempio n. 4
0
	def execute_file(self, path, provider=None):
		"""Execute specified item properly."""
		mime_type = self.get_mime_type(path)
		terminal_type = self._application.options.section('terminal').get('type')
		should_execute = False

		if provider is not None and provider.is_local:
			# only allow local files which have execute
			# bit set to be executed locally
			should_execute = os.access(path, os.X_OK)

			# if we still don't know content type, try to guess
			if self.is_mime_type_unknown(mime_type):
				data = self.get_sample_data(path, provider)
				mime_type = self.get_mime_type(data=data)

		if gio.content_type_can_be_executable(mime_type) and should_execute:
			# file type is executable
			if is_x_app(path):
				subprocess.Popen(
							(path, '&'),
							cwd=os.path.dirname(path)
						)

			else:
				# command is console based, create terminal tab and fork it
				if terminal_type != TerminalType.EXTERNAL:
					active_object = self._application.get_active_object()

					options = Parameters()
					options.set('close_with_child', False)
					options.set('shell_command', path)
					options.set('path', os.path.dirname(path))

					tab = self._application.create_terminal_tab(active_object._notebook, options)

		else:
			# file type is not executable, try to open with default associated application
			default_application = self.get_default_application_for_type(mime_type)

			if default_application is not None:
				self.open_file((path,), default_application)

			else:
				# no default application selected, show application selection dialog
				dialog = ApplicationSelectDialog(self._application, path)
				result = dialog.get_response()

				if result[0] == gtk.RESPONSE_OK:
					self.open_file(selection=(path,), exec_command=result[2])
Esempio n. 5
0
	def execute_file(self, path, provider=None):
		"""Execute specified item properly."""
		mime_type = self.get_mime_type(path)
		terminal_type = self._application.options.section('terminal').get('type')
		should_execute = False

		if provider is not None and provider.is_local:
			# only allow local files which have execute
			# bit set to be executed locally
			should_execute = os.access(path, os.X_OK)

			# if we still don't know content type, try to guess
			if self.is_mime_type_unknown(mime_type):
				data = self.get_sample_data(path, provider)
				mime_type = self.get_mime_type(data=data)

		if gio.content_type_can_be_executable(mime_type) and should_execute:
			# file type is executable
			if is_x_app(path):
				subprocess.Popen(
							(path, '&'),
							cwd=os.path.dirname(path)
						)

			else:
				# command is console based, create terminal tab and fork it
				active_object = self._application.get_active_object()

				options = Parameters()
				options.set('close_with_child', False)
				options.set('shell_command', path)
				options.set('path', os.path.dirname(path))

				self._application.create_terminal_tab(active_object._notebook, options)

		else:
			# file type is not executable, try to open with default associated application
			default_application = self.get_default_application_for_type(mime_type)

			if default_application is not None:
				self.open_file((path,), default_application)

			else:
				# no default application selected, show application selection dialog
				dialog = ApplicationSelectDialog(self._application, path)
				result = dialog.get_response()

				if result[0] == gtk.RESPONSE_OK:
					self.open_file(selection=(path,), exec_command=result[2])
Esempio n. 6
0
    def open_file(self, selection, application_info=None, exec_command=None):
        """Open filename using config file or specified execute command"""
        if application_info is not None:
            # launch application using GIO API
            application = self.get_gio_application_by_id(application_info.id)

            if application is not None:
                if application.supports_uris():
                    selection = map(
                        lambda path: 'file://{0}'.format(
                            urllib.pathname2url(path))
                        if not path.startswith('file://') else path, selection)
                    application.launch_uris(selection)
                else:
                    application.launch(
                        [gio.File(path=path) for path in selection])

        elif exec_command is not None:
            # use specified command
            command = exec_command

            selection = map(lambda item: item.replace('"', '\\"'), selection)
            exec_string = self.__format_command_string(selection, command)

            # open selected file(s)
            split_command = shlex.split(exec_string, posix=False)
            test_command = split_command[0] if len(
                split_command) > 1 else exec_string

            if is_x_app(test_command):
                subprocess.Popen(split_command,
                                 cwd=os.path.dirname(selection[0]))

            else:
                active_object = self._application.get_active_object()

                options = Parameters()
                options.set('close_with_child', True)
                options.set('shell_command', split_command[0])
                options.set('arguments', split_command)
                options.set('path', os.path.dirname(selection[0]))

                self._application.create_terminal_tab(active_object._notebook,
                                                      options)
Esempio n. 7
0
	def open_file(self, selection, application_info=None, exec_command=None):
		"""Open filename using config file or specified execute command"""
		if application_info is not None:
			# launch application using GIO API
			application = self.get_gio_application_by_id(application_info.id)

			if application is not None:
				if application.supports_uris():
					application.launch_uris(selection)
				else:
					application.launch([gio.File(path=path) for path in selection])
			
		elif exec_command is not None:
			# use specified command
			command = exec_command
		
			selection = map(lambda item: item.replace('"', '\\"'), selection)
			exec_string = self.__format_command_string(selection, command)

			# open selected file(s)
			split_command = shlex.split(exec_string, posix=False)
			test_command = split_command[0] if len(split_command) > 1 else exec_string

			if is_x_app(test_command):
				os.system('{0} &'.format(exec_string))

			else:
				active_object = self._application.get_active_object()

				options = Parameters()
				options.set('close_with_child', True)
				options.set('shell_command', split_command[0])
				options.set('arguments', split_command)
				options.set('path', os.path.dirname(selection[0]))

				self._application.create_terminal_tab(active_object._notebook, options)