diff --git a/README.md b/README.md index a44bca9b..9481c5a2 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ There are for the moment two possible checks: 1) Dependency checker
Check for module dependencies status and change their status accordingly. -2) Weekly Pmodules checker
- Report new, deleted or changed modules and write it to a pmodules_changes.md file. +2) Pmodules Database checker
+ Report new, deleted or changed modules, write it to the database and print changes to pmodules_changes.md. ## Usage On Merlin need to first load a Python3: @@ -33,8 +33,8 @@ python3 pmodules_tools/pmodules_tools.py --help python3 pmodules_tools/pmodules_tools.py --deps-check # or -d ``` -### Weekly Pmodules checker +### Pmodules Database checker ```sh -python3 pmodules_tools/pmodules_tools.py --weekly-check # or -w +python3 pmodules_tools/pmodules_tools.py --db-check # or -w ``` diff --git a/pmodules_tools/weekly_diff/__init__.py b/pmodules_tools/db_diff/__init__.py similarity index 100% rename from pmodules_tools/weekly_diff/__init__.py rename to pmodules_tools/db_diff/__init__.py diff --git a/pmodules_tools/weekly_diff/check.py b/pmodules_tools/db_diff/check.py similarity index 98% rename from pmodules_tools/weekly_diff/check.py rename to pmodules_tools/db_diff/check.py index 77ee2d7b..f84b4a8e 100644 --- a/pmodules_tools/weekly_diff/check.py +++ b/pmodules_tools/db_diff/check.py @@ -5,6 +5,41 @@ import re import shutil +def db_check_diff(current_pmodule_state, Pmodules_db_path, Pmodules_states): + current_sha = hashlib.sha256(current_pmodule_state.encode()).hexdigest() + + no_current_db = False + + # Retrieve old state for comparison + try: + old_pmodule_file = sorted( + [Pmodules_db_path + f for f in os.listdir(Pmodules_db_path)], + key=os.path.getctime, + )[0] + old_pmodule_state = open(old_pmodule_file, "r").read() + except: + print( + "There is no old Pmodule database available on path " + + Pmodules_db_path + + "... Writing current one" + ) + no_current_db = True + + # There is a database and we have to check the differences between the pmodule states. + if not no_current_db and compare_states_sha( + current_pmodule_state, old_pmodule_state, current_sha + ): + print_pmodules_differences( + current_pmodule_state, old_pmodule_state, Pmodules_states + ) + + # There is no database available or there are differences with the old pmodule state, writing current state. + if no_current_db or compare_states_sha( + current_pmodule_state, old_pmodule_state, current_sha + ): + write_curent_state(current_pmodule_state, current_sha, Pmodules_db_path) + + def compare_states_sha(current_pmodule_state, old_pmodule_state, current_sha): if (len(old_pmodule_state)) != 0: old_sha = hashlib.sha256(old_pmodule_state.encode()).hexdigest() @@ -111,41 +146,6 @@ def standard_print(file, module_list, string): file.write(diff + "
") -def weekly_check_diff(current_pmodule_state, Pmodules_db_path, Pmodules_states): - current_sha = hashlib.sha256(current_pmodule_state.encode()).hexdigest() - - no_current_db = False - - # Retrieve old state for comparison - try: - old_pmodule_file = sorted( - [Pmodules_db_path + f for f in os.listdir(Pmodules_db_path)], - key=os.path.getctime, - )[0] - old_pmodule_state = open(old_pmodule_file, "r").read() - except: - print( - "There is no old Pmodule database available on path " - + Pmodules_db_path - + "... Writing current one" - ) - no_current_db = True - - # There is a database and we have to check the differences between the pmodule states. - if not no_current_db and compare_states_sha( - current_pmodule_state, old_pmodule_state, current_sha - ): - print_pmodules_differences( - current_pmodule_state, old_pmodule_state, Pmodules_states - ) - - # There is no database available or there are differences with the old pmodule state, writing current state. - if no_current_db or compare_states_sha( - current_pmodule_state, old_pmodule_state, current_sha - ): - write_curent_state(current_pmodule_state, current_sha, Pmodules_db_path) - - def write_curent_state(current_pmodule_state, current_sha, Pmodules_db_path): # Emptying Pmodules database first if os.path.exists(Pmodules_db_path): diff --git a/pmodules_tools/pmodules_tools.py b/pmodules_tools/pmodules_tools.py index 1c81704a..1af971c7 100644 --- a/pmodules_tools/pmodules_tools.py +++ b/pmodules_tools/pmodules_tools.py @@ -2,8 +2,9 @@ import argparse import sys from datetime import date +from db_diff.check import db_check_diff from deps_status.check import deps_status_check, subprocess_cmd -from weekly_diff.check import weekly_check_diff + assert sys.version_info >= ( 3, @@ -23,9 +24,9 @@ def parse_args(): ) parser.add_argument( "-w", - "--weekly-check", + "--db-check", action="store_true", - help="Report new, deleted or changed modules and print it to pmodules_changes.md.", + help="Report new, deleted or changed modules, write it to the database and print changes to pmodules_changes.md.", ) parser.add_argument( "--select-module", @@ -52,8 +53,8 @@ def main(): module_cmd_process = subprocess_cmd(module_cmd) # Check for Pmodules addition, deletion or changes of state - if cli_args.weekly_check: - weekly_check_diff(module_cmd_process.stderr, Pmodules_db_path, Pmodules_states) + 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: