Skip to content

Minor Python tidies in apply-fixit-edits.py #3034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions utils/apply-fixit-edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from __future__ import print_function

import argparse
import collections
import json
import os
import sys
Expand All @@ -31,7 +32,7 @@ def apply_edits(path):
print("No remap files found")
return 1

edits_set = set()
edits_per_file = collections.defaultdict(list)
for remap_file in remap_files:
with open(remap_file) as f:
json_data = f.read()
Expand All @@ -43,24 +44,15 @@ def apply_edits(path):
offset = ed["offset"]
length = ed.get("remove", 0)
text = ed.get("text", "")
edits_set.add((fname, offset, length, text))

edits_per_file = {}
for ed in edits_set:
fname = ed[0]
if fname not in edits_per_file:
edits_per_file[fname] = []
edits_per_file[fname].append((ed[1], ed[2], ed[3]))
edits_per_file[fname].append((offset, length, text))

for fname, edits in edits_per_file.iteritems():
print('Updating', fname)
edits.sort(reverse=True)
with open(fname) as f:
file_data = f.read()
for ed in edits:
offset = ed[0]
length = ed[1]
text = ed[2]
offset, length, text = ed
file_data = file_data[:offset] + str(text) + \
file_data[offset + length:]
with open(fname, 'w') as f:
Expand Down