Created
October 1, 2018 12:38
-
-
Save alex-bender/4ca59415160a9642b106c36875207fbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Open fixture json files and remove lines which contain '>>>', '|||', '<<<', | |
and check that `.field.permissions` are unique""" | |
for fname in files: | |
fp = open(fname) | |
perms = json.loads(fixit(fname)) | |
fp.close() | |
for perm in perms: | |
item = perm['fields']['permissions'] | |
res = uniq(item) | |
def uniq(data): | |
res = [] | |
dup = [] | |
for perm in data: | |
item = ''.join(perm) | |
if item not in res: | |
res.append(item) | |
else: | |
dup.append(item) | |
return dup, len(data),len(res) | |
def fixit(fname): | |
res = [] | |
fp = open(fname) | |
lines = fp.readlines() | |
for line in lines: | |
if line.startswith('<<<<<<<'): | |
continue | |
elif line.startswith('>>>>'): | |
continue | |
elif line.startswith('||||'): | |
continue | |
elif line.startswith('===='): | |
continue | |
res.append(line) | |
fp.close() | |
return ''.join(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment