File: addheader.py

package info (click to toggle)
libpyzy 1.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 34,544 kB
  • sloc: python: 23,416; cpp: 20,929; makefile: 346; sql: 94; php: 16; sh: 16
file content (24 lines) | stat: -rw-r--r-- 583 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
import sys

def add_header(name, header):
    with file(name) as fin:
        lines = fin.readlines()
    with file(name, "w") as fout:
        for l in header:
            print >> fout, l,
        if lines[0].startswith("/*") and lines[0].endswith("*/\n"):
            pass
        else:
            print >> fout, lines[0],
        for l in lines[1:]:
            print >> fout, l,

def main():
    with file("header") as f:
        header = f.readlines()
    for name in sys.argv[1:]:
        add_header(name, header)

if __name__ == "__main__":
    main()