[flatpak] fix: not displaying the updates size for Flatpak 1.2

This commit is contained in:
Vinicius Moreira
2021-11-09 12:28:41 -03:00
parent 8488b086e6
commit d68bf1e53d
3 changed files with 33 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixes ### Fixes
- Flatpak - Flatpak
- not displaying update components not associated with installed packages - not displaying update components not associated with installed packages
- not displaying the updates size for Flatpak 1.2
- UI - UI
- upgrade summary: not displaying the icon type for some applications - upgrade summary: not displaying the icon type for some applications

View File

@@ -399,10 +399,10 @@ def run(app_id: str):
def map_update_download_size(app_ids: Iterable[str], installation: str, version: Version) -> Dict[str, int]: def map_update_download_size(app_ids: Iterable[str], installation: str, version: Version) -> Dict[str, int]:
success, output = ProcessHandler().handle_simple(SimpleProcess(['flatpak', 'update', '--{}'.format(installation)])) success, output = ProcessHandler().handle_simple(SimpleProcess(['flatpak', 'update', '--{}'.format(installation)]))
if version >= VERSION_1_5: if version >= VERSION_1_2:
res = {} res = {}
p = re.compile(r'^\d+.\t') p = re.compile(r'^\d+.\t')
p2 = re.compile(r'\s([0-9.?a-zA-Z]+)\s?') p2 = re.compile(r'([0-9.?a-zA-Z]+\s?)')
for l in output.split('\n'): for l in output.split('\n'):
if l: if l:
line = l.strip() line = l.strip()
@@ -420,11 +420,17 @@ def map_update_download_size(app_ids: Iterable[str], installation: str, version:
size_tuple = p2.findall(line_split[6]) size_tuple = p2.findall(line_split[6])
if size_tuple: if size_tuple:
size = size_tuple[0].split('?') if version >= VERSION_1_5:
size = size_tuple[0].split('?')
if size and len(size) > 1: if size and len(size) > 1:
try:
res[related_id[0].strip()] = size_to_byte(float(size[0]), size[1].strip())
except:
traceback.print_exc()
else:
try: try:
res[related_id[0].strip()] = size_to_byte(float(size[0]), size[1]) res[related_id[0].strip()] = size_to_byte(float(size_tuple[0]), size_tuple[1].strip())
except: except:
traceback.print_exc() traceback.print_exc()
return res return res

View File

@@ -0,0 +1,21 @@
from unittest import TestCase
from unittest.mock import patch, Mock
from bauh import __app_name__
from bauh.gems.flatpak import flatpak, VERSION_1_2
class FlatpakTest(TestCase):
@patch(f'{__app_name__}.gems.flatpak.flatpak.ProcessHandler.handle_simple', return_value=(True, """
Looking for updates...
\tID\tArch\tBranch\tRemote\tDownload
1.\t \torg.xpto.Xnote\tx86_64\tstable\tflathub\t< 4.3 MB
"""))
def test_map_update_download_size__for_flatpak_1_2(self, handle_simple: Mock):
download_size = flatpak.map_update_download_size(app_ids={'org.xpto.Xnote'}, installation='user', version=VERSION_1_2)
handle_simple.assert_called_once()
self.assertEqual({'org.xpto.Xnote': 4300000}, download_size)