mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 19:44:15 +02:00
Reading installed snaps now takes around 95% less time
This commit is contained in:
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
|
|
||||||
## [0.6.0]
|
## [0.6.0]
|
||||||
### Improvements:
|
### Improvements:
|
||||||
|
- Reading installed snaps now takes around 95% less time.
|
||||||
|
|
||||||
### Fixes:
|
### Fixes:
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from bauh.api.abstract.disk import DiskCacheLoader
|
|||||||
from bauh.api.abstract.handler import ProcessWatcher
|
from bauh.api.abstract.handler import ProcessWatcher
|
||||||
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion
|
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion
|
||||||
from bauh.commons.system import SystemProcess, ProcessHandler
|
from bauh.commons.system import SystemProcess, ProcessHandler
|
||||||
|
|
||||||
from bauh.gems.snap import snap, suggestions
|
from bauh.gems.snap import snap, suggestions
|
||||||
from bauh.gems.snap.model import SnapApplication
|
from bauh.gems.snap.model import SnapApplication
|
||||||
from bauh.gems.snap.worker import SnapAsyncDataLoader
|
from bauh.gems.snap.worker import SnapAsyncDataLoader
|
||||||
@@ -29,7 +28,7 @@ class SnapManager(SoftwareManager):
|
|||||||
name=app_json.get('name'),
|
name=app_json.get('name'),
|
||||||
version=app_json.get('version'),
|
version=app_json.get('version'),
|
||||||
latest_version=app_json.get('version'),
|
latest_version=app_json.get('version'),
|
||||||
description=app_json.get('description'))
|
description=app_json.get('description', app_json.get('summary')))
|
||||||
|
|
||||||
if app.publisher:
|
if app.publisher:
|
||||||
app.publisher = app.publisher.replace('*', '')
|
app.publisher = app.publisher.replace('*', '')
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class SnapApplication(SoftwarePackage):
|
|||||||
return self.get_default_icon_path()
|
return self.get_default_icon_path()
|
||||||
|
|
||||||
def is_application(self):
|
def is_application(self):
|
||||||
return not self.type and (self.type not in ('core', 'base', 'snapd') and not self._name_starts_with(('gtk-', 'gnome-', 'kde-', 'gtk2-')))
|
return not self.type and (self.name != 'snapd' and self.type not in ('core', 'base', 'os') and not self._name_starts_with(('gtk-', 'gnome-', 'kde-', 'gtk2-')))
|
||||||
|
|
||||||
def _name_starts_with(self, words: tuple):
|
def _name_starts_with(self, words: tuple):
|
||||||
for word in words:
|
for word in words:
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bauh.commons.system import new_root_subprocess, run_cmd
|
from bauh.commons.system import new_root_subprocess, run_cmd, new_subprocess
|
||||||
|
|
||||||
BASE_CMD = 'snap'
|
BASE_CMD = 'snap'
|
||||||
|
|
||||||
@@ -43,7 +44,6 @@ def app_str_to_json(app: str) -> dict:
|
|||||||
'notes': app_data[5] if len(app_data) >= 6 else None
|
'notes': app_data[5] if len(app_data) >= 6 else None
|
||||||
}
|
}
|
||||||
|
|
||||||
app_json.update(get_info(app_json['name'], ('summary', 'type', 'description')))
|
|
||||||
return app_json
|
return app_json
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +83,19 @@ def read_installed() -> List[dict]:
|
|||||||
if idx > 0 and app_str:
|
if idx > 0 and app_str:
|
||||||
apps.append(app_str_to_json(app_str))
|
apps.append(app_str_to_json(app_str))
|
||||||
|
|
||||||
|
info_out = new_subprocess(['cat', *['/var/lib/snapd/snap/{}/current/meta/snap.yaml'.format(a['name']) for a in apps]]).stdout
|
||||||
|
|
||||||
|
idx = -1
|
||||||
|
for o in new_subprocess(['grep', '-E', '(summary|type)', '--colour=never'], stdin=info_out).stdout:
|
||||||
|
if o:
|
||||||
|
line = o.decode()
|
||||||
|
|
||||||
|
if line.startswith('summary:'):
|
||||||
|
idx += 1
|
||||||
|
apps[idx]['summary'] = line.split(':')[1].strip()
|
||||||
|
else:
|
||||||
|
apps[idx]['type'] = line.split(':')[1].strip()
|
||||||
|
|
||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from bauh.api.abstract.cache import MemoryCache
|
|||||||
from bauh.api.abstract.context import ApplicationContext
|
from bauh.api.abstract.context import ApplicationContext
|
||||||
from bauh.api.abstract.controller import SoftwareManager
|
from bauh.api.abstract.controller import SoftwareManager
|
||||||
from bauh.api.abstract.model import PackageStatus
|
from bauh.api.abstract.model import PackageStatus
|
||||||
|
|
||||||
from bauh.gems.snap import snap
|
from bauh.gems.snap import snap
|
||||||
from bauh.gems.snap.constants import SNAP_API_URL
|
from bauh.gems.snap.constants import SNAP_API_URL
|
||||||
from bauh.gems.snap.model import SnapApplication
|
from bauh.gems.snap.model import SnapApplication
|
||||||
|
|||||||
Reference in New Issue
Block a user