Пример #1
0
    def handleConnected(self):
        """
        Implements abstract method of :class:`WebSocket`

        * Appends `self` to `self.controllers`
        * Validates manifest file.
        * Sends :class:`PreferencesEvent` to extension
        """
        self.extension_id = self.request.path[1:]
        if not self.extension_id:
            raise Exception('Incorrect path %s' % self.request.path)

        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.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()))
 def _get_extension_info(self, ext_id: str, prefs: ExtensionPreferences, error: ExtError = None) -> ExtensionInfo:
     ext_db = ExtensionDb.get_instance()
     is_connected = True
     try:
         ExtensionServer.get_instance().get_controller(ext_id)
     except KeyError:
         is_connected = False
     ext_runner = ExtensionRunner.get_instance()
     is_running = is_connected or ext_runner.is_running(ext_id)
     ext_db_record = ext_db.find(ext_id, {})
     return {
         'id': ext_id,
         'url': ext_db_record.get('url'),
         'updated_at': ext_db_record.get('updated_at'),
         'last_commit': ext_db_record.get('last_commit'),
         'last_commit_time': ext_db_record.get('last_commit_time'),
         'name': prefs.manifest.get_name(),
         'icon': prefs.manifest.get_icon_path(),
         'description': prefs.manifest.get_description(),
         'developer_name': prefs.manifest.get_developer_name(),
         'preferences': prefs.get_items(),
         'error': error,
         'is_running': is_running,
         'runtime_error': ext_runner.get_extension_error(ext_id) if not is_running else None
     }
    def _get_all_extensions(self):
        extensions = []
        for ext_id, _ in find_extensions(EXTENSIONS_DIR):
            prefs = ExtensionPreferences.create_instance(ext_id)
            prefs.manifest.refresh()
            try:
                prefs.manifest.validate()
                prefs.manifest.check_compatibility()
            except (ManifestValidationError, VersionIncompatibilityError):
                continue
            extensions.append(self._get_extension_info(ext_id, prefs))

        return extensions
    def _get_all_extensions(self):
        extensions = []
        for ext_id, _ in find_extensions(EXTENSIONS_DIR):
            prefs = ExtensionPreferences.create_instance(ext_id)
            prefs.manifest.refresh()
            try:
                prefs.manifest.validate()
                prefs.manifest.check_compatibility()
            except (ManifestValidationError, VersionIncompatibilityError):
                continue
            extensions.append(self._get_extension_info(ext_id, prefs))

        return extensions
Пример #5
0
 def _get_extension_info(self, ext_id):
     ext_db = ExtensionDb.get_instance()
     ext_db_record = ext_db.find(ext_id, {})
     prefs = ExtensionPreferences.create_instance(ext_id)
     prefs.manifest.refresh()
     return {
         'id': ext_id,
         'url': ext_db_record.get('url'),
         'updated_at': ext_db_record.get('updated_at'),
         'last_commit': ext_db_record.get('last_commit'),
         'last_commit_time': ext_db_record.get('last_commit_time'),
         'name': prefs.manifest.get_name(),
         'icon': prefs.manifest.get_icon_path(),
         'description': prefs.manifest.get_description(),
         'developer_name': prefs.manifest.get_developer_name(),
         'preferences': prefs.get_items()
     }
    def _get_all_extensions(self) -> List[ExtensionInfo]:
        extensions = []
        for ext_id, _ in find_extensions(EXTENSIONS_DIR):
            prefs = ExtensionPreferences.create_instance(ext_id)  # type: ExtensionPreferences
            prefs.manifest.refresh()
            error = None
            try:
                prefs.manifest.validate()
                prefs.manifest.check_compatibility()
            except UlauncherAPIError as e:
                error = cast(ExtError, {
                    'message': str(e),
                    'errorName': e.error_name
                })
            except Exception as e:
                error = cast(ExtError, {
                    'message': str(e),
                    'errorName': ErrorName.UnexpectedError.value
                })
            extensions.append(self._get_extension_info(ext_id, prefs, error))

        return extensions
 def prefs(self, manifest):
     return ExtensionPreferences('test_extension', manifest, '/tmp')