diff --git a/application/main.py b/application/main.py index 9b1ebfa..fcabb9f 100644 --- a/application/main.py +++ b/application/main.py @@ -32,6 +32,7 @@ read_changelog, read_latest_version_fetch, time_since_last_fetch, + update_changelog, write_latest_version_fetch, ) from application.widget.containers import PockerContainers @@ -512,40 +513,39 @@ def cli(ctx): @cli.command() @click.option("--force", "-f", is_flag=True, help="Force update.") def update(force): - current_version = parse(get_current_version()) - latest_version = None - if time_since_last_fetch() < 5 and not force: print( f"⚠️ {Fore.YELLOW}Updating too often might lead to being rate-limited.{Style.RESET_ALL}\n" "Pass --force or -f to force update." ) return - else: - latest_version = get_latest_version() - write_latest_version_fetch(latest_version.base_version) - if latest_version is not None and latest_version > current_version: + current_version = parse(get_current_version()) + latest_version = get_latest_version() + write_latest_version_fetch(latest_version.base_version) + + if latest_version > current_version: with yaspin(text=f"Updating to v{latest_version}", timer=True) as sp: result = subprocess.run( - [ - "pipx", - "install", - "git+https://github.com/pommee/Pocker@main", - "--force", - ], + ["pipx", "install", "pocker-tui", "--force"], text=True, capture_output=True, check=True, ) - sp.ok() - if "installed package pocker" in result.stdout: + sp.ok(text="[DONE]") + if "installed package pocker-tui" in result.stdout: click.echo( - f"Pocker is now updated from{Fore.LIGHTYELLOW_EX} v{current_version}{Style.RESET_ALL}{Fore.LIGHTGREEN_EX} -> v{latest_version}{Style.RESET_ALL}" + f"Pocker updated from{Fore.LIGHTYELLOW_EX} v{current_version}{Style.RESET_ALL}" + f"{Fore.LIGHTGREEN_EX} -> v{latest_version}{Style.RESET_ALL}" ) + update_changelog() read_changelog(current_version) - return - if latest_version == current_version: - print( - f"{Fore.LIGHTGREEN_EX}Already running latest (v{latest_version}){Style.RESET_ALL}" - ) + return + + print("An error occured!") + print("STDOUT: ", result.stdout) + print("STDERR: ", result.stderr) + + print( + f"{Fore.LIGHTGREEN_EX}Already running latest (v{latest_version}){Style.RESET_ALL}" + ) diff --git a/application/util/helper.py b/application/util/helper.py index 1ab4c35..6a1e49a 100644 --- a/application/util/helper.py +++ b/application/util/helper.py @@ -33,7 +33,7 @@ def get_current_version(): ) for line in result.stdout.splitlines(): - if "pocker" in line: + if "pocker-tui" in line: version = line.split()[1] return version @@ -167,3 +167,13 @@ def read_changelog(previously_installed_version): release.print_bug_fixes() print("") + + +def update_changelog(): + response = requests.get( + "https://raw.githubusercontent.com/pommee/Pocker/main/CHANGELOG.md" + ) + if response.status_code == 200: + file_path = POCKER_CONFIG_BASE_PATH / "CHANGELOG.md" + with open(file_path, "w") as file: + file.write(response.text) diff --git a/application/widget/help.py b/application/widget/help.py index 4f04bf4..ef5e895 100644 --- a/application/widget/help.py +++ b/application/widget/help.py @@ -71,7 +71,7 @@ def compose(self) -> ComposeResult: with Center(): yield Static(get_title(), id="title", classes="title") yield Markdown(HELP_MD, id="help", classes="help") - yield Markdown(self.read_changelog(), id="changelog", classes="changelog") + yield Markdown(self._read_changelog(), id="changelog", classes="changelog") @on(Markdown.LinkClicked) def on_markdown_link_clicked(self, event: Markdown.LinkClicked) -> None: @@ -80,7 +80,7 @@ def on_markdown_link_clicked(self, event: Markdown.LinkClicked) -> None: def action_go(self, href: str) -> None: webbrowser.open(href) - def read_changelog(self): + def _read_changelog(self): file_path = POCKER_CONFIG_BASE_PATH / "CHANGELOG.md" if not file_path.exists(): response = requests.get(