in pelican/plugins/asfdata.py [0:0]
def process_sequence(metadata, seq, sequence, load, debug):
reference = load
# has been converted to a sequence
is_sequence = False
# has been converted to a dictionary - won't be made into a sequence
is_dictionary = False
# save metadata at the end
save_metadata = True
# description
if debug and 'description' in sequence:
print(f'{seq}: {sequence["description"]}')
# select sub dictionary
if 'path' in sequence:
if debug:
print(f'path: {sequence["path"]}')
parts = sequence['path'].split('.')
for part in parts:
reference = reference[part]
# filter dictionary by attribute value. if filter is false discard
if 'where' in sequence:
if debug:
print(f'where: {sequence["where"]}')
where_parts(reference, sequence['where'])
# remove irrelevant keys
if 'trim' in sequence:
if debug:
print(f'trim: {sequence["trim"]}')
parts = sequence['trim'].split(',')
for part in parts:
remove_part(reference, part)
# transform roster and chair patterns
if 'asfid' in sequence:
if debug:
print(f'asfid: {sequence["asfid"]}')
asfid_part(reference, sequence['asfid'])
# add first letter ofr alphabetic categories
if 'alpha' in sequence:
if debug:
print(f'alpha: {sequence["alpha"]}')
alpha_part(reference, sequence['alpha'])
# this dictionary is derived from sub-dictionaries
if 'dictionary' in sequence:
if debug:
print(f'dictionary: {sequence["dictionary"]}')
reference = { }
paths = sequence['dictionary'].split(',')
# create a dictionary from the keys in one or more sub-dictionaries
for path in paths:
for key in load[path]:
reference[key] = load[path][key]
# dictionary result, do not sequence
is_dictionary = True
# this sequence is derived from another sequence
if 'sequence' in sequence:
if debug:
print(f'sequence: {sequence["sequence"]}')
reference = metadata[sequence['sequence']]
# sequences derived from prior sequences do not need to be converted to a sequence
is_sequence = True
# this sequence is a random sample of another sequence
if 'random' in sequence:
if debug:
print(f'random: {sequence["random"]}')
if is_sequence:
reference = random.sample(reference, sequence['random'])
else:
print(f'{seq} - random requires an existing sequence to sample')
# for a project or podling see if the logo exists w/HEAD and set the relative path.
if 'logo' in sequence:
if debug:
print(f'logo: {sequence["logo"]}')
if is_sequence:
# determine the project or podling logo
reference = add_logo(reference, sequence['logo'])
if seq == 'featured_pods':
# for podlings strip "Apache" from the beginning and "(incubating)" from the end.
# this is Sally's request
for item in reference:
setattr(item, 'name', ' '.join(item.name.split(' ')[1:-1]))
else:
print(f'{seq} - logo requires an existing sequence')
# this sequence is a sorted list divided into multiple columns
if 'split' in sequence:
if debug:
print(f'split: {sequence["split"]}')
if is_sequence:
# create a sequence for each column
split_list(metadata, seq, reference, sequence['split'])
# created column sequences are already saved to metadata so do not do so later
save_metadata = False
else:
print(f'{seq} - split requires an existing sequence to split')
if 'truncate' in sequence:
multiple = int(sequence["truncate"])
reference = int(reference / multiple) * multiple
# if this not already a sequence or dictionary then convert to a sequence
if not is_sequence and not is_dictionary:
# convert the dictionary/list to a sequence of objects
if debug:
print(f'{seq}: create sequence')
if isinstance(reference, dict):
reference = sequence_dict(seq, reference)
elif isinstance(reference, list):
reference = sequence_list(seq, reference)
# save sequence in metadata
if save_metadata:
metadata[seq] = reference
try:
metadata[f'{seq}_size'] = len(reference)
except TypeError: # allow for integer
pass