1414# You should have received a copy of the GNU General Public License
1515# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- import re , sys , re , getopt
1817from pathlib import Path
18+ import getopt
19+ import re
20+ import sys
1921
2022
2123class UpdateLicenseCode (object ):
22- """One time script modifying 4.0 legal code files for updated look. This does not change
23- legal code language. It adds a header and footer placeholders, and updates the HTML head.
24- This allows the update_cc4_code.py script to function."""
24+ """One time script modifying 4.0 legal code files for updated look. This
25+ does not change legal code language. It adds a header and footer
26+ placeholders, and updates the HTML head.
27+
28+ This allows the update_cc4_code.py script to function."""
2529
2630 placeholders = {
2731 "head" : (
@@ -43,7 +47,10 @@ class UpdateLicenseCode(object):
4347 }
4448
4549 image_map = {
46- "by" : {"file" : "attribution_icon_white.svg" , "alt_text" : "Attribution" },
50+ "by" : {
51+ "file" : "attribution_icon_white.svg" ,
52+ "alt_text" : "Attribution" ,
53+ },
4754 "sa" : {"file" : "sa_white.svg" , "alt_text" : "Share Alike" },
4855 "nd" : {"file" : "nd_white.svg" , "alt_text" : "No Derivatives" },
4956 "nc" : {"file" : "nc_white.svg" , "alt_text" : "Non-Commerical" },
@@ -62,8 +69,8 @@ def log(self, message, type="standard"):
6269 print (message )
6370
6471 def get_args (self ):
65- """Get arguments/options and set corresponding flags. On validation error
66- print usage help"""
72+ """Get arguments/options and set corresponding flags. On validation
73+ error print usage help"""
6774 try :
6875 opts , args = getopt .getopt (sys .argv [1 :], "va" )
6976 except getopt .GetoptError :
@@ -95,7 +102,7 @@ def get_path(self):
95102 print ("Please run from within the checked-out project." )
96103 if self .path :
97104 self .includes_path = self .path / "includes"
98- return self .path != False
105+ return self .path is not False
99106
100107 def process_files (self , filelist ):
101108 """File processing loop"""
@@ -129,8 +136,9 @@ def process_file(self, filepath):
129136
130137 def handle_placeholders (self , content ):
131138 self .log (" Adding placeholders" , "verbose" )
132- # The language selector has to come after the header. Because dictionaries don't
133- # maint order the easiest way to maintain order is sorting the interation keys.
139+ # The language selector has to come after the header. Because
140+ # dictionaries don't maintain order the easiest way to maintain order
141+ # is sorting the interation keys.
134142 for placeholder_pair in sorted (UpdateLicenseCode .placeholders ):
135143 if self .has_placeholders (content , placeholder_pair ):
136144 self .log (
@@ -166,18 +174,27 @@ def remove_deed3_css(self, content):
166174 """Remove refererences to deed3 css stylesheets from HEAD"""
167175 self .log (" Removing deed3 css references from head" , "verbose" )
168176 content = re .sub (r"\n.*?<link.*?deed3\.css.*?>.*?\n" , "\n " , content )
169- content = re .sub (r"\n.*?<link.*?deed3\-print\.css.*?>.*?\n" , "\n " , content )
170- content = re .sub (r"\n.*?<link.*?deed3\-ie\.css.*?>.*?\n" , "\n " , content )
177+ content = re .sub (
178+ r"\n.*?<link.*?deed3\-print\.css.*?>.*?\n" , "\n " , content
179+ )
180+ content = re .sub (
181+ r"\n.*?<link.*?deed3\-ie\.css.*?>.*?\n" , "\n " , content
182+ )
171183 return content
172184
173185 def handle_rtl_css (self , content ):
174186 """The Right-to-Left stylesheet needs to come after the HEAD includes
175187 and be renamed"""
176188 self .log (" Handling right to left css" , "verbose" )
177189 if content .find ("deed3-rtl.css" ) != - 1 :
178- content = re .sub (r"\n.*?<link.*?deed3\-rtl\.css.*?>.*?\n" , "\n " , content )
190+ content = re .sub (
191+ r"\n.*?<link.*?deed3\-rtl\.css.*?>.*?\n" , "\n " , content
192+ )
179193 bottom_placholder = UpdateLicenseCode .placeholders ["head" ][1 ]
180- new_rtl_css = '<link rel="stylesheet" type="text/css" href="/includes/legalcode-rtl.css" media="all">'
194+ new_rtl_css = (
195+ '<link rel="stylesheet" type="text/css"'
196+ ' href="/includes/legalcode-rtl.css" media="all">'
197+ )
181198 content = content .replace (
182199 bottom_placholder , bottom_placholder + "\n " + new_rtl_css
183200 )
@@ -211,9 +228,15 @@ def add_language_class(self, content, language_code):
211228 if body_tag .find (language_class ) == - 1 :
212229 # If language class not on body, add it
213230 if body_tag .find ("class" ) > 0 :
214- existing_classes = re .search ('class="(.*?)"' , body_tag ).group (1 )
231+ existing_classes = re .search ('class="(.*?)"' , body_tag ).group (
232+ 1
233+ )
215234 new_body_tag = (
216- '<body class="' + existing_classes + " " + language_class + '">'
235+ '<body class="'
236+ + existing_classes
237+ + " "
238+ + language_class
239+ + '">'
217240 )
218241 else :
219242 new_body_tag = '<body class="' + language_class + '">'
@@ -236,25 +259,36 @@ def add_type_logos(self, content, lic_type):
236259 filename = UpdateLicenseCode .image_map [lic_attr ]["file" ]
237260 alt_text = UpdateLicenseCode .image_map [lic_attr ]["alt_text" ]
238261 image_tag = (
239- '<img src="/images/deed/svg/' + filename + '" alt="' + alt_text + '"/>'
262+ '<img src="/images/deed/svg/'
263+ + filename
264+ + '" alt="'
265+ + alt_text
266+ + '"/>'
240267 )
241268 lic_images += (
242- '<span class="cc-icon-' + lic_attr + '">' + image_tag + "</span>"
269+ '<span class="cc-icon-'
270+ + lic_attr
271+ + '">'
272+ + image_tag
273+ + "</span>"
243274 )
244275 cc_logo_section = re .search (
245276 '<div id="cc-logo">.*?</div>' , content , re .DOTALL
246277 ).group ()
247278 new_cc_logo_section = (
248279 '<div id="cc-logo">'
249- + '<span class="cc-icon-logo"><img src="/images/deed/svg/cc_white.svg" alt="CC"/></span>'
280+ + '<span class="cc-icon-logo">'
281+ + '<img src="/images/deed/svg/cc_white.svg" alt="CC"/></span>'
250282 + lic_images
251283 + "</div>"
252284 )
253285 content = content .replace (cc_logo_section , new_cc_logo_section )
254286 return content
255287
256288 def handling_consideration_blockquotes (self , content ):
257- content = content .replace ("<blockquote>" , '<p class="usage-considerations">' )
289+ content = content .replace (
290+ "<blockquote>" , '<p class="usage-considerations">'
291+ )
258292 content = content .replace ("</blockquote>" , "</p>" )
259293 return content
260294
0 commit comments