2020-08-02 06:51:49 +00:00
|
|
|
#!/usr/bin/env python
|
2014-07-03 06:30:24 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-07-02 22:35:39 +00:00
|
|
|
"""
|
2024-06-03 16:09:41 +00:00
|
|
|
This script sorts the entries in the README.md file. It clusters the lines
|
|
|
|
into blocks based on indentation and sorts each block individually.
|
2014-07-02 22:35:39 +00:00
|
|
|
"""
|
2016-11-12 14:26:46 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
def sort_readme():
|
|
|
|
# Load the current README into memory as an array of lines
|
2014-07-02 22:35:39 +00:00
|
|
|
with open('README.md', 'r') as read_me_file:
|
2024-06-03 16:09:41 +00:00
|
|
|
read_me = read_me_file.readlines()
|
2016-11-12 14:26:46 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
# Cluster lines into blocks based on indentation
|
|
|
|
blocks = []
|
|
|
|
current_block = []
|
|
|
|
last_indent = None
|
|
|
|
|
|
|
|
for line in read_me:
|
|
|
|
stripped_line = line.lstrip()
|
|
|
|
indent = len(line) - len(stripped_line)
|
|
|
|
|
|
|
|
# Detecting list items by starting character
|
|
|
|
if stripped_line.startswith(('* [', '- [')):
|
|
|
|
if indent == last_indent:
|
|
|
|
current_block.append(line)
|
|
|
|
else:
|
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
current_block = [line]
|
|
|
|
last_indent = indent
|
2014-07-02 22:35:39 +00:00
|
|
|
else:
|
2024-06-03 16:09:41 +00:00
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
current_block = []
|
|
|
|
blocks.append([line])
|
|
|
|
last_indent = None
|
2016-11-12 14:26:46 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
|
|
|
|
# Sort each block individually
|
|
|
|
sorted_blocks = []
|
|
|
|
for block in blocks:
|
|
|
|
if block[0].lstrip().startswith(('* [', '- [')):
|
|
|
|
sorted_blocks.append(sorted(block, key=lambda s: s.lower()))
|
|
|
|
else:
|
|
|
|
sorted_blocks.append(block)
|
|
|
|
|
|
|
|
# Write the sorted blocks back to the README.md file
|
|
|
|
with open('README.md', 'w') as sorted_file:
|
|
|
|
for block in sorted_blocks:
|
|
|
|
sorted_file.write(''.join(block))
|
2016-11-11 13:45:39 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sort_readme()
|
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding: utf-8
|
2016-11-12 14:26:46 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
"""
|
|
|
|
This script sorts the entries in the README.md file. It clusters the lines
|
|
|
|
into blocks based on indentation and sorts each block individually.
|
|
|
|
"""
|
2014-07-03 06:30:24 +00:00
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
def sort_readme():
|
|
|
|
# Load the current README into memory as an array of lines
|
2016-11-11 14:57:50 +00:00
|
|
|
with open('README.md', 'r') as read_me_file:
|
|
|
|
read_me = read_me_file.readlines()
|
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
# Cluster lines into blocks based on indentation
|
2016-11-11 14:57:50 +00:00
|
|
|
blocks = []
|
2024-06-03 16:09:41 +00:00
|
|
|
current_block = []
|
2016-11-11 14:57:50 +00:00
|
|
|
last_indent = None
|
2024-06-03 16:09:41 +00:00
|
|
|
|
2016-11-11 14:57:50 +00:00
|
|
|
for line in read_me:
|
2024-06-03 16:09:41 +00:00
|
|
|
stripped_line = line.lstrip()
|
|
|
|
indent = len(line) - len(stripped_line)
|
|
|
|
|
|
|
|
# Detecting list items by starting character
|
|
|
|
if stripped_line.startswith(('* [', '- [')):
|
2016-11-11 14:57:50 +00:00
|
|
|
if indent == last_indent:
|
2024-06-03 16:09:41 +00:00
|
|
|
current_block.append(line)
|
2016-11-11 14:57:50 +00:00
|
|
|
else:
|
2024-06-03 16:09:41 +00:00
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
current_block = [line]
|
2016-11-11 14:57:50 +00:00
|
|
|
last_indent = indent
|
|
|
|
else:
|
2024-06-03 16:09:41 +00:00
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
current_block = []
|
2016-11-11 14:57:50 +00:00
|
|
|
blocks.append([line])
|
|
|
|
last_indent = None
|
|
|
|
|
2024-06-03 16:09:41 +00:00
|
|
|
if current_block:
|
|
|
|
blocks.append(current_block)
|
|
|
|
|
|
|
|
# Sort each block individually
|
|
|
|
sorted_blocks = []
|
|
|
|
for block in blocks:
|
|
|
|
if block[0].lstrip().startswith(('* [', '- [')):
|
|
|
|
sorted_blocks.append(sorted(block, key=lambda s: s.lower()))
|
|
|
|
else:
|
|
|
|
sorted_blocks.append(block)
|
|
|
|
|
|
|
|
# Write the sorted blocks back to the README.md file
|
|
|
|
with open('README.md', 'w') as sorted_file:
|
|
|
|
for block in sorted_blocks:
|
|
|
|
sorted_file.write(''.join(block))
|
2014-07-02 22:35:39 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-06-03 16:09:41 +00:00
|
|
|
sort_readme()
|