mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[appimage] refactoring: typing
This commit is contained in:
@@ -528,13 +528,13 @@ class AppImageManager(SoftwareManager, SettingsController):
|
|||||||
finally:
|
finally:
|
||||||
releases_con.close()
|
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 r, d, files in os.walk(folder):
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.endswith('.desktop'):
|
if f.endswith('.desktop'):
|
||||||
return f
|
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):
|
for f in glob.glob(folder + ('/**' if not folder.endswith('/') else '**'), recursive=True):
|
||||||
if RE_ICON_ENDS_WITH.match(f):
|
if RE_ICON_ENDS_WITH.match(f):
|
||||||
return f
|
return f
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
RE_DESKTOP_EXEC = re.compile(r'(Exec\s*=(.+)(\n?))')
|
RE_DESKTOP_EXEC = re.compile(r'(Exec\s*=(.+)(\n?))')
|
||||||
RE_MANY_SPACES = re.compile(r'\s+')
|
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 r, d, files in os.walk(folder):
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.lower().endswith('.appimage'):
|
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:
|
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)):
|
for idx in range(len(words)):
|
||||||
if words[idx].lower() == treated_name:
|
if words[idx].lower() == treated_name:
|
||||||
words[idx] = '"{}"'.format(file_path)
|
words[idx] = f'"{file_path}"'
|
||||||
changed = True
|
changed = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not changed:
|
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)))
|
final_entry = final_entry.replace(full_match, full_match.replace(exec_groups[1], ' '.join(words)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user