3 from __future__
import print_function
9 def writeheader(filename
, header
):
11 write a header to filename,
12 skip files where first line after optional shebang matches the skip regex
13 filename should be the name of the file to write to
14 header should be a list of strings
15 skip should be a regex
17 with
open(filename
, "r") as f
:
21 # comment out the next 3 lines if you don't wish to preserve shebangs
22 if len(inpt
) > 0 and inpt
[0].startswith("#!"):
23 output
.append(inpt
[0])
26 if inpt
[0].strip().startswith("/*"):
27 for i
, line
in enumerate(inpt
):
28 if line
.strip().endswith("*/"):
32 while not inpt
[0].strip():
35 output
.extend(header
) # add the header
39 with
open(filename
, 'w') as f
:
41 print("added header to %s" % filename
)
42 except IOError as err
:
43 print("something went wrong trying to add header to %s: %s" % (filename
, err
))
46 def main(args
=sys
.argv
):
47 with
open(os
.path
.dirname(os
.path
.realpath(__file__
)) + "/copyright-header.txt") as headerfile
:
48 header
= headerfile
.readlines()
49 for filename
in args
[1:]:
50 writeheader(filename
, header
)
53 if __name__
== '__main__':
54 # call the main method