diff options
author | 2015-07-20 08:11:41 +0200 | |
---|---|---|
committer | 2015-07-20 08:11:41 +0200 | |
commit | 4bcb0c13f50ddb1cd3fd0341b4bb31d9c3c7fc7a (patch) | |
tree | 55eccacfca0e69435d0d4e6615205310ca11f271 /3rdparty/jsoncpp/devtools/licenseupdater.py | |
parent | d132946c6f45aa8d271c6180e86f72dd08243048 (diff) | |
parent | 229785f695b26c702c8490792611f59d0366a933 (diff) |
Merge pull request #5 from mamedev/master
Sync to base master
Diffstat (limited to '3rdparty/jsoncpp/devtools/licenseupdater.py')
-rw-r--r-- | 3rdparty/jsoncpp/devtools/licenseupdater.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/3rdparty/jsoncpp/devtools/licenseupdater.py b/3rdparty/jsoncpp/devtools/licenseupdater.py index 8cb71d737b3..6f823618fb9 100644 --- a/3rdparty/jsoncpp/devtools/licenseupdater.py +++ b/3rdparty/jsoncpp/devtools/licenseupdater.py @@ -13,7 +13,7 @@ BRIEF_LICENSE = LICENSE_BEGIN + """2007-2010 Baptiste Lepilleur """.replace('\r\n','\n') -def update_license( path, dry_run, show_diff ): +def update_license(path, dry_run, show_diff): """Update the license statement in the specified file. Parameters: path: path of the C++ source file to update. @@ -22,28 +22,28 @@ def update_license( path, dry_run, show_diff ): show_diff: if True, print the path of the file that would be modified, as well as the change made to the file. """ - with open( path, 'rt' ) as fin: + with open(path, 'rt') as fin: original_text = fin.read().replace('\r\n','\n') newline = fin.newlines and fin.newlines[0] or '\n' - if not original_text.startswith( LICENSE_BEGIN ): + if not original_text.startswith(LICENSE_BEGIN): # No existing license found => prepend it new_text = BRIEF_LICENSE + original_text else: - license_end_index = original_text.index( '\n\n' ) # search first blank line + license_end_index = original_text.index('\n\n') # search first blank line new_text = BRIEF_LICENSE + original_text[license_end_index+2:] if original_text != new_text: if not dry_run: - with open( path, 'wb' ) as fout: - fout.write( new_text.replace('\n', newline ) ) + with open(path, 'wb') as fout: + fout.write(new_text.replace('\n', newline)) print('Updated', path) if show_diff: import difflib - print('\n'.join( difflib.unified_diff( original_text.split('\n'), - new_text.split('\n') ) )) + print('\n'.join(difflib.unified_diff(original_text.split('\n'), + new_text.split('\n')))) return True return False -def update_license_in_source_directories( source_dirs, dry_run, show_diff ): +def update_license_in_source_directories(source_dirs, dry_run, show_diff): """Updates license text in C++ source files found in directory source_dirs. Parameters: source_dirs: list of directory to scan for C++ sources. Directories are @@ -56,11 +56,11 @@ def update_license_in_source_directories( source_dirs, dry_run, show_diff ): from devtools import antglob prune_dirs = antglob.prune_dirs + 'scons-local* ./build* ./libs ./dist' for source_dir in source_dirs: - cpp_sources = antglob.glob( source_dir, + cpp_sources = antglob.glob(source_dir, includes = '''**/*.h **/*.cpp **/*.inl''', - prune_dirs = prune_dirs ) + prune_dirs = prune_dirs) for source in cpp_sources: - update_license( source, dry_run, show_diff ) + update_license(source, dry_run, show_diff) def main(): usage = """%prog DIR [DIR2...] @@ -83,7 +83,7 @@ python devtools\licenseupdater.py include src help="""On update, show change made to the file.""") parser.enable_interspersed_args() options, args = parser.parse_args() - update_license_in_source_directories( args, options.dry_run, options.show_diff ) + update_license_in_source_directories(args, options.dry_run, options.show_diff) print('Done') if __name__ == '__main__': |