def main(): """Updates the copyright year in all source files to the given year.""" if len(sys.argv) != 2: print('Usage: update_copyright.py <year>') return 1 try: year = sys.argv[1] sys.stdout.write('Updating copyright year to: ' + year + ' ') src_path = os.path.abspath(os.path.join( os.path.dirname(__file__), '../src')) # Fix copyright headers in C++ files for filename in find_files(src_path, ['.h', '.cc']): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] regex = re.compile( '(.*Copyright \(C\) \d\d\d\d)(.*)( by the Widelands Development Team.*)') for line in lines: match = regex.match(line) if match: if match.group(1).endswith(year): line = match.group(1) + match.group(3) else: line = match.group(1) + '-' + year + match.group(3) new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) # Now update the Buildinfo filename = os.path.join(src_path, 'build_info.h') lines = read_text_file(filename).strip().split('\n') new_lines = [] regex = re.compile( '(.*constexpr uint16_t kWidelandsCopyrightEnd = )(\d\d\d\d)(;)') for line in lines: match = regex.match(line) if match: line = match.group(1) + year + match.group(3) new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) print(' done.') except Exception: print('Something went wrong:') traceback.print_exc() return 1
def main(): """Updates the copyright year in all source files to the given year.""" if len(sys.argv) != 2: print('Usage: update_copyright.py <year>') return 1 try: year = sys.argv[1] sys.stdout.write('Updating copyright year to: ' + year + ' ') src_path = os.path.abspath(os.path.join( os.path.dirname(__file__), '../src')) # Fix copyright headers in C++ files for filename in find_files(src_path, ['.h', '.cc']): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] regex = re.compile( '(.*Copyright \(C\) \d\d\d\d)(.*)( by the Widelands Development Team.*)') for line in lines: match = regex.match(line) if match: line = match.group(1) + '-' + year + match.group(3) new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) # Now update the Buildinfo filename = os.path.join(src_path, 'build_info.h') lines = read_text_file(filename).strip().split('\n') new_lines = [] regex = re.compile( '(.*constexpr uint16_t kWidelandsCopyrightEnd = )(\d\d\d\d)(;)') for line in lines: match = regex.match(line) if match: line = match.group(1) + year + match.group(3) new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) print(' done.') except Exception: print('Something went wrong:') traceback.print_exc() return 1
def update_file(filename, regex, replace): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] for line in lines: match = regex.match(line) if match: line = replace(match) new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines))
def main(): parse_args() if not os.path.isdir('src') or not os.path.isdir('utils'): print('CWD is not the root of the repository.') return 1 sys.stdout.write('Fixing Lua tabs ') for filename in find_files('.', ['.lua']): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] for line in lines: m = LEADING_TABS.match(line) if m is not None: line = line[m.start():m.end()].expandtabs( SPACES_PER_TAB) + line[m.end():] new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) call(['git', 'add', '--renormalize', filename]) print(' done.') sys.stdout.write('\nFormatting C++ ') for filename in find_files('./src', ['.cc', '.h']): if 'third_party' in filename: continue sys.stdout.write('.') sys.stdout.flush() call(['clang-format', '-i', filename]) call(['git', 'add', '--renormalize', filename]) print(' done.') sys.stdout.write('\nFormatting Python utils ') for filename in find_files('./utils', ['.py']): sys.stdout.write('.') sys.stdout.flush() call(['pyformat', '-i', filename]) call(['git', 'add', '--renormalize', filename]) print(' done.') print('Formatting finished.') return 0
def main(): parse_args() if not os.path.isdir('src') or not os.path.isdir('utils'): print('CWD is not the root of the repository.') return 1 sys.stdout.write('Fixing Lua tabs ') for filename in find_files('.', ['.lua']): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] for line in lines: m = LEADING_TABS.match(line) if m is not None: line = line[m.start():m.end()].expandtabs( SPACES_PER_TAB) + line[m.end():] new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) print(' done.') sys.stdout.write('\nFormatting C++ ') for filename in find_files('./src', ['.cc', '.h']): if 'third_party' in filename: continue sys.stdout.write('.') sys.stdout.flush() call(['clang-format', '-i', filename]) print(' done.') sys.stdout.write('\nFormatting Python utils ') for filename in find_files('./utils', ['.py']): sys.stdout.write('.') sys.stdout.flush() call(['pyformat', '-i', filename]) print(' done.') print 'Formatting finished.' return 0
errors = 0 for line in known_clean_lines: e = check_line('selftest false-positives', 1, line) errors += e if e > 0: print('SELFTEST ERROR: false-positive in "{}"'.format(line)) for line in known_issues: e = check_line('selftest false-negatives', 1, line, False) if e == 0: errors += 1 print('SELFTEST ERROR: false-negative in "{}"'.format(line)) if errors > 0: print('\nThere were selftest errors, please fix!') sys.exit(1) # Actual check for filename in find_files( os.path.abspath(os.path.join(os.path.dirname(__file__), '..')), ['.lua', '.rst', '.rst.org']): for lidx, line in enumerate(read_text_file(filename).strip().split('\n')): errors += check_line( re.compile(r""".*widelands.(.*)""").search(filename).group(1), lidx, line) if errors > 0: print('\nThere were {} error(s), please fix!'.format(errors)) sys.exit(1)
def main(): args = parse_args() format_cplusplus = args['c++'] or not (args['lua'] or args['python']) format_lua = args['lua'] or not (args['c++'] or args['python']) format_python = args['python'] or not (args['c++'] or args['lua']) if not os.path.isdir('src') or not os.path.isdir('utils'): print('CWD is not the root of the repository.') return 1 if format_cplusplus: directory = args['dir'] if not directory: directory = './src' sys.stdout.write('\nFormatting C++ in directory: ' + directory + ' ') for filename in find_files(directory, ['.cc', '.h']): if 'third_party' in filename: continue sys.stdout.write('.') sys.stdout.flush() call(['clang-format', '-i', filename]) call(['git', 'add', '--renormalize', filename]) print(' done.') if format_lua: directories = set() if args['dir']: directories.add(args['dir']) else: directories = {'./data', './test'} for directory in directories: sys.stdout.write('\nFixing Lua tabs in directory: ' + directory + ' ') for filename in find_files(directory, ['.lua']): sys.stdout.write('.') sys.stdout.flush() lines = read_text_file(filename).strip().split('\n') new_lines = [] for line in lines: m = LEADING_TABS.match(line) if m is not None: line = line[m.start():m.end()].expandtabs( SPACES_PER_TAB) + line[m.end():] new_lines.append(line.rstrip() + '\n') write_text_file(filename, ''.join(new_lines)) call(['git', 'add', '--renormalize', filename]) print(' done.') if format_python: directories = set() if args['dir']: directories.add(args['dir']) else: directories = {'./utils', './cmake/codecheck'} for directory in directories: sys.stdout.write('\nFormatting Python scripts in directory: ' + directory + ' ') for filename in find_files(directory, ['.py']): sys.stdout.write('.') sys.stdout.flush() call(['pyformat', '-i', filename]) call(['git', 'add', '--renormalize', filename]) print(' done.') print('Formatting finished.') return 0