[improvement][flathub] automatically adds Flathub as the default remote at the user level

This commit is contained in:
Vinícius Moreira
2020-01-13 13:04:35 -03:00
parent fe03590ea6
commit 9f15b1b244
3 changed files with 43 additions and 11 deletions

View File

@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Flatpak:
- the application name tooltip now displays the installation level. e.g: **gedit ( system )**
- info window displaying the installation level
- "remote not set" warning dropped in favor of the new behavior: automatically adds Flathub as the default remote at the user level
- Web:
- not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event.
- supporting JPEG images as custom icons

View File

@@ -58,12 +58,27 @@ class FlatpakManager(SoftwareManager):
return app
def _get_search_remote(self) -> str:
remotes = flatpak.list_remotes()
if remotes['system']:
remote_level = 'system'
elif remotes['user']:
remote_level = 'user'
else:
remote_level = 'user'
flatpak.set_default_remotes(remote_level)
return remote_level
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult:
if is_url:
return SearchResult([], [], 0)
remote_level = self._get_search_remote()
res = SearchResult([], [], 0)
apps_found = flatpak.search(flatpak.get_version(), words)
apps_found = flatpak.search(flatpak.get_version(), words, remote_level)
if apps_found:
already_read = set()
@@ -310,10 +325,7 @@ class FlatpakManager(SoftwareManager):
return updates
def list_warnings(self, internet_available: bool) -> List[str]:
if flatpak.is_installed():
if not flatpak.has_remotes_set():
return [self.i18n['flatpak.notification.no_remotes'],
self.i18n['flatpak.notification.disable'].format(bold('Flatpak'), bold(self.i18n['manage_window.settings.gems']))]
return []
def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]:
cli_version = flatpak.get_version()
@@ -327,6 +339,7 @@ class FlatpakManager(SoftwareManager):
return res
else:
self.logger.info("Mapping suggestions")
remote_level = self._get_search_remote()
installed = {i.id for i in self.read_installed(disk_loader=None).installed} if filter_installed else None
for line in file.text.split('\n'):
@@ -345,7 +358,7 @@ class FlatpakManager(SoftwareManager):
if cached_sug:
res.append(cached_sug)
else:
app_json = flatpak.search(cli_version, appid, app_id=True)
app_json = flatpak.search(cli_version, appid, remote_level, app_id=True)
if app_json:
model = PackageSuggestion(self._map_to_model(app_json[0], False, None), priority)

View File

@@ -3,7 +3,7 @@ import subprocess
import traceback
from datetime import datetime
from io import StringIO
from typing import List, Dict
from typing import List, Dict, Set
from bauh.api.exception import NoInternetException
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess
@@ -260,9 +260,9 @@ def get_app_commits_data(app_ref: str, origin: str, installation: str) -> List[d
return commits
def search(version: str, word: str, app_id: bool = False) -> List[dict]:
def search(version: str, word: str, installation: str, app_id: bool = False) -> List[dict]:
res = run_cmd('{} search {}'.format(BASE_CMD, word))
res = run_cmd('{} search {} --{}'.format(BASE_CMD, word, installation))
found = []
@@ -343,13 +343,31 @@ def install(app_id: str, origin: str, installation: str):
return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y', '--{}'.format(installation)])
def set_default_remotes():
run_cmd('{} remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo'.format(BASE_CMD))
def set_default_remotes(installation: str):
run_cmd('{} remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo --{}'.format(BASE_CMD, installation))
def has_remotes_set() -> bool:
return bool(run_cmd('{} remotes'.format(BASE_CMD)).strip())
def list_remotes() -> Dict[str, Set[str]]:
res = {'system': set(), 'user': set()}
output = run_cmd('{} remotes'.format(BASE_CMD)).strip()
if output:
lines = output.split('\n')
for line in lines:
remote = line.split('\t')
if 'system' in remote[1]:
res['system'].add(remote[0].strip())
elif 'user' in remote[1]:
res['user'].add(remote[0].strip())
return res
def run(app_id: str):
subprocess.Popen([BASE_CMD, 'run', app_id])