Skip to content

Commit

Permalink
improved appimage extgraction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mijorus committed May 30, 2023
1 parent c3f6ca3 commit 4977311
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/providers/AppImageProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ def refresh_title(self, el: AppImageListElement) -> str:
return el.name

def uninstall(self, el: AppImageListElement):
logging.info(f'Removing {el.file_path}')
os.remove(el.file_path)

if el.desktop_entry:
logging.info(f'Removing {el.desktop_entry.getFileName()}')
os.remove(el.desktop_entry.getFileName())

el.set_installed_status(InstalledStatus.NOT_INSTALLED)
Expand Down Expand Up @@ -364,26 +366,49 @@ def mount_appimage(self, file_path: str) -> str:
if not os.path.exists(f'{dest_path}'):
os.mkdir(f'{dest_path}')

logging.debug(f'Created temporary folder at {dest_path}')

gio_copy(file, dest)

logging.debug(f'Chmod file {dest.get_path()}')
os.chmod(dest.get_path(), 0o755)

prefix = [dest.get_path(), '--appimage-extract']
appimage_extract_support = False

try:
appimage_help = subprocess.run([dest.get_path(), '--appimage-help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.decode()

appimage_extract_support = ('-appimage-extract' in appimage_help)
if not appimage_extract_support:
raise InternalError('This appimage does not support appimage-extract')

extraction_output = ''
except Exception as e:
logging.error(str(e))

if appimage_extract_support:
prefix = [dest.get_path(), '--appimage-extract']
extraction_output = ''

# check if the appimage supports partial extraction
appimage_help = terminal.sh([dest.get_path(), '--appimage-help'], cwd=dest_path)
if '--appimage-extract [<pattern>]' in appimage_help:
for match in ['*.desktop', 'usr/share/icons/*', '*.svg', '*.png']:
run = [*prefix, match]
# check if the appimage supports partial extraction
if '--appimage-extract [<pattern>]' in appimage_help:
for match in ['*.desktop', 'usr/share/icons/*', '*.svg', '*.png']:
run = [*prefix, match]

extraction_output = terminal.sh(run, cwd=dest_path)
extraction_output = terminal.sandbox_sh(run, cwd=dest_path)
else:
logging.debug('This AppImage does not support partial extraction, running ' + ' '.join(prefix))
extraction_output = terminal.sandbox_sh([*prefix], cwd=dest_path)

logging.debug(f'Extracted appimage {file.get_path()} with log:\n\n======\n\n{extraction_output}\n\n======\n\n')

else:
logging.debug('This AppImage does not support partial extraction, running ' + ' '.join(prefix))
extraction_output = terminal.sh([*prefix], cwd=dest_path)
logging.info('This appiamge does not support appimage-extract, trying with 7z')
z7zoutput = '=== 7z log ==='
z7zoutput = '\n\n' + terminal.sandbox_sh(['7z', 'x', dest.get_path(), '-r', '*.png', '-osquashfs-root', '-y'], cwd=dest_path)
z7zoutput += '\n\n' + terminal.sandbox_sh(['7z', 'x', dest.get_path(), '-r', '*.desktop', '-osquashfs-root', '-y'], cwd=dest_path)
z7zoutput += '\n\n' + terminal.sandbox_sh(['7z', 'x', dest.get_path(), '-r', '*.svg', '-osquashfs-root', '-y'], cwd=dest_path)

logging.debug(f'Extracted appimage {file.get_path()} with log:\n\n======\n\n{extraction_output}\n\n======\n\n')
logging.debug(z7zoutput)

return f'{dest_path}/squashfs-root'

Expand Down

0 comments on commit 4977311

Please sign in to comment.