Skip to content

Commit c7cdc76

Browse files
committed
fixed regex to work with language codes longer than 2 characters. updated to skip symlinks. updated to not print skipped files (matching add_cc4_links.py behavior)
1 parent 2372872 commit c7cdc76

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tools/add_cc0_links.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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
17+
import os.path, re, sys
1818
from pathlib import Path
1919

2020

@@ -63,8 +63,9 @@ def get_files(self):
6363
self.files = [
6464
f
6565
for f in self.path.glob("zero_1.0*.html")
66-
if not f.match(self.exclude_pattern)
66+
if not os.path.islink(f) and not f.match(self.exclude_pattern)
6767
]
68+
self.files.sort()
6869

6970
def process_files(self):
7071
"""Add links to all the license files"""
@@ -82,7 +83,7 @@ def file_license_and_language(self, filepath):
8283
def links_in_page(self, content):
8384
"""Find the translated license links at the bottom of the page"""
8485
return re.findall(
85-
r'//creativecommons\.org/publicdomain/zero/1\.0/legalcode(\...)?">([^>]+)</a>',
86+
r'//creativecommons\.org/publicdomain/zero/1\.0/legalcode(\.[^"]{2,})?">([^>]+)</a>',
8687
content,
8788
)
8889

@@ -155,8 +156,8 @@ def process_file(self, filepath):
155156
with filepath.open("w") as outfile:
156157
outfile.write(updated_content)
157158
print("Added link to file: " + filepath.name)
158-
else:
159-
print("File already contains link: " + filepath.name)
159+
# else:
160+
# print("File already contains link: " + filepath.name)
160161

161162
def main(self):
162163
"""Get the command line arguments, find the files, and process them"""

0 commit comments

Comments
 (0)