1
1
#!/usr/bin/env python3
2
2
# vim: set fileencoding=utf-8:
3
3
4
- """Add/Update the language list at the bottom of all CC0 legalcode files."""
4
+ """Add/Update the language list at the bottom of all CC0 legalcode files.
5
+ """
5
6
6
7
# Copyright 2016, 2017 Creative Commons
7
8
#
@@ -47,6 +48,8 @@ def __init__(self, message, code=None):
47
48
48
49
49
50
def diff_changes (filename , old , new ):
51
+ """Display changes as a colorized unified diff.
52
+ """
50
53
diff = list (
51
54
difflib .unified_diff (
52
55
old .split ("\n " ),
@@ -56,10 +59,6 @@ def diff_changes(filename, old, new):
56
59
n = 3 ,
57
60
)
58
61
)
59
- # Limit diff lines to two terminal lines (max 160 characters)
60
- # for i, line in enumerate(diff):
61
- # if len(line) > 160:
62
- # diff[i] = f"{line[0:157]}..."
63
62
# Color diff output
64
63
rst = "\033 [0m"
65
64
for i , line in enumerate (diff ):
@@ -79,6 +78,10 @@ def diff_changes(filename, old, new):
79
78
80
79
81
80
def update_lang_footer (args , filename , content , lang_tags ):
81
+ """Replace the contents of the language footer (everything between the
82
+ FOOTER_COMMENTS) with a list of links based on the legalcode files
83
+ currently present.
84
+ """
82
85
print (f"{ filename } : inserting language footer links" )
83
86
current_language = lang_tags_from_filenames (filename )[0 ]
84
87
footer = ""
@@ -116,13 +119,18 @@ def update_lang_footer(args, filename, content, lang_tags):
116
119
117
120
118
121
def has_footer_comments (content ):
122
+ """Determine if the FOOTER_COMMENTS are already present.
123
+ """
119
124
for comment in FOOTER_COMMENTS :
120
125
if content .find (comment ) == - 1 :
121
126
return False
122
127
return True
123
128
124
129
125
130
def insert_missing_lang_footer_comments (args , filename , content ):
131
+ """Insert the FOOTER_COMMENTS in the appropriate locations, if they are not
132
+ present.
133
+ """
126
134
if has_footer_comments (content ):
127
135
print (f"{ filename } : language footer comments present: skipping insert" )
128
136
return content
@@ -165,12 +173,17 @@ def insert_missing_lang_footer_comments(args, filename, content):
165
173
166
174
167
175
def has_correct_faq_officialtranslations (content ):
176
+ """Determine if the link to the tranlsation FAQ is correct.
177
+ """
168
178
if content .find (f'"FAQ_TRANSLATION_LINK"' ) == - 1 :
169
179
return False
170
180
return True
171
181
172
182
173
183
def normalize_faq_translation_link (args , filename , content ):
184
+ """Replace various incorrect translation FAQ links with the correct link
185
+ (FAQ_TRANSLATION_LINK).
186
+ """
174
187
if has_correct_faq_officialtranslations (content ):
175
188
print (
176
189
f"{ filename } : correct translation FAQ link: skipping normalization"
@@ -210,6 +223,8 @@ def normalize_faq_translation_link(args, filename, content):
210
223
211
224
212
225
def process_file_contents (args , file_list , lang_tags ):
226
+ """Process each of the CC0 legalcode files and update them, as necessary.
227
+ """
213
228
for filename in file_list :
214
229
with open (filename , "r" , encoding = "utf-8" ) as file_in :
215
230
content = file_in .read ()
@@ -238,7 +253,7 @@ def process_file_contents(args, file_list, lang_tags):
238
253
239
254
240
255
def lang_tags_from_filenames (file_list ):
241
- """Extract RFC 5646 language tags from filename
256
+ """Extract RFC 5646 language tags from filename(s)
242
257
"""
243
258
if isinstance (file_list , str ):
244
259
lang_tags = [file_list .split ("." )[1 ][2 :]]
0 commit comments