even better approach for check 029 implementation
"Check copyright namerecords match license file"
Also removes the 'license' condition from check 030
(issue
@@ -838,12 +838,24 @@ def licenses(family_directory):
@register_condition
@condition
-def license(licenses):
+def license_path(licenses):
"""Get license path"""
# return license if there is exactly one license
return licenses[0] if len(licenses) == 1 else None
+@register_condition
+@condition
+def license(license_path):
+ """Get license name"""
+ if "LICENSE.txt" in license_path:
+ return "LICENSE.txt" # APACHE License
+ if "OFL.txt" in license_path:
+ return "OFL.txt" # Open Font License
+ # else
+ return "unknown:'{}'".format(license_path)
+
+
@register_test
@old_style_test(
id='com.google.fonts/test/028'
@@ -872,10 +884,7 @@ def check_font_has_a_license(fb, licenses):
def check_copyright_entries_match_license(fb, ttFont, license):
"""Check copyright namerecords match license file"""
failed = False
- for license_filename in ['OFL.txt', 'LICENSE.txt']:
- if license_filename not in license:
- continue
- placeholder = PLACEHOLDER_LICENSING_TEXT[license_filename]
+ placeholder = PLACEHOLDER_LICENSING_TEXT[license]
entry_found = False
for i, nameRecord in enumerate(ttFont['name'].names):
if nameRecord.nameID == NAMEID_LICENSE_DESCRIPTION:
@@ -896,18 +905,16 @@ def check_copyright_entries_match_license(fb, ttFont, license):
unidecode(value),
unidecode(placeholder)))
if not entry_found:
- failed = True
fb.error(("Font lacks NameID {} (LICENSE DESCRIPTION)."
" A proper licensing entry must be set."
"").format(NAMEID_LICENSE_DESCRIPTION))
- if not failed:
+ elif not failed:
fb.ok("licensing entry on name table is correctly set.")
@register_test
@old_style_test(
id='com.google.fonts/test/030'
- , conditions=['license']
, priority=CRITICAL
)
def check_font_has_a_valid_license_url(fb, ttFont):
@@ -964,7 +971,6 @@ def check_font_has_a_valid_license_url(fb, ttFont):
def check_description_strings_in_name_table(fb, ttFont):
"""Description strings in the name table
must not contain copyright info."""
-
failed = False
for name in ttFont['name'].names:
if 'opyright' in name.string.decode(name.getEncoding())\
