Add option for checking if hook is enabled in config file

This commit is contained in:
Eric Torres 2022-03-24 18:49:45 -07:00
parent e59bde6cd1
commit 9a876aa31d
4 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -9,4 +9,4 @@ Target = *
Depends = coreutils
Depends = packaging-scripts
When = PostTransaction
Exec = /usr/bin/pug2
Exec = /usr/bin/pug2 --check-if-enabled