diff --git a/tools/has_update b/tools/has_update index b2dcdf4..7043d9c 100644 --- a/tools/has_update +++ b/tools/has_update @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# version: 0.1 -# File: /srv/toot/has_update +# version: 0.2 +# File: /srv/toot/tools/has_update # Copyright (C) 2023 Cyrille Louarn @@ -47,10 +47,13 @@ repo = f"https://api.github.com/repos/{owner}/{name}/releases/latest" # VLH (Very Little Help) helps = """Usage: has_update [argument] +! With no argument, a message is ouput ONLY if an update is available + -h : This help ! -v : Show both versions (online, and installed) """ + #=====================================================# # Check available version using Git API with requests # #-----------------------------------------------------# @@ -77,12 +80,12 @@ def get_installed_release(): text=True, # Set stdout + stderr check=True # exception if failure ) - - # Output captured successfully + + # Output if success return result.stdout.strip() - + + # Command failed except subprocess.CalledProcessError as e: - # Handle the case where the command fails print("Failed to get installed release:", e.stderr.strip()) sys.exit(2) @@ -91,11 +94,12 @@ def get_installed_release(): # Main # #------# -# With -h argument, show both versions +# With -h argument, show help only if '-h' in sys.argv: print(helps) sys.exit(0) + # Get versions (online and local) available_version = get_available_release() installed_version = get_installed_release() @@ -106,7 +110,7 @@ if '-v' in sys.argv: print(f"{owner}:") print(f"- Available: {available_version}\n- Installed: {installed_version}") -# A new version is available +# Show message if a new version is available elif available_version != installed_version: print(f"{owner}: {installed_version} -> {available_version}")