Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- def calc_lengths():
- max_lengths = {}
- for root in os.listdir('.'):
- if not root.startswith('pages'):
- continue
- for platform in os.listdir(root):
- for page in os.listdir(os.path.join(root, platform)):
- fname = os.path.join(root, platform, page)
- with open(fname, encoding='utf8') as f:
- max_length = 0
- for line in f:
- line = line.rstrip('\n')
- if line.startswith('>') or line.startswith('-'):
- max_length = max(max_length, len(line))
- max_lengths[fname] = max_length
- return max_lengths
- def find_too_long(max_lengths, limit, old_found={}):
- found = {}
- for fname, max_length in max_lengths.items():
- diff = max_length - limit
- if diff > 0:
- if fname not in old_found:
- found[fname] = (max_length, diff)
- n = len(found)
- if (n <= 50):
- print('Limit %d:' % limit, n, '{}page{} over the limit.'.format('more ' if old_found else '', 's' if n == 0 or n > 1 else ''))
- for fname, (max_length, diff) in sorted(found.items(), key=lambda x: (-x[1][0], x[0])):
- print('{:<50s} {} ({} over)'.format(fname.replace('\\', '/'), max_length, diff))
- else:
- print('Limit %d:' % limit, n, '{}pages over the limit (avoiding listing).'.format('more ' if old_found else ''))
- print('-' * 65)
- old_found.update(found)
- ml = calc_lengths()
- for limit in (250, 240, 220, 200, 180, 150, 140, 100, 80):
- find_too_long(ml, limit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement