Skip to content

Commit dae9e83

Browse files
authored
Merge pull request #270 from oree-xx/report_scripts
Checks for last entry in the report script
2 parents 0787051 + 36fd3aa commit dae9e83

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

scripts/3-report/gcs_report.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def parse_arguments():
5959
help="Enable git actions such as fetch, merge, add, commit, and push"
6060
" (default: False)",
6161
)
62+
parser.add_argument(
63+
"--force",
64+
action="store_true",
65+
help="Regenerate data even if report files exist",
66+
)
6267
args = parser.parse_args()
6368
if not args.enable_save and args.enable_git:
6469
parser.error("--enable-git requires --enable-save")
@@ -70,6 +75,23 @@ def parse_arguments():
7075
return args
7176

7277

78+
def check_report_completion(args):
79+
""" "
80+
The function checks for the last plot and image
81+
caption created in this script. This helps to
82+
immediately know if all plots in the script have
83+
been created and should not be regenerated.
84+
85+
"""
86+
if args.force:
87+
return
88+
last_entry = shared.path_join(PATHS["data_phase"], "gcs_free_culture.png")
89+
if os.path.exists(last_entry):
90+
raise shared.QuantifyingException(
91+
f"{last_entry} already exists. Report script completed", 0
92+
)
93+
94+
7395
def gcs_intro(args):
7496
"""
7597
Write Google Custom Search (GCS) introduction.
@@ -491,7 +513,7 @@ def main():
491513
args = parse_arguments()
492514
shared.paths_log(LOGGER, PATHS)
493515
shared.git_fetch_and_merge(args, PATHS["repo"])
494-
516+
check_report_completion(args)
495517
gcs_intro(args)
496518
plot_products(args)
497519
plot_tool_status(args)

scripts/3-report/github_report.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def parse_arguments():
6262
action="store_true",
6363
help="Regenerate data even if images files already exist",
6464
)
65+
parser.add_argument(
66+
"--force",
67+
action="store_true",
68+
help="Regenerate data even if report files exist",
69+
)
6570
args = parser.parse_args()
6671
if not args.enable_save and args.enable_git:
6772
parser.error("--enable-git requires --enable-save")
@@ -73,6 +78,25 @@ def parse_arguments():
7378
return args
7479

7580

81+
def check_report_completion(args):
82+
""" "
83+
The function checks for the last plot and image
84+
caption created in this script. This helps to
85+
immediately know if all plots in the script have
86+
been created and should not be regenerated.
87+
88+
"""
89+
if args.force:
90+
return
91+
last_entry = shared.path_join(
92+
PATHS["data_phase"], "github_restriction.png"
93+
)
94+
if os.path.exists(last_entry):
95+
raise shared.QuantifyingException(
96+
f"{last_entry} already exists. Report script completed", 0
97+
)
98+
99+
76100
def load_data(args):
77101
"""
78102
Load the collected data from the CSV file.
@@ -243,6 +267,7 @@ def main():
243267
args = parse_arguments()
244268
shared.paths_log(LOGGER, PATHS)
245269
shared.git_fetch_and_merge(args, PATHS["repo"])
270+
check_report_completion(args)
246271
github_intro(args)
247272
plot_totals_by_license_type(args)
248273
plot_totals_by_restriction(args)

scripts/3-report/wikipedia_report.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def parse_arguments():
5757
help="Enable git actions such as fetch, merge, add, commit, and push"
5858
" (default: False)",
5959
)
60+
parser.add_argument(
61+
"--force",
62+
action="store_true",
63+
help="Regenerate data even if report files exist",
64+
)
6065
args = parser.parse_args()
6166
if not args.enable_save and args.enable_git:
6267
parser.error("--enable-git requires --enable-save")
@@ -68,6 +73,25 @@ def parse_arguments():
6873
return args
6974

7075

76+
def check_report_completion(args):
77+
""" "
78+
The function checks for the last plot and image
79+
caption created in this script. This helps to
80+
immediately know if all plots in the script have
81+
been created and should not be regenerated.
82+
83+
"""
84+
if args.force:
85+
return
86+
last_entry = shared.path_join(
87+
PATHS["data_phase"], "wikipedia_least_language_usage.png"
88+
)
89+
if os.path.exists(last_entry):
90+
raise shared.QuantifyingException(
91+
f"{last_entry} already exists. Report script completed", 0
92+
)
93+
94+
7195
def wikipedia_intro(args):
7296
"""
7397
Write Wikipedia introduction.
@@ -261,6 +285,7 @@ def main():
261285
args = parse_arguments()
262286
shared.paths_log(LOGGER, PATHS)
263287
shared.git_fetch_and_merge(args, PATHS["repo"])
288+
check_report_completion(args)
264289
wikipedia_intro(args)
265290
plot_language_representation(args)
266291
plot_highest_language_usage(args)

0 commit comments

Comments
 (0)