-#!/usr/bin/env python3
+#!/usr/bin/env python
## ---------------------------------------------------------------------
##
## Copyright (C) 2019 by the deal.II authors
# This script should be invoked from the root folder of the deal.ii
# repository:
# contrib/utilities/check_encoding.py
+from __future__ import print_function
-import glob
import itertools
+import io
+import os
+import sys
-filenames = itertools.chain(glob.iglob('**/*.h', recursive=True),
- glob.iglob('**/*.cc', recursive=True),
- glob.iglob('**/*.html', recursive=True))
+def filename_generator(suffix):
+ for root, _, file_names in os.walk("./"):
+ for file_name in file_names:
+ if file_name.endswith(suffix):
+ if root == "./":
+ yield root + file_name
+ else:
+ yield root + "/" + file_name
+
+
+filenames = itertools.chain(filename_generator(".h"),
+ filename_generator(".cc"),
+ filename_generator(".html"))
+
+return_code = 0
for filename in filenames:
+ file_handle = io.open(filename, encoding='utf-8')
try:
- with open(filename, encoding='utf-8') as file:
- file.read()
- except:
- raise Exception(filename + ' is not encoded is not encoded with UTF-8')
+ file_handle.read()
+ except UnicodeDecodeError:
+ print(filename + ' is not encoded with UTF-8')
+ return_code = 1
+ finally:
+ file_handle.close()
+
+sys.exit(return_code)
-#!/usr/bin/env python3
+#!/usr/bin/env python
## ---------------------------------------------------------------------
##
## Copyright (C) 2019 by the deal.II authors
# the deal.ii repository you can use the script
# contrib/utilities/set_canonical_webpages.py
-import glob
+import os
-filenames = glob.iglob('**/*html', recursive=True)
+LINK_START = ('<link rel="canonical" href="https://www.dealii.org/current'
+ + '/doxygen/')
-for filename in filenames:
- file = open(filename, 'r')
- new_text_data = str()
- if '<link rel="canonical"' not in file.read():
- file.seek(0)
- for line in file.readlines():
- # Do not add the canonical link twice
- canonical_link_added = False
- new_text_data += line
- if (not canonical_link_added) and ('<head>' in line):
- new_text_data += ('<link rel="canonical" href="https://www.dealii.org/current/doxygen/deal.II/'
- + filename + '" />' + '\n')
- canonical_link_added = True
- file.close()
+def filename_generator():
+ for root, _, file_names in os.walk("./"):
+ for file_name in file_names:
+ if file_name.endswith(".html"):
+ if root == "./":
+ yield root + file_name
+ else:
+ yield root + "/" + file_name
+for filename in filename_generator():
+ # there is no relevant content in the header
+ if filename == "./header.html":
+ pass
+ new_text_data = str()
+ with open(filename, 'r') as file_handle:
+ if '<link rel="canonical"' not in file_handle.read():
+ file_handle.seek(0)
+ for line in file_handle.readlines():
+ # Do not add the canonical link twice
+ canonical_link_added = False
+ new_text_data += line
+ if not canonical_link_added and '<head>' in line:
+ assert filename[:2] == "./"
+ new_text_data += LINK_START + filename[2:] + '" />\n'
+ canonical_link_added = True
+ if new_text_data:
# Truncate the file and write the new text
- file = open(filename, 'w+')
- file.write(new_text_data)
- file.close()
+ with open(filename, 'w+') as file_handle:
+ file_handle.write(new_text_data)