Fix comments in has_update
This commit is contained in:
parent
931ddcaea2
commit
0c4b98024a
|
@ -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 <echolib+tools@a-lec.org>
|
||||
|
||||
|
@ -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}")
|
||||
|
||||
|
|
Loading…
Reference in New Issue