mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 16:44:16 +02:00
[snap] mapping categories | fix: not caching installed applications data
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import logging
|
||||
import os
|
||||
import traceback
|
||||
from threading import Thread
|
||||
from typing import Dict, List
|
||||
|
||||
from bauh.api.abstract.cache import MemoryCache
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.api.abstract.model import PackageStatus
|
||||
from bauh.api.http import HttpClient
|
||||
from bauh.gems.snap import snap
|
||||
from bauh.gems.snap.constants import SNAP_API_URL
|
||||
from bauh.gems.snap.model import SnapApplication
|
||||
@@ -68,3 +72,29 @@ class SnapAsyncDataLoader(Thread):
|
||||
|
||||
if self.persist:
|
||||
self.manager.cache_to_disk(pkg=self.app, icon_bytes=None, only_icon=False)
|
||||
|
||||
|
||||
class CategoriesDownloader:
|
||||
|
||||
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/categories.txt'
|
||||
|
||||
def __init__(self, http_client: HttpClient, logger: logging.Logger):
|
||||
self.http_client = http_client
|
||||
self.logger = logger
|
||||
|
||||
def get_categories(self) -> Dict[str, List[str]]:
|
||||
self.logger.info('Downloading Snap category definitions from {}'.format(self.URL_CATEGORIES_FILE))
|
||||
|
||||
res = self.http_client.get(self.URL_CATEGORIES_FILE, headers={'Authorization': 'token {}'.format(os.getenv('GITHUB_TOKEN'))})
|
||||
|
||||
if res:
|
||||
categories_map = {}
|
||||
for l in res.text.split('\n'):
|
||||
if l:
|
||||
data = l.split('=')
|
||||
categories_map[data[0]] = [c.strip() for c in data[1].split(',') if c]
|
||||
|
||||
self.logger.info('Loaded categories for {} Snap applications'.format(len(categories_map)))
|
||||
return categories_map
|
||||
else:
|
||||
self.logger.info('Could not download {}'.format(self.URL_CATEGORIES_FILE))
|
||||
|
||||
Reference in New Issue
Block a user