From 289a6377af8e58a5cbb372e2737a4aeff2e4b2fe Mon Sep 17 00:00:00 2001 From: Andreas Kull Date: Fri, 30 Oct 2015 23:16:08 +0100 Subject: [PATCH] Removed Python scripts since repository was marked as Python --- .scripts/sort.py | 50 ------------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 .scripts/sort.py diff --git a/.scripts/sort.py b/.scripts/sort.py deleted file mode 100644 index d809100..0000000 --- a/.scripts/sort.py +++ /dev/null @@ -1,50 +0,0 @@ -# coding: utf-8 - -""" - The approach taken is explained below. I decided to do it simply. - Initially I was considering parsing the data into some sort of - structure and then generating an appropriate README. I am still - considering doing it - but for now this should work. The only issue - I see is that it only sorts the entries at the lowest level, and that - the order of the top-level contents do not match the order of the actual - entries. - - This could be extended by having nested blocks, sorting them recursively - and flattening the end structure into a list of lines. Revision 2 maybe ^.^. -""" - - -def main(): - # First, we load the current README into memory as an array of lines - with open('README.md', 'r') as read_me_file: - read_me = read_me_file.readlines() - - # Then we cluster the lines together as blocks - # Each block represents a collection of lines that should be sorted - # This was done by assuming only links ([...](...)) are meant to be sorted - # Clustering is done by indentation - blocks = [] - last_indent = None - for line in read_me: - s_line = line.lstrip() - indent = len(line) - len(s_line) - - if any([s_line.startswith(s) for s in ['* [', '- [']]): - if indent == last_indent: - blocks[-1].append(line) - else: - blocks.append([line]) - last_indent = indent - else: - blocks.append([line]) - last_indent = None - - with open('README.md', 'w+') as sorted_file: - # Then all of the blocks are sorted individually - blocks = [''.join(sorted(block, key=lambda s: s.lower())) for block in blocks] - # And the result is written back to README.md - sorted_file.write(''.join(blocks)) - - -if __name__ == "__main__": - main()