Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/utilities.py

Issue 2367303002: [Bindings] Remove a redundant option write-file-if-only-changed in bindings (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build . 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build .
6 6
7 Design doc: http://www.chromium.org/developers/design-documents/idl-build 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build
8 """ 8 """
9 9
10 import os 10 import os
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 idl_file_names.extend(resolve_cygpath(cygdrive_names)) 296 idl_file_names.extend(resolve_cygpath(cygdrive_names))
297 return idl_file_names 297 return idl_file_names
298 298
299 299
300 def read_pickle_files(pickle_filenames): 300 def read_pickle_files(pickle_filenames):
301 for pickle_filename in pickle_filenames: 301 for pickle_filename in pickle_filenames:
302 with open(pickle_filename) as pickle_file: 302 with open(pickle_filename) as pickle_file:
303 yield pickle.load(pickle_file) 303 yield pickle.load(pickle_file)
304 304
305 305
306 def write_file(new_text, destination_filename, only_if_changed): 306 def write_file(new_text, destination_filename):
307 if only_if_changed and os.path.isfile(destination_filename): 307 # If |new_text| is same with the file content, we skip updating.
308 if os.path.isfile(destination_filename):
308 with open(destination_filename) as destination_file: 309 with open(destination_filename) as destination_file:
309 if destination_file.read() == new_text: 310 if destination_file.read() == new_text:
310 return 311 return
312
311 destination_dirname = os.path.dirname(destination_filename) 313 destination_dirname = os.path.dirname(destination_filename)
312 if not os.path.exists(destination_dirname): 314 if not os.path.exists(destination_dirname):
313 os.makedirs(destination_dirname) 315 os.makedirs(destination_dirname)
314 with open(destination_filename, 'w') as destination_file: 316 with open(destination_filename, 'w') as destination_file:
315 destination_file.write(new_text) 317 destination_file.write(new_text)
316 318
317 319
318 def write_pickle_file(pickle_filename, data, only_if_changed): 320 def write_pickle_file(pickle_filename, data):
319 if only_if_changed and os.path.isfile(pickle_filename): 321 # If |data| is same with the file content, we skip updating.
322 if os.path.isfile(pickle_filename):
320 with open(pickle_filename) as pickle_file: 323 with open(pickle_filename) as pickle_file:
321 try: 324 try:
322 if pickle.load(pickle_file) == data: 325 if pickle.load(pickle_file) == data:
323 return 326 return
324 except Exception: 327 except Exception:
325 # If trouble unpickling, overwrite 328 # If trouble unpickling, overwrite
326 pass 329 pass
327 with open(pickle_filename, 'w') as pickle_file: 330 with open(pickle_filename, 'w') as pickle_file:
328 pickle.dump(data, pickle_file) 331 pickle.dump(data, pickle_file)
329 332
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 510
508 # Remember an open brace. 511 # Remember an open brace.
509 match = re_last_brace.search(line) 512 match = re_last_brace.search(line)
510 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line) 513 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line)
511 514
512 # Let |'\n'.join| emit the last newline. 515 # Let |'\n'.join| emit the last newline.
513 if output: 516 if output:
514 output.append('') 517 output.append('')
515 518
516 return '\n'.join(output) 519 return '\n'.join(output)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698