2626# Setup
2727LOGGER , PATHS = shared .setup (__file__ )
2828QUARTER = os .path .basename (PATHS ["data_quarter" ])
29- SECTION = Path (__file__ ).name
29+ SECTION_FILE = Path (__file__ ).name
30+ SECTION_TITLE = "Github"
31+
32+ IMAGE_PATHS = [
33+ shared .path_join (PATHS ["data_phase" ], "github_totals_by_license_type.png" ),
34+ shared .path_join (PATHS ["data_phase" ], "github_restriction.png" ),
35+ ]
3036
3137
3238def parse_arguments ():
@@ -56,6 +62,11 @@ def parse_arguments():
5662 help = "Enable git actions such as fetch, merge, add, commit, and push"
5763 " (default: False)" ,
5864 )
65+ parser .add_argument (
66+ "--force" ,
67+ action = "store_true" ,
68+ help = "Regenerate data even if images files already exist" ,
69+ )
5970 args = parser .parse_args ()
6071 if not args .enable_save and args .enable_git :
6172 parser .error ("--enable-git requires --enable-save" )
@@ -67,6 +78,14 @@ def parse_arguments():
6778 return args
6879
6980
81+ def check_image_files (args , image_paths ):
82+ for path in image_paths :
83+ if os .path .exists (path ) and not args .force :
84+ raise shared .QuantifyingException (
85+ f"image file already exists for { path } " , 0
86+ )
87+
88+
7089def load_data (args ):
7190 """
7291 Load the collected data from the CSV file.
@@ -100,7 +119,8 @@ def github_intro(args):
100119 cc_percentage = f"{ (cc_total / total_repositories ) * 100 :.2f} %"
101120 shared .update_readme (
102121 args ,
103- SECTION ,
122+ SECTION_FILE ,
123+ SECTION_TITLE ,
104124 "Overview" ,
105125 None ,
106126 None ,
@@ -111,7 +131,7 @@ def github_intro(args):
111131 f"** of the { total_repositories } total public repositories"
112132 " on GitHub that use a CC legal tool. Additionally,"
113133 " many more use a non-CC use a Public domain"
114- " equivalent legal tools.** \n "
134+ " equivalent legal tools.\n "
115135 "\n "
116136 " The Github data showcases the different level of"
117137 " rights reserved on repositories We have Public"
@@ -121,7 +141,7 @@ def github_intro(args):
121141 " without restriction."
122142 " See more at"
123143 " [Public-domain-equivalent license]"
124- "(https://en.wikipedia.org/wiki/Public-domain-equivalent_license)"
144+ "(https://en.wikipedia.org/wiki/Public-domain-equivalent_license). \n "
125145 " While a Permissive category of license contains works"
126146 " under MIT-0 and CC BY 4.0 allows users to"
127147 " reuse the code with some conditions and attribution"
@@ -130,7 +150,7 @@ def github_intro(args):
130150 " and Copyleft contains works under CC BY-SA 4.0."
131151 " which requires any derivative works to be licensed"
132152 " under the same terms."
133- " [Copyleft](https://en.wikipedia.org/wiki/Copyleft)"
153+ " [Copyleft](https://en.wikipedia.org/wiki/Copyleft). \n "
134154 "\n "
135155 "Thank you GitHub for providing public API"
136156 " access to repository metadata!" ,
@@ -172,7 +192,8 @@ def plot_totals_by_license_type(args):
172192
173193 shared .update_readme (
174194 args ,
175- SECTION ,
195+ SECTION_FILE ,
196+ SECTION_TITLE ,
176197 title ,
177198 image_path ,
178199 "Plots showing totals by license type."
@@ -220,7 +241,8 @@ def plot_totals_by_restriction(args):
220241
221242 shared .update_readme (
222243 args ,
223- SECTION ,
244+ SECTION_FILE ,
245+ SECTION_TITLE ,
224246 title ,
225247 image_path ,
226248 "Plots showing totals by different levels of restrictions."
@@ -234,6 +256,7 @@ def main():
234256 args = parse_arguments ()
235257 shared .paths_log (LOGGER , PATHS )
236258 shared .git_fetch_and_merge (args , PATHS ["repo" ])
259+ check_image_files (args , IMAGE_PATHS )
237260 github_intro (args )
238261 plot_totals_by_license_type (args )
239262 plot_totals_by_restriction (args )
0 commit comments