comparison mxtool/mx.py @ 21957:555f788b964b

show diff if jvmci.make generation modifies an existing file
author Doug Simon <doug.simon@oracle.com>
date Sat, 13 Jun 2015 00:25:30 +0200
parents 3a292e8b9e51
children 3adf20a59771
comparison
equal deleted inserted replaced
21956:35affb9c707a 21957:555f788b964b
2589 return 2589 return
2590 2590
2591 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + 2591 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
2592 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') 2592 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
2593 2593
2594 def update_file(path, content): 2594 def update_file(path, content, showDiff=False):
2595 """ 2595 """
2596 Updates a file with some given content if the content differs from what's in 2596 Updates a file with some given content if the content differs from what's in
2597 the file already. The return value indicates if the file was updated. 2597 the file already. The return value indicates if the file was updated.
2598 """ 2598 """
2599 existed = exists(path) 2599 existed = exists(path)
2605 2605
2606 if old == content: 2606 if old == content:
2607 return False 2607 return False
2608 2608
2609 if existed and _opts.backup_modified: 2609 if existed and _opts.backup_modified:
2610 shutil.move(path, path + '.orig') 2610 shutil.move(path, path + '.orig')
2611 2611
2612 with open(path, 'wb') as f: 2612 with open(path, 'wb') as f:
2613 f.write(content) 2613 f.write(content)
2614 2614
2615 log(('modified ' if existed else 'created ') + path) 2615 if existed:
2616 log('modified ' + path)
2617 if showDiff:
2618 log('diff: ' + path)
2619 log(''.join(difflib.unified_diff(old.splitlines(1), content.splitlines(1))))
2620
2621 else:
2622 log('created ' + path)
2616 return True 2623 return True
2617 except IOError as e: 2624 except IOError as e:
2618 abort('Error while writing to ' + path + ': ' + str(e)) 2625 abort('Error while writing to ' + path + ': ' + str(e))
2619 2626
2620 # Builtin commands 2627 # Builtin commands