File: mk_copyright.py

package info (click to toggle)
z3 4.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 33,364 kB
  • sloc: cpp: 501,803; python: 16,788; cs: 10,567; java: 9,687; ml: 3,282; ansic: 2,531; sh: 162; javascript: 37; makefile: 32
file content (57 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download | duplicates (3)
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
# Copyright (c) 2015 Microsoft Corporation

import os
import re

cr = re.compile("Copyright")
aut = re.compile("Automatically generated")

cr_notice = """
/*++
Copyright (c) 2015 Microsoft Corporation

--*/

"""

def has_cr(file):
    ins = open(file)
    lines = 0
    line = ins.readline()
    while line and lines < 20:
        m = cr.search(line)
        if m:
            ins.close()
            return True
        m = aut.search(line)
        if m:
            ins.close()
            return True
        line = ins.readline()
    ins.close()
    return False

def add_cr(file):
    tmp = "%s.tmp" % file
    ins = open(file)
    ous = open(tmp,'w')
    ous.write(cr_notice)
    line = ins.readline()
    while line:
        ous.write(line)
        line = ins.readline()
    ins.close()
    ous.close()
    os.system("move %s %s" % (tmp, file))

def add_missing_cr(dir):
    for root, dirs, files in os.walk(dir):
        for f in files:
            if f.endswith('.cpp') or f.endswith('.h') or f.endswith('.c') or f.endswith('.cs'):
                path = "%s\\%s" % (root, f)
                if not has_cr(path):
                    print("Missing CR for %s" % path)
                    add_cr(path)

add_missing_cr('src')
add_missing_cr('examples')