FIX: change name weekly-check to db-check

This commit is contained in:
2023-02-06 11:16:11 +00:00
parent 3052bbefa1
commit 6299d3d691
4 changed files with 45 additions and 44 deletions

View File

@ -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 + "<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):
# Emptying Pmodules database first
if os.path.exists(Pmodules_db_path):

View File

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