Pmodules_tools/pmodules_tools/pmodules_tools.py

67 lines
1.8 KiB
Python

import argparse
import sys
from db_diff.check import db_check_diff
from deps_status.check import deps_status_check, subprocess_cmd
assert sys.version_info >= (
3,
7,
), "Python version is too low, please load a python >= 3.7"
def parse_args():
parser = argparse.ArgumentParser(
description="A python project to analyse Pmodules modules and their status changes."
)
parser.add_argument(
"-d",
"--deps-check",
action="store_true",
help="Check for module dependencies status and change their status accordingly.",
)
parser.add_argument(
"-w",
"--db-check",
action="store_true",
help="Report new, deleted or changed modules, write it to the database and print changes to pmodules_changes.md.",
)
parser.add_argument(
"--select-module",
default="",
help="Select a subtype of module which should be checked for. Default is all.",
)
args = parser.parse_args()
return args
def main():
# Analyse CLI args
cli_args = parse_args()
# Global variables
Pmodules_db_path = "/opt/psi/var/cache/pmodules_db/"
Pmodules_states = [" stable", " unstable", " deprecated"]
# Main search to analyse
module_cmd = (
"$PMODULES_HOME/bin/modulecmd bash search -a "
+ cli_args.select_module
+ " --all-deps --no-header"
)
module_cmd_process = subprocess_cmd(module_cmd)
# Check for Pmodules addition, deletion or changes of state
if cli_args.db_check:
db_check_diff(module_cmd_process.stderr, Pmodules_db_path, Pmodules_states)
# Check for module dependencies status and change the main module status accordingly
if cli_args.deps_check:
deps_status_check(module_cmd_process)
if __name__ == "__main__":
main()