diff --git a/scripts/3-report/gcs_report.py b/scripts/3-report/gcs_report.py index eb9130fe..17884dff 100755 --- a/scripts/3-report/gcs_report.py +++ b/scripts/3-report/gcs_report.py @@ -59,6 +59,11 @@ def parse_arguments(): help="Enable git actions such as fetch, merge, add, commit, and push" " (default: False)", ) + parser.add_argument( + "--force", + action="store_true", + help="Regenerate data even if report files exist", + ) args = parser.parse_args() if not args.enable_save and args.enable_git: parser.error("--enable-git requires --enable-save") @@ -70,6 +75,23 @@ def parse_arguments(): return args +def check_report_completion(args): + """ " + The function checks for the last plot and image + caption created in this script. This helps to + immediately know if all plots in the script have + been created and should not be regenerated. + + """ + if args.force: + return + last_entry = shared.path_join(PATHS["data_phase"], "gcs_free_culture.png") + if os.path.exists(last_entry): + raise shared.QuantifyingException( + f"{last_entry} already exists. Report script completed", 0 + ) + + def gcs_intro(args): """ Write Google Custom Search (GCS) introduction. @@ -491,7 +513,7 @@ def main(): args = parse_arguments() shared.paths_log(LOGGER, PATHS) shared.git_fetch_and_merge(args, PATHS["repo"]) - + check_report_completion(args) gcs_intro(args) plot_products(args) plot_tool_status(args) diff --git a/scripts/3-report/github_report.py b/scripts/3-report/github_report.py index 958dcc40..f918842b 100755 --- a/scripts/3-report/github_report.py +++ b/scripts/3-report/github_report.py @@ -62,6 +62,11 @@ def parse_arguments(): action="store_true", help="Regenerate data even if images files already exist", ) + parser.add_argument( + "--force", + action="store_true", + help="Regenerate data even if report files exist", + ) args = parser.parse_args() if not args.enable_save and args.enable_git: parser.error("--enable-git requires --enable-save") @@ -73,6 +78,25 @@ def parse_arguments(): return args +def check_report_completion(args): + """ " + The function checks for the last plot and image + caption created in this script. This helps to + immediately know if all plots in the script have + been created and should not be regenerated. + + """ + if args.force: + return + last_entry = shared.path_join( + PATHS["data_phase"], "github_restriction.png" + ) + if os.path.exists(last_entry): + raise shared.QuantifyingException( + f"{last_entry} already exists. Report script completed", 0 + ) + + def load_data(args): """ Load the collected data from the CSV file. @@ -243,6 +267,7 @@ def main(): args = parse_arguments() shared.paths_log(LOGGER, PATHS) shared.git_fetch_and_merge(args, PATHS["repo"]) + check_report_completion(args) github_intro(args) plot_totals_by_license_type(args) plot_totals_by_restriction(args) diff --git a/scripts/3-report/wikipedia_report.py b/scripts/3-report/wikipedia_report.py index 9224bcb6..51c7d121 100755 --- a/scripts/3-report/wikipedia_report.py +++ b/scripts/3-report/wikipedia_report.py @@ -57,6 +57,11 @@ def parse_arguments(): help="Enable git actions such as fetch, merge, add, commit, and push" " (default: False)", ) + parser.add_argument( + "--force", + action="store_true", + help="Regenerate data even if report files exist", + ) args = parser.parse_args() if not args.enable_save and args.enable_git: parser.error("--enable-git requires --enable-save") @@ -68,6 +73,25 @@ def parse_arguments(): return args +def check_report_completion(args): + """ " + The function checks for the last plot and image + caption created in this script. This helps to + immediately know if all plots in the script have + been created and should not be regenerated. + + """ + if args.force: + return + last_entry = shared.path_join( + PATHS["data_phase"], "wikipedia_least_language_usage.png" + ) + if os.path.exists(last_entry): + raise shared.QuantifyingException( + f"{last_entry} already exists. Report script completed", 0 + ) + + def wikipedia_intro(args): """ Write Wikipedia introduction. @@ -261,6 +285,7 @@ def main(): args = parse_arguments() shared.paths_log(LOGGER, PATHS) shared.git_fetch_and_merge(args, PATHS["repo"]) + check_report_completion(args) wikipedia_intro(args) plot_language_representation(args) plot_highest_language_usage(args)