[appimage] refactoring: typing

This commit is contained in:
Vinicius Moreira
2022-10-24 07:48:41 -03:00
parent 695f5e03f0
commit 123983dfaa
2 changed files with 7 additions and 6 deletions

View File

@@ -528,13 +528,13 @@ class AppImageManager(SoftwareManager, SettingsController):
finally:
releases_con.close()
def _find_desktop_file(self, folder: str) -> str:
def _find_desktop_file(self, folder: str) -> Optional[str]:
for r, d, files in os.walk(folder):
for f in files:
if f.endswith('.desktop'):
return f
def _find_icon_file(self, folder: str) -> str:
def _find_icon_file(self, folder: str) -> Optional[str]:
for f in glob.glob(folder + ('/**' if not folder.endswith('/') else '**'), recursive=True):
if RE_ICON_ENDS_WITH.match(f):
return f

View File

@@ -1,15 +1,16 @@
import os
import re
from typing import Optional
RE_DESKTOP_EXEC = re.compile(r'(Exec\s*=(.+)(\n?))')
RE_MANY_SPACES = re.compile(r'\s+')
def find_appimage_file(folder: str) -> str:
def find_appimage_file(folder: str) -> Optional[str]:
for r, d, files in os.walk(folder):
for f in files:
if f.lower().endswith('.appimage'):
return '{}/{}'.format(folder, f)
return f'{folder}/{f}'
def replace_desktop_entry_exec_command(desktop_entry: str, appname: str, file_path: str) -> str:
@@ -30,12 +31,12 @@ def replace_desktop_entry_exec_command(desktop_entry: str, appname: str, file_pa
for idx in range(len(words)):
if words[idx].lower() == treated_name:
words[idx] = '"{}"'.format(file_path)
words[idx] = f'"{file_path}"'
changed = True
break
if not changed:
words = ['"{}"'.format(file_path)]
words = [f'"{file_path}"']
final_entry = final_entry.replace(full_match, full_match.replace(exec_groups[1], ' '.join(words)))