From 7bedb53f6578358cfa56f254eddf0d4544b8837f Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Thu, 24 Mar 2022 13:01:28 -0700 Subject: [PATCH] Print error messages when necessary --- CHANGELOG.rst | 8 ++++++++ bin/pug2 | 45 ++++++++++++++++++++++++++++++++------------- misc/pug.hook | 1 + 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 367a52b..2514b98 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ Changelog for packaging-scripts =============================== +Version 1.6.0 +------------- + +* pug2 + + * Print error messages from gist when necessary + + Version 1.5.3 ------------- diff --git a/bin/pug2 b/bin/pug2 index 058d1d0..e9dbe24 100644 --- a/bin/pug2 +++ b/bin/pug2 @@ -82,20 +82,39 @@ if __name__ == "__main__": gist_id = config.get(CONFIG_SECTION, CONFIG_OPTION_ID) if gist_id == "": - print("No gist ID detected, creating new.") - gist_process = subprocess.run( - f"pacman -Qqen | gist --filename {gist_filename} --description {gist_description}", - capture_output=True, - shell=True, - ) - config[CONFIG_SECTION][CONFIG_OPTION_ID] = extract_gist_id(gist_process.stdout) + try: + print("No gist ID detected, creating new.") + gist_process = subprocess.run( + f"pacman -Qqen | gist --filename {gist_filename} --description {gist_description}", + capture_output=True, + text=True, + shell=True, + check=True, + ) + except subprocess.CalledProcessError as e: + print(e.stdout.strip(), file=sys.stderr) + sys.exit(e.returncode) + else: + config[CONFIG_SECTION][CONFIG_OPTION_ID] = extract_gist_id( + gist_process.stdout + ) + print("Gist creation complete.") + elif package_lists_match(gist_id): print("Package lists match, no update necessary.") sys.exit(0) else: - print("Package lists differ, updating.") - subprocess.run( - f"pacman -Qqen | gist --update {gist_id} --filename {gist_filename} --description {gist_description}", - capture_output=True, - shell=True, - ) + try: + print("Package lists differ, updating.") + subprocess.run( + f"pacman -Qqen | gist --update {gist_id} --filename {gist_filename} --description {gist_description}", + capture_output=True, + text=True, + shell=True, + check=True, + ) + except subprocess.CalledProcessError as e: + print(e.stdout.strip(), file=sys.stderr) + sys.exit(e.returncode) + else: + print("Update complete.") diff --git a/misc/pug.hook b/misc/pug.hook index 183e40f..6e6a9a1 100644 --- a/misc/pug.hook +++ b/misc/pug.hook @@ -7,5 +7,6 @@ Target = * [Action] Depends = coreutils +Depends = packaging-scripts When = PostTransaction Exec = /usr/bin/pug2