Skip to content

Commit a77ca17

Browse files
committed
added doc strings
1 parent e3e69c8 commit a77ca17

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tools/cc0_update.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
# vim: set fileencoding=utf-8:
33

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+
"""
56

67
# Copyright 2016, 2017 Creative Commons
78
#
@@ -47,6 +48,8 @@ def __init__(self, message, code=None):
4748

4849

4950
def diff_changes(filename, old, new):
51+
"""Display changes as a colorized unified diff.
52+
"""
5053
diff = list(
5154
difflib.unified_diff(
5255
old.split("\n"),
@@ -56,10 +59,6 @@ def diff_changes(filename, old, new):
5659
n=3,
5760
)
5861
)
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]}..."
6362
# Color diff output
6463
rst = "\033[0m"
6564
for i, line in enumerate(diff):
@@ -79,6 +78,10 @@ def diff_changes(filename, old, new):
7978

8079

8180
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+
"""
8285
print(f"{filename}: inserting language footer links")
8386
current_language = lang_tags_from_filenames(filename)[0]
8487
footer = ""
@@ -116,13 +119,18 @@ def update_lang_footer(args, filename, content, lang_tags):
116119

117120

118121
def has_footer_comments(content):
122+
"""Determine if the FOOTER_COMMENTS are already present.
123+
"""
119124
for comment in FOOTER_COMMENTS:
120125
if content.find(comment) == -1:
121126
return False
122127
return True
123128

124129

125130
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+
"""
126134
if has_footer_comments(content):
127135
print(f"{filename}: language footer comments present: skipping insert")
128136
return content
@@ -165,12 +173,17 @@ def insert_missing_lang_footer_comments(args, filename, content):
165173

166174

167175
def has_correct_faq_officialtranslations(content):
176+
"""Determine if the link to the tranlsation FAQ is correct.
177+
"""
168178
if content.find(f'"FAQ_TRANSLATION_LINK"') == -1:
169179
return False
170180
return True
171181

172182

173183
def normalize_faq_translation_link(args, filename, content):
184+
"""Replace various incorrect translation FAQ links with the correct link
185+
(FAQ_TRANSLATION_LINK).
186+
"""
174187
if has_correct_faq_officialtranslations(content):
175188
print(
176189
f"{filename}: correct translation FAQ link: skipping normalization"
@@ -210,6 +223,8 @@ def normalize_faq_translation_link(args, filename, content):
210223

211224

212225
def process_file_contents(args, file_list, lang_tags):
226+
"""Process each of the CC0 legalcode files and update them, as necessary.
227+
"""
213228
for filename in file_list:
214229
with open(filename, "r", encoding="utf-8") as file_in:
215230
content = file_in.read()
@@ -238,7 +253,7 @@ def process_file_contents(args, file_list, lang_tags):
238253

239254

240255
def lang_tags_from_filenames(file_list):
241-
"""Extract RFC 5646 language tags from filename
256+
"""Extract RFC 5646 language tags from filename(s)
242257
"""
243258
if isinstance(file_list, str):
244259
lang_tags = [file_list.split(".")[1][2:]]

0 commit comments

Comments
 (0)