1616
1717from pathlib import Path
1818import getopt
19+ import os
1920import re
2021import sys
2122
@@ -146,8 +147,8 @@ def log(self, message, type="standard"):
146147 print (message )
147148
148149 def get_args (self ):
149- """Get arguments/options and set corresponding flags. On validation error
150- print usage help"""
150+ """Get arguments/options and set corresponding flags. On validation
151+ error print usage help"""
151152 try :
152153 opts , args = getopt .getopt (sys .argv [1 :], "v" )
153154 except getopt .GetoptError :
@@ -175,7 +176,7 @@ def get_path(self):
175176 if not self .path :
176177 print ("Please run from within the checked-out project." )
177178 if self .path :
178- self .includes_path = Path (sys .path [0 ] + " /legalcode-includes" )
179+ self .includes_path = Path (f" { sys .path [0 ]} /legalcode-includes" )
179180 return self .path is not False
180181
181182 def process_files (self , filelist ):
@@ -186,19 +187,19 @@ def process_files(self, filelist):
186187 def process_file (self , filepath ):
187188 """Verify the required placeholders exist and update file with common
188189 elements"""
189- self .log (" \n " + "Processing: " + filepath .name , "verbose" )
190+ self .log (f" \n Processing: { filepath .name } " , "verbose" )
190191 with filepath .open (encoding = "utf-8" ) as infile :
191192 content = infile .read ()
192193
193194 if self .has_placeholders (content ):
194- self .log (" Updating content: " + filepath .name , "verbose" )
195+ self .log (f " Updating content: { filepath .name } " , "verbose" )
195196 content = self .add_includes (content )
196197 content = self .add_language_selector (content , filepath )
197198 with filepath .open ("w" , encoding = "utf-8" ) as outfile :
198199 outfile .write (content )
199200 else :
200201 self .log (
201- " No placeholders, skipping: " + filepath .name , "standard"
202+ f " No placeholders, skipping: { filepath .name } " , "standard"
202203 )
203204
204205 return
@@ -221,9 +222,9 @@ def add_includes(self, content):
221222 with includefile .open () as infile :
222223 includetext = infile .read ()
223224
224- replacement = start + " \n " + includetext + " \n " + end
225+ replacement = f" { start } \n { includetext } \n { end } "
225226 target_string = re .search (
226- start + " .*?" + end , content , re .DOTALL
227+ f" { start } .*?{ end } " , content , re .DOTALL
227228 ).group ()
228229 content = content .replace (target_string , replacement , 1 )
229230
@@ -237,7 +238,7 @@ def add_language_selector(self, content, filepath):
237238 if license_data ["type" ] not in self .languages :
238239 self .languages [license_data ["type" ]] = []
239240 glob_string = (
240- license_data [" type" ] + "_" + license_data [" version" ] + " *.html"
241+ f" { license_data [' type' ] } _ { license_data [' version' ] } *.html"
241242 )
242243 language_file_list = [f for f in self .path .glob (glob_string )]
243244 for filepath in language_file_list :
@@ -250,44 +251,38 @@ def add_language_selector(self, content, filepath):
250251 current_language = license_data ["language" ]
251252 sibling_languages = self .languages [license_data ["type" ]]
252253
253- selector = '<div id="language-selector-block" class="container">'
254- selector += ' <div class ="language-selector-inner ">'
255- selector += self . lang_sel_text [ current_language ]
256- selector += (
254+ selector = (
255+ ' <div id ="language-selector-block" class="container ">'
256+ ' <div class="language-selector-inner">'
257+ f" { self . lang_sel_text [ current_language ] } "
257258 ' <img class="language-icon"'
258259 ' src="/images/language_icon_x2.png" alt="Languages" />'
260+ " <select>"
259261 )
260- selector += " <select>"
261262 for iso_code in sibling_languages :
262263 # Set the selected option to the current language of the page
263264 selected = ""
264265 if iso_code == current_language :
265266 selected = ' selected="selected" '
266267 # Determine to option value for the language. English breaks the
267268 # pattern so handle it differently.
268- option_value = "legalcode." + iso_code
269+ option_value = f "legalcode.{ iso_code } "
269270 if iso_code == "en" :
270271 option_value = "legalcode"
271272 # Add the selector vlaue
272- selector += (
273- '<option value="'
274- + option_value
275- + '"'
276- + selected
277- + ">"
278- + self .iso_to_language [iso_code ]
279- + "</option>"
273+ selector = (
274+ f'{ selector } <option value="{ option_value } "{ selected } >'
275+ f"{ self .iso_to_language [iso_code ]} "
276+ "</option>"
280277 )
281- selector += " </select>"
282- selector += " </div>"
283- selector += "</div>"
278+ selector = f"{ selector } </select> </div></div>"
284279
285280 # Add the language selector block to the content
286281 start , end = UpdateLicenseCode .placeholders ["language-selector" ]
287282 target_string = re .search (
288- start + " .*?" + end , content , re .DOTALL
283+ f" { start } .*?{ end } " , content , re .DOTALL
289284 ).group ()
290- replacement = start + " \n " + selector + " \n " + end
285+ replacement = f" { start } \n { selector } \n { end } "
291286 content = content .replace (target_string , replacement , 1 )
292287
293288 return content
@@ -315,7 +310,11 @@ def has_placeholders(self, content):
315310 def main (self ):
316311 """Get the command line arguments, find the files, and process them"""
317312 if self .get_args () and self .get_path ():
318- file_list = [f for f in self .path .glob ("*4.0*.html" )]
313+ file_list = [
314+ f
315+ for f in self .path .glob ("*4.0*.html" )
316+ if not os .path .islink (f )
317+ ]
319318 self .process_files (file_list )
320319
321320
0 commit comments