#!/usr/bin/env python # ----------------------------------------------------------------------------- # add_version_headers # # Add version header # # Copyright (c) 2017 Yann Herklotz Grave -- MIT License # See file LICENSE for more details # ----------------------------------------------------------------------------- """\file add_version_headers \brief Adds the version headers to every file. Add Version Headers =================== This file adds the version headers to every file in the directory Improvements ------------ Add the ability to input command line arguments. """ import os import re import sys header = """/* ---------------------------------------------------------------\ ------------- * {0} * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. * ---------------------------------------------------------------------------- */ """ class HeaderUpdate(object): """Updates the header in all the source and header files in the code""" def __init__(self, **kwargs): self.match_re = ".*[.]cpp$|.*[.]hpp$" self.exclude_re = "^$" self.exclude_build = True self.exclude_dir = ".*build.*" self.match_dir = "" for key, value in kwargs.items(): setattr(self, key, value) def writeHeader(self): for subdir, dirs, files in os.walk(os.getcwd()): if (not re.match(self.exclude_dir, subdir)) and \ (re.match(self.match_dir, subdir)): for file_ in files: if (re.match(self.match_re, file_)) and \ (not re.match(self.exclude_re, file_)): with open(os.path.join(subdir, file_), 'r') \ as src_file: src = src_file.read() if not re.match("^\/[*] -+", src): print(os.path.join(subdir, file_), end=" ") with open(os.path.join(subdir, file_), 'w') as src_file_lic: src_file_lic.write(header.format(file_)) src_file_lic.write(src) print("-- done") def updateHeader(self): ... def removeHeader(self): ... def main(argv): update = HeaderUpdate(exclude_re="^picopng[.]cpp", exclude_dir=".*build.*|.*google.*", match_dir=".*src.*|.*include.*|.*test.*") update.writeHeader() if __name__ == "__main__": main(sys.argv)