File: addheader.py

package info (click to toggle)
ibus-pinyin 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: cpp: 6,536; ansic: 791; python: 567; makefile: 392; sh: 24; awk: 13
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()