Reading installed snaps now takes around 95% less time

This commit is contained in:
Vinicius Moreira
2019-09-13 19:02:39 -03:00
parent 5f2427d2e5
commit 4ff7d3d84a
5 changed files with 18 additions and 6 deletions

View File

@@ -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:

View File

@@ -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('*', '')

View File

@@ -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:

View File

@@ -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

View File

@@ -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