From eefa958b3e2e8ab64685f089036a47f70759e6fd Mon Sep 17 00:00:00 2001 From: shashank40 Date: Wed, 19 Jun 2024 20:54:28 +0530 Subject: [PATCH] Added functionality to unzip --- openadapt/app/tray.py | 10 ++++------ openadapt/build_utils.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/openadapt/app/tray.py b/openadapt/app/tray.py index 470021453..459ac71ba 100644 --- a/openadapt/app/tray.py +++ b/openadapt/app/tray.py @@ -13,7 +13,6 @@ import os import sys import requests -from urllib.parse import urlparse import threading from tqdm import tqdm @@ -42,7 +41,7 @@ from openadapt.app.dashboard.run import cleanup as cleanup_dashboard from openadapt.app.dashboard.run import run as run_dashboard from openadapt.app.main import FPATH # , start -from openadapt.build_utils import is_running_from_executable +from openadapt.build_utils import is_running_from_executable, unzip_file from openadapt.db import crud from openadapt.models import Recording from openadapt.replay import replay @@ -197,17 +196,15 @@ def download_latest_version(self, base_url: str, latest_version: str) -> None: FILE_NAME = f"OpenAdapt-v{latest_version}.zip" DOWNLOAD_URL = base_url + f"/v{latest_version}/{FILE_NAME}" - parsed_url = urlparse(DOWNLOAD_URL) - filename = os.path.basename(parsed_url.path) downloads_path = os.path.join(os.path.expanduser("~"), "Downloads") - local_filename = os.path.join(downloads_path, filename) + local_filename = os.path.join(downloads_path, FILE_NAME) response = requests.get(DOWNLOAD_URL, stream=True) total_size = response.headers.get('content-length') total_size = int(total_size) if total_size else None block_size = 1024 # 1 Kilobyte with open(local_filename, 'wb') as file, tqdm( - total=total_size, unit='B', unit_scale=True, desc=filename + total=total_size, unit='B', unit_scale=True, desc=FILE_NAME ) as progress_bar: for data in response.iter_content(block_size): if CANCEL_APP_DOWNLOAD: @@ -215,6 +212,7 @@ def download_latest_version(self, base_url: str, latest_version: str) -> None: break file.write(data) progress_bar.update(len(data)) + unzip_file(local_filename) def check_and_download_latest_version(self) -> None: diff --git a/openadapt/build_utils.py b/openadapt/build_utils.py index 36d748725..575cb125d 100644 --- a/openadapt/build_utils.py +++ b/openadapt/build_utils.py @@ -3,7 +3,20 @@ import os import pathlib import sys +import shutil +def set_permissions(path): + for root, dirs, files in os.walk(path): + for dir in dirs: + os.chmod(os.path.join(root, dir), 0o755) + for file in files: + os.chmod(os.path.join(root, file), 0o755) + +def unzip_file(file_path: str) -> None: + if os.path.exists(file_path): + shutil.unpack_archive(file_path, os.path.dirname(file_path)) + set_permissions(os.path.dirname(file_path)) + print("Unzipped") def get_root_dir_path() -> pathlib.Path: """Get the path to the project root directory."""