diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/add_version_headers | 27 | ||||
-rwxr-xr-x | scripts/update_version | 38 |
2 files changed, 57 insertions, 8 deletions
diff --git a/scripts/add_version_headers b/scripts/add_version_headers index c4fd3ffc..cf1531b0 100755 --- a/scripts/add_version_headers +++ b/scripts/add_version_headers @@ -24,10 +24,12 @@ import os import re import sys +from subprocess import call -header = """/* ---------------------------------------------------------------\ -------------- - * {0} + +header = """/** ---------------------------------------------------------------\ +------------ + * @file: {0} * * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> * MIT License, see LICENSE file for more details. @@ -38,7 +40,7 @@ header = """/* ---------------------------------------------------------------\ lic_regex = re.compile( - "\/\* -+\n \* ([a-z]+\.(?:cpp|h)|\{0\})\n(?: \*[ a-zA-Z0-9_.,\-()<>@]*\n)+ \* -+\n \*/", re.MULTILINE) + "\/(?:\*|\*\*) -+\n \* ((?:@file: )?[a-z0-9]+\.(?:cpp|h)|\{0\})\n(?: \*[ a-zA-Z0-9_.,\-()<>@]*\n)+ \* -+\n \*/\n\n", re.MULTILINE) class HeaderUpdate(object): @@ -75,11 +77,13 @@ class HeaderUpdate(object): src = f.read() f.seek(0) if lic_regex.match(src): - print("Updating {}: ".format( - os.path.basename(filePath)), end="") - src = lic_regex.sub(header.format( + other_src = lic_regex.sub(header.format( os.path.basename(filePath)), src) - print("done") + if other_src != src: + print("Updating {}: ".format( + os.path.basename(filePath)), end="") + src = other_src + print("done") else: print("Adding {}: ".format( os.path.basename(filePath)), end="") @@ -102,12 +106,19 @@ class HeaderUpdate(object): not re.match(self.exclude_re, fileName)): fileOperation(os.path.join(subdir, fileName)) + def runClangFormat(self): + def clangFormatFileOpration(filePath): + call(["clang-format", "-i", filePath]) + + self._traverseDir(self.starting_dir, clangFormatFileOpration) + def main(argv): update = HeaderUpdate(exclude_re="^picopng\.cpp", match_dir=".*yage|.*tests", exclude_dir=".*lib.*|.*build.*") update.updateHeader() + update.runClangFormat() if __name__ == "__main__": diff --git a/scripts/update_version b/scripts/update_version new file mode 100755 index 00000000..9c618fa6 --- /dev/null +++ b/scripts/update_version @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# ----------------------------------------------------------------------------- +# @file: add_version_headers +# +# Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> +# MIT License, see LICENSE file for more details. +# ----------------------------------------------------------------------------- + + +import os +import re +import sys + + +def main(argv): + cwd = os.path.join(os.getcwd(), argv[2]) + cmake = os.path.join(cwd, "CMakeLists.txt") + doxyfile = os.path.join(cwd, "docs", "Doxyfile") + + with open(cmake, "r+") as f_: + src = f_.read() + f_.seek(0) + src = re.sub(r"(project\(\w+\s+VERSION\s+)[0-9.]+", r"\g<1>{0}.0".format(argv[1]), src, re.MULTILINE) + f_.write(src) + f_.truncate() + + with open(doxyfile, "r+") as f_: + src = f_.read() + f_.seek(0) + src = re.sub(r"(PROJECT_NUMBER\s+=\s+v)[0-9.]+", r"\g<1>{0}".format(argv[1]), src, re.MULTILINE) + f_.write(src) + f_.truncate() + + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) |