Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import unicode_literals
- import io
- import re
- import os
- import sys
- def parse(file, encoding='UTF-8-SIG'):
- valid = []
- text = io.open(file, encoding=encoding).read()
- nav_whole = re.match(r'(.*?)(FileStates \[.*?^\])(.*?\Z)', text, re.S | re.M)
- chunk_pat = re.compile(r'(?P<prev>\s*\[\s*FilePath = )(?P<path>.*?$)(?P<last>.*?Favorites \[.*?\].*?\]\n)', re.M | re.S)
- for mat in chunk_pat.finditer(nav_whole.group(2)):
- if os.path.exists(mat.group('path')):
- valid.append(mat.group())
- with io.open(file, 'w', encoding=encoding) as outfile:
- outfile.write(nav_whole.group(1))
- outfile.write('FileStates [\n')
- outfile.writelines(valid)
- outfile.write(']')
- outfile.write(nav_whole.group(3))
- if __name__ == '__main__':
- if len(sys.argv) == 2:
- parse(sys.argv[1])
Add Comment
Please, Sign In to add comment