Skip to content

Commit

Permalink
fix: update command now installs via pipx
Browse files Browse the repository at this point in the history
  • Loading branch information
pommee committed Aug 22, 2024
1 parent 98cb9fd commit b9a272d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
42 changes: 21 additions & 21 deletions application/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
)
12 changes: 11 additions & 1 deletion application/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions application/widget/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit b9a272d

Please sign in to comment.