Merge branch 'fix_name' into 'master'

FIX: change name weekly-check to db-check

See merge request Pmodules/dependency-checker!4
This commit is contained in:
2023-02-06 11:16:11 +00:00
4 changed files with 45 additions and 44 deletions

View File

@ -11,8 +11,8 @@ There are for the moment two possible checks:
1) Dependency checker <br> 1) Dependency checker <br>
Check for module dependencies status and change their status accordingly. Check for module dependencies status and change their status accordingly.
2) Weekly Pmodules checker <br> 2) Pmodules Database checker <br>
Report new, deleted or changed modules and write it to a pmodules_changes.md file. Report new, deleted or changed modules, write it to the database and print changes to pmodules_changes.md.
## Usage ## Usage
On Merlin need to first load a Python3: 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 python3 pmodules_tools/pmodules_tools.py --deps-check # or -d
``` ```
### Weekly Pmodules checker ### Pmodules Database checker
```sh ```sh
python3 pmodules_tools/pmodules_tools.py --weekly-check # or -w python3 pmodules_tools/pmodules_tools.py --db-check # or -w
``` ```

View File

@ -5,6 +5,41 @@ import re
import shutil 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): def compare_states_sha(current_pmodule_state, old_pmodule_state, current_sha):
if (len(old_pmodule_state)) != 0: if (len(old_pmodule_state)) != 0:
old_sha = hashlib.sha256(old_pmodule_state.encode()).hexdigest() old_sha = hashlib.sha256(old_pmodule_state.encode()).hexdigest()
@ -111,41 +146,6 @@ def standard_print(file, module_list, string):
file.write(diff + "<br>") file.write(diff + "<br>")
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): def write_curent_state(current_pmodule_state, current_sha, Pmodules_db_path):
# Emptying Pmodules database first # Emptying Pmodules database first
if os.path.exists(Pmodules_db_path): if os.path.exists(Pmodules_db_path):

View File

@ -2,8 +2,9 @@ import argparse
import sys import sys
from datetime import date from datetime import date
from db_diff.check import db_check_diff
from deps_status.check import deps_status_check, subprocess_cmd from deps_status.check import deps_status_check, subprocess_cmd
from weekly_diff.check import weekly_check_diff
assert sys.version_info >= ( assert sys.version_info >= (
3, 3,
@ -23,9 +24,9 @@ def parse_args():
) )
parser.add_argument( parser.add_argument(
"-w", "-w",
"--weekly-check", "--db-check",
action="store_true", 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( parser.add_argument(
"--select-module", "--select-module",
@ -52,8 +53,8 @@ def main():
module_cmd_process = subprocess_cmd(module_cmd) module_cmd_process = subprocess_cmd(module_cmd)
# Check for Pmodules addition, deletion or changes of state # Check for Pmodules addition, deletion or changes of state
if cli_args.weekly_check: if cli_args.db_check:
weekly_check_diff(module_cmd_process.stderr, Pmodules_db_path, Pmodules_states) db_check_diff(module_cmd_process.stderr, Pmodules_db_path, Pmodules_states)
# Check for module dependencies status and change the main module status accordingly # Check for module dependencies status and change the main module status accordingly
if cli_args.deps_check: if cli_args.deps_check: