Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
args = parser.parse_args()
response = requests.get(API_URL.format(args.key))
try:
webfontList = response.json()['items']
webfontListFamilyNames = [item['family'] for item in webfontList]
except (ValueError, KeyError):
sys.exit("Unable to load and parse"
" list of families from Google Web Fonts API.")
for dirpath, dirnames, filenames in os.walk(args.repo):
metadata_path = os.path.join(dirpath, 'METADATA.pb')
if not os.path.exists(metadata_path):
continue
metadata = FamilyProto()
text_data = open(metadata_path, "rb").read()
text_format.Merge(text_data, metadata)
try:
family = metadata.name
except KeyError:
print(('ERROR: "{}" does not contain'
' familyname info.').format(metadata_path),
file=sys.stderr)
continue
try:
index = webfontListFamilyNames.index(family)
webfontsItem = webfontList[index]
except ValueError:
print(('ERROR: Family "{}" could not be found'
' in Google Web Fonts API.').format(family))
Args:
fontdir: Directory containing font files for which we want metadata.
Returns:
OrderedDict of a complete METADATA.pb structure.
"""
file_family_style_weights = _FileFamilyStyleWeights(fontdir)
first_file = file_family_style_weights[0].file
subsets = ['menu'] + [s[0] for s in fonts.SubsetsInFont(first_file,
FLAGS.min_pct,
FLAGS.min_pct_ext)]
old_metadata_file = os.path.join(fontdir, 'METADATA.pb')
font_license = fonts.LicenseFromPath(fontdir)
metadata = fonts_pb2.FamilyProto()
metadata.name = file_family_style_weights[0].family
if FLAGS.update and os.path.isfile(old_metadata_file):
old_metadata = fonts_pb2.FamilyProto()
with open(old_metadata_file, "rb") as old_meta:
text_format.Parse(old_meta.read(), old_metadata)
metadata.designer = old_metadata.designer
metadata.category = old_metadata.category
metadata.date_added = old_metadata.date_added
else:
metadata.designer = 'UNKNOWN'
metadata.category = 'SANS_SERIF'
metadata.date_added = time.strftime('%Y-%m-%d')
metadata.license = font_license
subsets = sorted(subsets)
Python object loaded from METADATA.pb content.
Raises:
ValueError: if file_or_dir isn't a METADATA.pb file or dir containing one.
"""
if (os.path.isfile(file_or_dir) and
os.path.basename(file_or_dir) == 'METADATA.pb'):
metadata_file = file_or_dir
elif os.path.isdir(file_or_dir):
metadata_file = os.path.join(file_or_dir, 'METADATA.pb')
if not os.path.isfile(metadata_file):
raise ValueError('No METADATA.pb in %s' % file_or_dir)
else:
raise ValueError(
'%s is neither METADATA.pb file or a directory' % file_or_dir)
msg = fonts_pb2.FamilyProto()
with codecs.open(metadata_file, encoding='utf-8') as f:
text_format.Merge(f.read(), msg)
return msg
def get_FamilyProto_Message(path):
message = FamilyProto()
text_data = open(path, "rb").read()
text_format.Merge(text_data, message)
return message
"""
file_family_style_weights = _FileFamilyStyleWeights(fontdir)
first_file = file_family_style_weights[0].file
subsets = ['menu'] + [s[0] for s in fonts.SubsetsInFont(first_file,
FLAGS.min_pct,
FLAGS.min_pct_ext)]
old_metadata_file = os.path.join(fontdir, 'METADATA.pb')
font_license = fonts.LicenseFromPath(fontdir)
metadata = fonts_pb2.FamilyProto()
metadata.name = file_family_style_weights[0].family
if FLAGS.update and os.path.isfile(old_metadata_file):
old_metadata = fonts_pb2.FamilyProto()
with open(old_metadata_file, "rb") as old_meta:
text_format.Parse(old_meta.read(), old_metadata)
metadata.designer = old_metadata.designer
metadata.category = old_metadata.category
metadata.date_added = old_metadata.date_added
else:
metadata.designer = 'UNKNOWN'
metadata.category = 'SANS_SERIF'
metadata.date_added = time.strftime('%Y-%m-%d')
metadata.license = font_license
subsets = sorted(subsets)
for subset in subsets:
metadata.subsets.append(subset)
for (fontfile, family, style, weight) in file_family_style_weights: