From 9a876aa31d2fef7af8f2703996e6285484da171b Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Thu, 24 Mar 2022 18:49:45 -0700 Subject: [PATCH] Add option for checking if hook is enabled in config file --- CHANGELOG.rst | 7 +++++++ bin/pug2 | 16 ++++++++++++++-- misc/packaging-scripts.conf | 2 +- misc/pug.hook | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 54133c7..c2939c1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,13 @@ Changelog for packaging-scripts Version 1.6.0 ------------- +* pug2 + + * Add --check-if-enabled option for running with pacman hook + +Version 1.6.0 +------------- + * pug2 * Print error messages from gist when necessary diff --git a/bin/pug2 b/bin/pug2 index e9dbe24..8e4a635 100644 --- a/bin/pug2 +++ b/bin/pug2 @@ -7,6 +7,7 @@ Dependencies * gist """ +import argparse import configparser import re import subprocess @@ -20,7 +21,7 @@ DEFAULT_FILENAME = "pacman-packages.txt" # Config file options CONFIG_SECTION = "pug2" CONFIG_OPTION_DESCRIPTION = "GIST_DESCRIPTION" -CONFIG_OPTION_ENABLE = "GIST_PUG_ENABLE" +CONFIG_OPTION_ENABLE = "RUN_ON_PACMAN_HOOK" CONFIG_OPTION_FILENAME = "GIST_FILENAME" CONFIG_OPTION_ID = "GIST_ID" @@ -70,11 +71,22 @@ def package_lists_match(gist_id): # ========== Main Script ========== if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-c", + "--check-if-enabled", + dest="check_enabled", + help="check if enabled in config file", + action="store_true", + ) + args = parser.parse_args() config = configparser.ConfigParser() config.read(CONFIG_FILE) # Check if script is enabled to run; if not, exit silently - if not config.getboolean(CONFIG_SECTION, CONFIG_OPTION_ENABLE): + if args.check_enabled and not config.getboolean( + CONFIG_SECTION, CONFIG_OPTION_ENABLE + ): sys.exit(0) gist_description = config.get(CONFIG_SECTION, CONFIG_OPTION_DESCRIPTION) diff --git a/misc/packaging-scripts.conf b/misc/packaging-scripts.conf index fde555c..d49a763 100644 --- a/misc/packaging-scripts.conf +++ b/misc/packaging-scripts.conf @@ -2,7 +2,7 @@ # Note that empty options are left without quotes [pug2] # Activate pug script upon running pug ALPM hook -GIST_PUG_ENABLE = no +RUN_ON_PACMAN_HOOK = no # Name for gist # Default: pacman-packages.txt diff --git a/misc/pug.hook b/misc/pug.hook index 6e6a9a1..6a6e2a2 100644 --- a/misc/pug.hook +++ b/misc/pug.hook @@ -9,4 +9,4 @@ Target = * Depends = coreutils Depends = packaging-scripts When = PostTransaction -Exec = /usr/bin/pug2 +Exec = /usr/bin/pug2 --check-if-enabled