Skip to content

Commit

Permalink
[flatpak] Formatting the API categories to the same format provided b…
Browse files Browse the repository at this point in the history
…y the other packaging technologies
  • Loading branch information
vinifmor committed Oct 24, 2019
1 parent 064ef53 commit 1a4ccfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- showing an error popup when **AppImageLauncher** messes up with an application installation
- Flatpak:
- Runtimes now are categorized as "runtime"
- Formatting the API categories to the same format provided by the other packaging technologies
- AUR:
- showing a "user-friendly" popup when there are integrity issues with the source-files of a building package
- not waiting for the categories file to be retrieved from the cloud during application boot ( reduces boot time )
Expand Down
4 changes: 3 additions & 1 deletion bauh/gems/flatpak/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, context: ApplicationContext):
super(FlatpakManager, self).__init__(context=context)
self.i18n = context.i18n
self.api_cache = context.cache_factory.new()
self.category_cache = context.cache_factory.new()
context.disk_loader_factory.map(FlatpakApplication, self.api_cache)
self.enabled = True
self.http_client = context.http_client
Expand All @@ -46,7 +47,8 @@ def _map_to_model(self, app_json: dict, installed: bool, disk_loader: DiskCacheL
disk_loader.fill(app) # preloading cached disk data

if internet:
FlatpakAsyncDataLoader(app=app, api_cache=self.api_cache, manager=self, context=self.context).start()
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)
Expand Down
18 changes: 16 additions & 2 deletions bauh/gems/flatpak/worker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import traceback
from threading import Thread

Expand All @@ -9,17 +10,20 @@
from bauh.gems.flatpak.constants import FLATHUB_API_URL, FLATHUB_URL
from bauh.gems.flatpak.model import FlatpakApplication

RE_SPLIT_UPPER = re.compile(r'[A-Z][a-z]*')


class FlatpakAsyncDataLoader(Thread):

def __init__(self, app: FlatpakApplication, manager: SoftwareManager, context: ApplicationContext, api_cache: MemoryCache):
def __init__(self, app: FlatpakApplication, manager: SoftwareManager, context: ApplicationContext, api_cache: MemoryCache, category_cache: MemoryCache):
super(FlatpakAsyncDataLoader, self).__init__(daemon=True)
self.app = app
self.manager = manager
self.http_client = context.http_client
self.api_cache = api_cache
self.persist = False
self.logger = context.logger
self.category_cache = category_cache

def run(self):
if self.app:
Expand Down Expand Up @@ -51,7 +55,17 @@ def run(self):
self.app.icon_url = FLATHUB_URL + self.app.icon_url

if data.get('categories'):
self.app.categories = [c['name'] for c in data['categories']]
cats = []
for c in data['categories']:
cached = self.category_cache.get(c['name'])

if not cached:
cached = ' '.join(RE_SPLIT_UPPER.findall(c['name'])).lower()
self.category_cache.add_non_existing(c['name'], cached)

cats.append(cached)

self.app.categories = cats

loaded_data = self.app.get_data_to_cache()

Expand Down

0 comments on commit 1a4ccfc

Please sign in to comment.