12
12
from __future__ import print_function
13
13
14
14
import argparse
15
+ import collections
15
16
import json
16
17
import os
17
18
import sys
@@ -31,7 +32,7 @@ def apply_edits(path):
31
32
print ("No remap files found" )
32
33
return 1
33
34
34
- edits_set = set ( )
35
+ edits_per_file = collections . defaultdict ( list )
35
36
for remap_file in remap_files :
36
37
with open (remap_file ) as f :
37
38
json_data = f .read ()
@@ -43,24 +44,15 @@ def apply_edits(path):
43
44
offset = ed ["offset" ]
44
45
length = ed .get ("remove" , 0 )
45
46
text = ed .get ("text" , "" )
46
- edits_set .add ((fname , offset , length , text ))
47
-
48
- edits_per_file = {}
49
- for ed in edits_set :
50
- fname = ed [0 ]
51
- if fname not in edits_per_file :
52
- edits_per_file [fname ] = []
53
- edits_per_file [fname ].append ((ed [1 ], ed [2 ], ed [3 ]))
47
+ edits_per_file [fname ].append ((offset , length , text ))
54
48
55
49
for fname , edits in edits_per_file .iteritems ():
56
50
print ('Updating' , fname )
57
51
edits .sort (reverse = True )
58
52
with open (fname ) as f :
59
53
file_data = f .read ()
60
54
for ed in edits :
61
- offset = ed [0 ]
62
- length = ed [1 ]
63
- text = ed [2 ]
55
+ offset , length , text = ed
64
56
file_data = file_data [:offset ] + str (text ) + \
65
57
file_data [offset + length :]
66
58
with open (fname , 'w' ) as f :
0 commit comments