aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/add_version_headers
blob: 0949fb86ae15a9e545900a9de33c5bba6197a48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -----------------------------------------------------------------------------
# add_version_headers
#
# Add version header
#
# Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- 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 <ymherklotz@gmail.com> -- 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$"
        if "match_re" in kwargs:
            self.match_re = kwargs["match_re"]
        self.exclude_re = ""
        if "exlude_re" in kwargs:
            self.exclude_re = kwargs["exclude_re"]
        self.exclude_build = True
        if "exclude_build" in kwargs:
            self.exclude_build = kwargs["exclude_build"]

    def writeHeader(self):
        for subdir, dirs, files in os.walk(os.getcwd()):
            if (not re.match(".*build.*", subdir) or (not self.exclude_build)):
                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("^/[*] -*$"):
                            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):
    udpate = HeaderUpdate(exclude_re="^picopng[.]cpp")


if __name__ == "__main__":
    main(sys.argv)