Skip to content

Instantly share code, notes, and snippets.

@alex-bender
Created October 1, 2018 12:38
Show Gist options
  • Save alex-bender/4ca59415160a9642b106c36875207fbf to your computer and use it in GitHub Desktop.
Save alex-bender/4ca59415160a9642b106c36875207fbf to your computer and use it in GitHub Desktop.
"""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