Skip to content

Commit

Permalink
allow specifying the target directory for a package installation (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler authored Jul 12, 2024
1 parent cf29b44 commit c04a645
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions air_link/main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def main_page():
ui.codemirror().bind_value(app.storage.general, 'env').classes('h-32 border')

ui.label('Packages').classes('text-2xl')
ui.input('Installation directory', value='~/robot').bind_value_to(app.storage.general, 'target_directory')
show_packages()
upload = ui.upload(auto_upload=True, on_upload=add_package).props('accept=.zip').classes('hidden')
ui.button('Upload package', icon='upload', on_click=lambda: upload.run_method('pickFiles')).props('outline')
Expand Down
12 changes: 5 additions & 7 deletions air_link/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
PACKAGES_PATH.mkdir(exist_ok=True)
CURRENT_VERSION_PATH = Path(PACKAGES_PATH / 'current_version.txt')

TARGET = Path('~/robot').expanduser()
TARGET.mkdir(exist_ok=True)


def sorted_nicely(paths: List[Path]) -> List[Path]:
# https://stackoverflow.com/a/2669120/3419103
Expand Down Expand Up @@ -52,15 +49,16 @@ def remove_package(path: Path) -> None:

async def install_package(path: Path) -> None:
logging.info(f'Extracting {path}...')
shutil.rmtree(TARGET)
target = Path(app.storage.general['target_directory']).expanduser()
shutil.rmtree(target)
with zipfile.ZipFile(path, 'r') as zip_ref:
members = zip_ref.infolist()
for member in members:
extracted_path = zip_ref.extract(member, TARGET)
extracted_path = zip_ref.extract(member, target)
os.chmod(extracted_path, member.external_attr >> 16)
logging.info('...done!')

Path(TARGET / '.env').write_text(app.storage.general.get('env', ''))
Path(target / '.env').write_text(app.storage.general.get('env', ''))

logging.info('Running install script...')
with ui.dialog(value=True).props('maximized persistent') as dialog, ui.card():
Expand All @@ -71,7 +69,7 @@ async def install_package(path: Path) -> None:
close_button = ui.button(icon='close', on_click=dialog.close).props('flat round color=gray-500')
close_button.visible = False
log = ui.log().classes('h-full')
await run_sh(f'cd {TARGET}; ./install.sh', log)
await run_sh(f'cd {target}; ./install.sh', log)
spinner.visible = False
close_button.visible = True
ui.notification('Installation complete', icon='done', type='positive')
Expand Down

0 comments on commit c04a645

Please sign in to comment.