Esempio n. 1
0
    def run_pip_command(self, interpreter, worker_function, package,
                        operation):
        """
        Run a pip command. The command is run on the backend for the current
        interpreter.

        :param interpreter: Interpreter which is going to run the backend
        :param worker_function: The worker function to execute.
        :param package: The list of packages to install, as a string where each
            item is separated by a space.
        :param operation: Operation title (used for the info label)
        """
        self.stop_backend()
        self.ui.lblInfos.setText(operation)
        self._worker = worker_function
        self._package = package
        self.stop_backend()
        self.backend = BackendManager(self)
        process = BackendProcess(self.parent())
        process.finished.connect(self._on_process_finished)
        self.backend._process = process
        server_script = server.__file__.replace('.pyc', '.py')
        port = self.backend.pick_free_port()
        self.backend._port = port
        if LINUX and self._need_root_perms(interpreter):
            _logger().info('running pip command with root privileges')
            auth = get_authentication_program()
            if 'kdesu' in auth:
                # no quotes around command when using kdesu
                cmd = '%s %s %s %s --syspath %s'
            else:
                # gksu requires quotes around command
                cmd = '%s "%s %s %s --syspath %s"'
            cmd = cmd % (auth, interpreter, server_script, str(port),
                         get_library_zip_path())
            process.start(cmd)
        elif DARWIN and self._need_root_perms(interpreter):
            cmd = 'sudo %s %s %s --syspath %s' % (
                interpreter, server_script, str(port), get_library_zip_path())
            auth_process = QtCore.QProcess()
            auth_process.start('pseudo')
            auth_process.waitForFinished()
            process.start(cmd)
        else:
            self.backend.start(server.__file__,
                               interpreter=interpreter,
                               args=['-s'] + [get_library_zip_path()])
        QtCore.QTimer.singleShot(100, self._run_command)
Esempio n. 2
0
    def start(self,
              script,
              interpreter=sys.executable,
              args=None,
              error_callback=None):
        """
        Starts the backend process.

        The backend is a python script that starts a
        :class:`pyqode.core.backend.JsonServer`. You must write the backend
        script so that you can apply your own backend configuration.

        The script can be run with a custom interpreter. The default is to use
        sys.executable.

        .. note:: This restart the backend process if it was previously
                  running.

        :param script: Path to the backend script.
        :param interpreter: The python interpreter to use to run the backend
            script. If None, sys.executable is used unless we are in a frozen
            application (frozen backends do not require an interpreter).
        :param args: list of additional command line args to use to start
            the backend process.
        """
        if self.running:
            self.stop()
        self.server_script = script
        self.interpreter = interpreter
        self.args = args
        backend_script = script.replace('.pyc', '.py')
        self._port = self.pick_free_port()
        if hasattr(sys, "frozen") and not backend_script.endswith('.py'):
            # frozen backend script on windows/mac does not need an interpreter
            program = backend_script
            pgm_args = [str(self._port)]
        else:
            program = interpreter
            pgm_args = [backend_script, str(self._port)]
        if args:
            pgm_args += args
        self._process = BackendProcess(self.editor)
        if error_callback:
            self._process.error.connect(error_callback)
        self._process.start(program, pgm_args)
        _logger().info('starting backend process: %s %s', program,
                       ' '.join(pgm_args))
Esempio n. 3
0
    def start(self,
              script,
              interpreter=sys.executable,
              args=None,
              error_callback=None,
              reuse=False):
        """
        Starts the backend process.

        The backend is a python script that starts a
        :class:`pyqode.core.backend.JsonServer`. You must write the backend
        script so that you can apply your own backend configuration.

        The script can be run with a custom interpreter. The default is to use
        sys.executable.

        .. note:: This restart the backend process if it was previously
                  running.

        :param script: Path to the backend script.
        :param interpreter: The python interpreter to use to run the backend
            script. If None, sys.executable is used unless we are in a frozen
            application (frozen backends do not require an interpreter).
        :param args: list of additional command line args to use to start
            the backend process.
        :param reuse: True to reuse an existing backend process. WARNING: to
            use this, your application must have one single server script. If
            you're creating an app which supports multiple programming
            languages you will need to merge all backend scripts into one
            single script, otherwise the wrong script might be picked up).
        """
        self._shared = reuse
        if reuse and BackendManager.SHARE_COUNT:
            self._port = BackendManager.LAST_PORT
            self._process = BackendManager.LAST_PROCESS
            BackendManager.SHARE_COUNT += 1
        else:
            if self.running:
                self.stop()
            self.server_script = script
            self.interpreter = interpreter
            self.args = args
            backend_script = script.replace('.pyc', '.py')
            self._port = self.pick_free_port()
            if hasattr(sys, "frozen") and not backend_script.endswith('.py'):
                # frozen backend script on windows/mac does not need an
                # interpreter
                program = backend_script
                pgm_args = [str(self._port)]
            else:
                program = interpreter
                pgm_args = [backend_script, str(self._port)]
            if args:
                pgm_args += args
            self._process = BackendProcess(self.editor)
            if error_callback:
                self._process.error.connect(error_callback)
            self._process.start(program, pgm_args)

            if reuse:
                BackendManager.LAST_PROCESS = self._process
                BackendManager.LAST_PORT = self._port
                BackendManager.SHARE_COUNT += 1
            _logger().debug('starting backend process: %s %s', program,
                            ' '.join(pgm_args))