Add option for checking if hook is enabled in config file
This commit is contained in:
parent
e59bde6cd1
commit
9a876aa31d
@ -4,6 +4,13 @@ Changelog for packaging-scripts
|
|||||||
Version 1.6.0
|
Version 1.6.0
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
* pug2
|
||||||
|
|
||||||
|
* Add --check-if-enabled option for running with pacman hook
|
||||||
|
|
||||||
|
Version 1.6.0
|
||||||
|
-------------
|
||||||
|
|
||||||
* pug2
|
* pug2
|
||||||
|
|
||||||
* Print error messages from gist when necessary
|
* Print error messages from gist when necessary
|
||||||
|
16
bin/pug2
16
bin/pug2
@ -7,6 +7,7 @@ Dependencies
|
|||||||
* gist
|
* gist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -20,7 +21,7 @@ DEFAULT_FILENAME = "pacman-packages.txt"
|
|||||||
# Config file options
|
# Config file options
|
||||||
CONFIG_SECTION = "pug2"
|
CONFIG_SECTION = "pug2"
|
||||||
CONFIG_OPTION_DESCRIPTION = "GIST_DESCRIPTION"
|
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_FILENAME = "GIST_FILENAME"
|
||||||
CONFIG_OPTION_ID = "GIST_ID"
|
CONFIG_OPTION_ID = "GIST_ID"
|
||||||
|
|
||||||
@ -70,11 +71,22 @@ def package_lists_match(gist_id):
|
|||||||
|
|
||||||
# ========== Main Script ==========
|
# ========== Main Script ==========
|
||||||
if __name__ == "__main__":
|
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 = configparser.ConfigParser()
|
||||||
config.read(CONFIG_FILE)
|
config.read(CONFIG_FILE)
|
||||||
|
|
||||||
# Check if script is enabled to run; if not, exit silently
|
# 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)
|
sys.exit(0)
|
||||||
|
|
||||||
gist_description = config.get(CONFIG_SECTION, CONFIG_OPTION_DESCRIPTION)
|
gist_description = config.get(CONFIG_SECTION, CONFIG_OPTION_DESCRIPTION)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Note that empty options are left without quotes
|
# Note that empty options are left without quotes
|
||||||
[pug2]
|
[pug2]
|
||||||
# Activate pug script upon running pug ALPM hook
|
# Activate pug script upon running pug ALPM hook
|
||||||
GIST_PUG_ENABLE = no
|
RUN_ON_PACMAN_HOOK = no
|
||||||
|
|
||||||
# Name for gist
|
# Name for gist
|
||||||
# Default: pacman-packages.txt
|
# Default: pacman-packages.txt
|
||||||
|
@ -9,4 +9,4 @@ Target = *
|
|||||||
Depends = coreutils
|
Depends = coreutils
|
||||||
Depends = packaging-scripts
|
Depends = packaging-scripts
|
||||||
When = PostTransaction
|
When = PostTransaction
|
||||||
Exec = /usr/bin/pug2
|
Exec = /usr/bin/pug2 --check-if-enabled
|
||||||
|
Loading…
x
Reference in New Issue
Block a user