Exemple #1
0
    def _map_to_model(self, app_json: dict, installed: bool, disk_loader: Optional[DiskCacheLoader], internet: bool = True) -> Tuple[FlatpakApplication, Optional[FlatpakAsyncDataLoader]]:

        app = FlatpakApplication(**app_json, i18n=self.i18n)
        app.installed = installed
        api_data = self.api_cache.get(app_json['id'])

        if app.runtime and app.latest_version is None:
            app.latest_version = app.version

        expired_data = api_data and api_data.get('expires_at') and api_data['expires_at'] <= datetime.utcnow()

        data_loader: Optional[FlatpakAsyncDataLoader] = None

        if not api_data or expired_data:
            if not app.runtime:
                if disk_loader:
                    disk_loader.fill(app)  # preloading cached disk data

                if internet:
                    data_loader = FlatpakAsyncDataLoader(app=app, api_cache=self.api_cache, manager=self,
                                                         context=self.context, category_cache=self.category_cache)
                    data_loader.start()

        else:
            app.fill_cached_data(api_data)
            app.status = PackageStatus.READY

        return app, data_loader
Exemple #2
0
    def _map_to_model(self,
                      app_json: dict,
                      installed: bool,
                      disk_loader: DiskCacheLoader,
                      internet: bool = True) -> FlatpakApplication:

        app = FlatpakApplication(**app_json, i18n=self.i18n)
        app.installed = installed
        api_data = self.api_cache.get(app_json['id'])

        expired_data = api_data and api_data.get(
            'expires_at') and api_data['expires_at'] <= datetime.utcnow()

        if not api_data or expired_data:
            if not app.runtime:
                if disk_loader:
                    disk_loader.fill(app)  # preloading cached disk data

                if internet:
                    FlatpakAsyncDataLoader(
                        app=app,
                        api_cache=self.api_cache,
                        manager=self,
                        context=self.context,
                        category_cache=self.category_cache).start()

        else:
            app.fill_cached_data(api_data)

        return app
Exemple #3
0
 def test_format_category(self):
     self.assertEqual('irc client',
                      FlatpakAsyncDataLoader.format_category('IRCClient'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('TextEditor'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('Text Editor'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('text editor'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('Text editor'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('text Editor'))
     self.assertEqual('text editor',
                      FlatpakAsyncDataLoader.format_category('textEditor'))
     self.assertEqual('ide', FlatpakAsyncDataLoader.format_category('IDE'))
     self.assertEqual(
         'faster irc client',
         FlatpakAsyncDataLoader.format_category('Faster IRCClient'))
     self.assertEqual('3d graphics',
                      FlatpakAsyncDataLoader.format_category('3DGraphics'))
     self.assertEqual('32d graphics',
                      FlatpakAsyncDataLoader.format_category('32DGraphics'))
     self.assertEqual('d32 graphics',
                      FlatpakAsyncDataLoader.format_category('D32Graphics'))