Exemple #1
0
    def map_json(self,
                 app_json: dict,
                 installed: bool,
                 disk_loader: DiskCacheLoader,
                 internet: bool = True) -> SnapApplication:
        app = SnapApplication(
            publisher=app_json.get('publisher'),
            rev=app_json.get('rev'),
            notes=app_json.get('notes'),
            has_apps_field=app_json.get('apps_field', False),
            id=app_json.get('name'),
            name=app_json.get('name'),
            version=app_json.get('version'),
            latest_version=app_json.get('version'),
            description=app_json.get('description', app_json.get('summary')),
            verified_publisher=app_json.get('developer_validation',
                                            '') == 'verified',
            extra_actions=self.custom_actions)

        if app.publisher and app.publisher.endswith('*'):
            app.verified_publisher = True
            app.publisher = app.publisher.replace('*', '')

        categories = self.categories.get(app.name.lower())

        if categories:
            app.categories = categories

        app.installed = installed

        if not app.is_application():
            categories = app.categories

            if categories is None:
                categories = []
                app.categories = categories

            if 'runtime' not in categories:
                categories.append('runtime')

        api_data = self.api_cache.get(app_json['name'])
        expired_data = api_data and api_data.get(
            'expires_at') and api_data['expires_at'] <= datetime.utcnow()

        if (not api_data or expired_data) and app.is_application():
            if disk_loader and app.installed:
                disk_loader.fill(app)

            if internet:
                SnapAsyncDataLoader(app=app,
                                    api_cache=self.api_cache,
                                    manager=self,
                                    context=self.context).start()
        else:
            app.fill_cached_data(api_data)

        return app
Exemple #2
0
    def _fill_categories(self, app: SnapApplication):
        categories = self.categories.get(app.name.lower())

        if categories:
            app.categories = categories

        if not app.is_application():
            categories = app.categories

            if categories is None:
                categories = []
                app.categories = categories

            if 'runtime' not in categories:
                categories.append('runtime')