Exemplo n.º 1
0
    def configure(self, extension_id):
        """
        * Adds itself to the controllers dict
        * Validates manifest file.
        * Sends :class:`PreferencesEvent` to extension
        """
        self.extension_id = extension_id
        if not self.extension_id:
            raise RuntimeError("No extension_id provided")

        logger.info('Extension "%s" connected', self.extension_id)

        self.manifest = ExtensionManifest.open(self.extension_id)
        try:
            self.manifest.validate()
        except ExtensionManifestError as e:
            logger.warning("Couldn't connect '%s'. %s: %s", self.extension_id,
                           type(e).__name__, e)
            self.framer.close()
            return

        self.preferences = ExtensionPreferences.create_instance(
            self.extension_id)
        self.controllers[self.extension_id] = self
        self._debounced_send_event = debounce(
            self.manifest.get_option('query_debounce', 0.05))(self._send_event)

        self._send_event(PreferencesEvent(self.preferences.get_dict()))
Exemplo n.º 2
0
    def run(self, extension_id):
        """
        * Validates manifest
        * Runs extension in a new process
        """
        if self.is_running(extension_id):
            raise ExtensionIsRunningError(f"Extension ID: {extension_id}")

        manifest = ExtensionManifest.open(extension_id)
        manifest.validate()
        manifest.check_compatibility()

        cmd = [
            sys.executable,
            os.path.join(self.extensions_dir, extension_id, 'main.py')
        ]
        env = {}
        env['PYTHONPATH'] = ':'.join(
            filter(
                bool,
                [ULAUNCHER_APP_DIR, os.getenv('PYTHONPATH')]))

        if self.verbose:
            env['VERBOSE'] = '1'

        if self.dont_run_extensions:
            args = [env.get('VERBOSE', ''), env['PYTHONPATH']]
            args.extend(cmd)
            run_cmd = 'VERBOSE={} PYTHONPATH={} {} {}'.format(*args)
            logger.warning('Copy and run the following command to start %s',
                           extension_id)
            logger.warning(run_cmd)
            self.set_extension_error(extension_id,
                                     ExtRunErrorName.NoExtensionsFlag, run_cmd)
            return

        launcher = Gio.SubprocessLauncher.new(Gio.SubprocessFlags.STDERR_PIPE)
        for env_name, env_value in env.items():
            launcher.setenv(env_name, env_value, True)

        t_start = time()
        subproc = launcher.spawnv(cmd)
        error_line_str = Gio.DataInputStream.new(subproc.get_stderr_pipe())
        self.extension_procs[extension_id] = ExtensionProc(
            extension_id=extension_id,
            subprocess=subproc,
            start_time=t_start,
            error_stream=error_line_str,
            recent_errors=deque(maxlen=1))
        logger.debug("Launched %s using Gio.Subprocess", extension_id)

        subproc.wait_async(None, self.handle_wait, extension_id)
        self.read_stderr_line(self.extension_procs[extension_id])
Exemplo n.º 3
0
 def test_open__manifest_file__is_read(self):
     ext_dir = os.path.dirname(os.path.abspath(__file__))
     manifest = ExtensionManifest.open('test_extension', ext_dir)
     assert manifest.get_name() == "Test Extension"
Exemplo n.º 4
0
 def create_instance(cls, ext_id):
     return cls(ext_id, ExtensionManifest.open(ext_id))
Exemplo n.º 5
0
 def test_open__manifest_file__is_read(self, ext_dir):
     manifest = ExtensionManifest.open('test_extension', ext_dir)
     assert manifest.get_name() == "Test Extension"