big tabs vs spaces adjust
This commit is contained in:
parent
b83bfe5687
commit
1f2c44c82d
296
build.py
296
build.py
|
@ -18,190 +18,194 @@ DELIMITER = "| :|"
|
|||
# split strings longer than length into a list
|
||||
# strings are split at last index of delim
|
||||
def split_to_list(str, length, delim=' '):
|
||||
l = []
|
||||
l = []
|
||||
|
||||
while len(str) > length:
|
||||
sep = str.rfind(delim, 0, length)
|
||||
l.append(str[0:sep])
|
||||
str = str[sep+1:]
|
||||
|
||||
l.append(str)
|
||||
while len(str) > length:
|
||||
sep = str.rfind(delim, 0, length)
|
||||
l.append(str[0:sep])
|
||||
str = str[sep+1:]
|
||||
|
||||
return l
|
||||
l.append(str)
|
||||
|
||||
return l
|
||||
|
||||
# build_header using section title
|
||||
def build_header(l_title):
|
||||
header = []
|
||||
def build_header(l_title, add_index=false, index_prefix=None):
|
||||
header = []
|
||||
|
||||
len_title = len(l_title[0])
|
||||
pad, pad_left = divmod(MAX_WIDTH - (len_title + (TITLE_PADDING * 2)) - 2, 2)
|
||||
len_border = len_title + ((TITLE_PADDING * 2) - 2)
|
||||
|
||||
# upper part
|
||||
header.append(' ' * (pad + pad_left + 2) + '_' * len_border + ' ' * (pad + 2))
|
||||
header.append('_' * (pad + pad_left) + '//' + ' ' * len_border + '\\\\' + '_' * pad)
|
||||
# ' ' padded Title
|
||||
count = 1
|
||||
for title in l_title:
|
||||
c_pad = '_' if count == len(l_title) else ' '
|
||||
pad_right = len_title - len(title)
|
||||
header.append(c_pad * (pad + pad_left) + '|' + ' ' * TITLE_PADDING + title + ' ' * (TITLE_PADDING + pad_right) + '|' + c_pad * pad)
|
||||
count += 1
|
||||
# lower part
|
||||
header.append(' ' * (pad + pad_left) + '\\\\' + '_' * len_border + '//' + ' ' * pad)
|
||||
header.append(' ' * MAX_WIDTH)
|
||||
len_title = len(l_title[0])
|
||||
pad, pad_left = divmod(MAX_WIDTH - (len_title + (TITLE_PADDING * 2)) - 2, 2)
|
||||
len_border = len_title + ((TITLE_PADDING * 2) - 2)
|
||||
|
||||
return header
|
||||
# upper part
|
||||
header.append(' ' * (pad + pad_left + 2) + '_' * len_border + ' ' * (pad + 2))
|
||||
header.append('_' * (pad + pad_left) + '//' + ' ' * len_border + '\\\\' + '_' * pad)
|
||||
# ' ' padded Title
|
||||
count = 1
|
||||
for title in l_title:
|
||||
c_pad = '_' if count == len(l_title) else ' '
|
||||
pad_right = len_title - len(title)
|
||||
header.append(c_pad * (pad + pad_left) + '|' + ' ' * TITLE_PADDING + title + ' ' * (TITLE_PADDING + pad_right) + '|' + c_pad * pad)
|
||||
count += 1
|
||||
# lower part
|
||||
header.append(' ' * (pad + pad_left) + '\\\\' + '_' * len_border + '//' + ' ' * pad)
|
||||
# add navigation tag
|
||||
if add_index == true and index_prefix.length == 1:
|
||||
pass
|
||||
else:
|
||||
header.append(' ' * MAX_WIDTH)
|
||||
|
||||
return header
|
||||
|
||||
def build_index(yaml, prefix):
|
||||
l_title = []
|
||||
for item in yaml:
|
||||
l_title += [item['title']]
|
||||
l_title = []
|
||||
for item in yaml:
|
||||
l_title += [item['title']]
|
||||
|
||||
l_index = []
|
||||
for i, item in enumerate(l_title):
|
||||
l_index += [' - ' + item.ljust(MAX_WIDTH - 10) + f'[{prefix}{i+1:03}] ']
|
||||
l_index = []
|
||||
for i, item in enumerate(l_title):
|
||||
l_index += [' - ' + item.ljust(MAX_WIDTH - 10) + f'[{prefix}{i+1:03}] ']
|
||||
|
||||
l_index += [' ' * MAX_WIDTH]
|
||||
l_index += [' ' * MAX_WIDTH]
|
||||
|
||||
return l_index
|
||||
return l_index
|
||||
|
||||
def build_game(name, platform):
|
||||
s_platform = platform.ljust(MAX_WIDTH_PLATFORM)
|
||||
s_name = name.ljust(MAX_WIDTH_NAME)
|
||||
|
||||
return f' {s_platform} | {s_name} '
|
||||
s_platform = platform.ljust(MAX_WIDTH_PLATFORM)
|
||||
s_name = name.ljust(MAX_WIDTH_NAME)
|
||||
|
||||
return f' {s_platform} | {s_name} '
|
||||
|
||||
#
|
||||
# main
|
||||
#
|
||||
|
||||
def main():
|
||||
print('go')
|
||||
with open(f'{BASE}/todo.yaml', 'r') as file:
|
||||
todo_yaml = yaml.safe_load(file)
|
||||
print('go')
|
||||
with open(f'{BASE}/todo.yaml', 'r') as file:
|
||||
todo_yaml = yaml.safe_load(file)
|
||||
|
||||
with open(f'{BASE}/finished.yaml', 'r') as file:
|
||||
finished_yaml = yaml.safe_load(file)
|
||||
with open(f'{BASE}/finished.yaml', 'r') as file:
|
||||
finished_yaml = yaml.safe_load(file)
|
||||
|
||||
#
|
||||
# Section: TO-DO
|
||||
#
|
||||
|
||||
todo_result = []
|
||||
#
|
||||
# Section: TO-DO
|
||||
#
|
||||
|
||||
todo_result += build_header([TITLE_LEFT])
|
||||
todo_result = []
|
||||
|
||||
todo_result += build_index(todo_yaml, 'S')
|
||||
todo_result += build_header([TITLE_LEFT])
|
||||
|
||||
for section in todo_yaml:
|
||||
s_title = section['title']
|
||||
l_title = []
|
||||
todo_result += build_index(todo_yaml, 'S')
|
||||
|
||||
if len(s_title) > MAX_WIDTH_TITLE:
|
||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||
else:
|
||||
l_title = [s_title]
|
||||
|
||||
# Create section header
|
||||
todo_result += build_header(l_title)
|
||||
|
||||
# Create table header
|
||||
todo_result += [' ______ ________________________________________________________',
|
||||
'|======|========================================================']
|
||||
for section in todo_yaml:
|
||||
s_title = section['title']
|
||||
l_title = []
|
||||
|
||||
# Add games one by one
|
||||
# Prefix : |
|
||||
for game in section['games']:
|
||||
s_name = game['name']
|
||||
s_platform = game['platform']
|
||||
if len(s_title) > MAX_WIDTH_TITLE:
|
||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||
else:
|
||||
l_title = [s_title]
|
||||
|
||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||
|
||||
if len(s_name) > MAX_WIDTH_NAME:
|
||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||
for i,i_name in enumerate(l_name):
|
||||
todo_result += ['|' + build_game(i_name, s_platform if i == 0 else '')]
|
||||
else:
|
||||
todo_result += ['|' + build_game(s_name, s_platform)]
|
||||
# Create section header
|
||||
todo_result += build_header(l_title)
|
||||
|
||||
# Close table header
|
||||
todo_result += ['|______|________________________________________________________',
|
||||
' ' * MAX_WIDTH]
|
||||
|
||||
#
|
||||
# Section: Finished
|
||||
#
|
||||
# Create table header
|
||||
todo_result += [' ______ ________________________________________________________',
|
||||
'|======|========================================================']
|
||||
|
||||
finished_result = []
|
||||
# Add games one by one
|
||||
# Prefix : |
|
||||
for game in section['games']:
|
||||
s_name = game['name']
|
||||
s_platform = game['platform']
|
||||
|
||||
finished_result += build_header([TITLE_RIGHT])
|
||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||
|
||||
finished_result += build_index(finished_yaml, 'P')
|
||||
if len(s_name) > MAX_WIDTH_NAME:
|
||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||
for i,i_name in enumerate(l_name):
|
||||
todo_result += ['|' + build_game(i_name, s_platform if i == 0 else '')]
|
||||
else:
|
||||
todo_result += ['|' + build_game(s_name, s_platform)]
|
||||
|
||||
for section in finished_yaml:
|
||||
s_title = section['title']
|
||||
l_title = []
|
||||
# Close table header
|
||||
todo_result += ['|______|________________________________________________________',
|
||||
' ' * MAX_WIDTH]
|
||||
|
||||
if len(s_title) > MAX_WIDTH_TITLE:
|
||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||
else:
|
||||
l_title = [s_title]
|
||||
|
||||
# Create section header
|
||||
finished_result += build_header(l_title)
|
||||
|
||||
# Create table header
|
||||
finished_result += ['______ ________________________________________________________ ',
|
||||
'======|========================================================|']
|
||||
#
|
||||
# Section: Finished
|
||||
#
|
||||
|
||||
# Add games one by one
|
||||
# Suffix : |
|
||||
for game in section['games']:
|
||||
s_name = game['name']
|
||||
s_platform = game['platform']
|
||||
finished_result = []
|
||||
|
||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||
|
||||
if len(s_name) > MAX_WIDTH_NAME:
|
||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||
for i,i_name in enumerate(l_name):
|
||||
finished_result += [build_game(i_name, platform if i == 0 else '') + '|']
|
||||
else:
|
||||
finished_result += [build_game(s_name, s_platform) + '|']
|
||||
finished_result += build_header([TITLE_RIGHT])
|
||||
|
||||
# Close table header
|
||||
finished_result += ['______|________________________________________________________|',
|
||||
' ' * MAX_WIDTH]
|
||||
finished_result += build_index(finished_yaml, 'P')
|
||||
|
||||
# adjust length of both sides
|
||||
len_difference = len(todo_result) - len(finished_result)
|
||||
# todo > finished
|
||||
if len_difference > 0:
|
||||
finished_result += [' ' * MAX_WIDTH] * len_difference
|
||||
# todo < finished
|
||||
elif len_difference < 0:
|
||||
len_difference *= -1
|
||||
todo_result += [' ' * MAX_WIDTH] * len_difference
|
||||
for section in finished_yaml:
|
||||
s_title = section['title']
|
||||
l_title = []
|
||||
|
||||
if len(todo_result) != len(finished_result):
|
||||
raise Exception("Results are not of equal size. Something went wrong...")
|
||||
|
||||
result = []
|
||||
i = 0
|
||||
while len(todo_result) > i:
|
||||
result += [todo_result[i] + DELIMITER + finished_result[i]]
|
||||
i += 1
|
||||
|
||||
with open('list-of-game.txt', 'w') as file:
|
||||
for i in result:
|
||||
file.write(f"{i}\n")
|
||||
if len(s_title) > MAX_WIDTH_TITLE:
|
||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||
else:
|
||||
l_title = [s_title]
|
||||
|
||||
print('done')
|
||||
|
||||
return
|
||||
# Create section header
|
||||
finished_result += build_header(l_title)
|
||||
|
||||
# Create table header
|
||||
finished_result += ['______ ________________________________________________________ ',
|
||||
'======|========================================================|']
|
||||
|
||||
# Add games one by one
|
||||
# Suffix : |
|
||||
for game in section['games']:
|
||||
s_name = game['name']
|
||||
s_platform = game['platform']
|
||||
|
||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||
|
||||
if len(s_name) > MAX_WIDTH_NAME:
|
||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||
for i,i_name in enumerate(l_name):
|
||||
finished_result += [build_game(i_name, platform if i == 0 else '') + '|']
|
||||
else:
|
||||
finished_result += [build_game(s_name, s_platform) + '|']
|
||||
|
||||
# Close table header
|
||||
finished_result += ['______|________________________________________________________|',
|
||||
' ' * MAX_WIDTH]
|
||||
|
||||
# adjust length of both sides
|
||||
len_difference = len(todo_result) - len(finished_result)
|
||||
# todo > finished
|
||||
if len_difference > 0:
|
||||
finished_result += [' ' * MAX_WIDTH] * len_difference
|
||||
# todo < finished
|
||||
elif len_difference < 0:
|
||||
len_difference *= -1
|
||||
todo_result += [' ' * MAX_WIDTH] * len_difference
|
||||
|
||||
if len(todo_result) != len(finished_result):
|
||||
raise Exception("Results are not of equal size. Something went wrong...")
|
||||
|
||||
result = []
|
||||
i = 0
|
||||
while len(todo_result) > i:
|
||||
result += [todo_result[i] + DELIMITER + finished_result[i]]
|
||||
i += 1
|
||||
|
||||
with open('list-of-game.txt', 'w') as file:
|
||||
for i in result:
|
||||
file.write(f"{i}\n")
|
||||
|
||||
print('done')
|
||||
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue