Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
Formatting fixes
  • Loading branch information
shashank40 committed Jun 20, 2024
1 parent fa4a33a commit d1c2604
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions build_scripts/get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
import requests
import json

APP_VERSION_URL = "https://api.github.com/repos/OpenAdaptAI/OpenAdapt/releases?per_page=10&page=1"
APP_VERSION_URL = (
"https://api.github.com/repos/OpenAdaptAI/OpenAdapt/releases?per_page=10&page=1"
)


def get_version() -> str:
"""Get the version of the package."""
return importlib.metadata.version("openadapt")


def get_latest_version() -> str:
"""Get the latest version of the app available."""
response = requests.get(APP_VERSION_URL, stream=True)
data = json.loads(response.text)
return data[0]['tag_name'].replace('v', '')
return data[0]["tag_name"].replace("v", "")


if __name__ == "__main__":
print(get_version())
8 changes: 5 additions & 3 deletions openadapt/app/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ def _quit() -> None:
self.launch_dashboard()

def stop_download(self) -> None:
"""Stops download when button clicked."""
global CANCEL_APP_DOWNLOAD
self.show_toast("Stopping download...", duration=4000)
CANCEL_APP_DOWNLOAD = True

def download_latest_version(self, base_url: str, latest_version: str) -> None:
"""Download latest version of the app."""
global CANCEL_APP_DOWNLOAD

DOWNLOAD_URL = ""
Expand All @@ -219,14 +221,13 @@ def download_latest_version(self, base_url: str, latest_version: str) -> None:
for data in response.iter_content(block_size):
if CANCEL_APP_DOWNLOAD:
CANCEL_APP_DOWNLOAD = False
break
return
file.write(data)
progress_bar.update(len(data))
unzip_file(local_filename)

def check_and_download_latest_version(self) -> None:
"""Check and Download latest version"""

"""Checks and Download latest version."""
if Version(CURRENT_VERSION) >= Version(LATEST_VERSION):
self.show_toast("You are already on the latest version.")
return
Expand All @@ -241,6 +242,7 @@ def check_and_download_latest_version(self) -> None:
self.show_toast("After download, use the latest app version", duration=10000)

def download_latest_app_version(self) -> None:
"""Main function called when download button is clicked. This calls the necessary function according to the condition."""
global CANCEL_APP_DOWNLOAD

if self.download_update_action.text() == "Stop Download":
Expand Down
7 changes: 6 additions & 1 deletion openadapt/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
import sys
import shutil

def set_permissions(path):

def set_permissions(path: str) -> None:
"""Set the permissions of all files to make the executable."""
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:
"""Unzip a file to the given directory."""
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."""
if not is_running_from_executable():
Expand Down

0 comments on commit d1c2604

Please sign in to comment.