File: mkfile

package info (click to toggle)
qmapshack 1.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 123,120 kB
  • sloc: cpp: 516,656; sh: 1,354; python: 997; xml: 710; awk: 21; makefile: 12; ansic: 1
file content (38 lines) | stat: -rwxr-xr-x 843 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3

import sys
import os

if len(sys.argv) != 2:
    print("bad number of arguments")
    sys.exit(-1)
    

path    = sys.argv[0][:-6]
fn      = sys.argv[1]

if os.path.exists(fn):
    print("file already exists.")
    sys.exit(-1)

pathTemplates   = os.path.join(path, "templates")
name, ext       = os.path.splitext(fn)

if ext == ".h":
    template = os.path.join(pathTemplates, "header.h")
elif ext == ".cpp":
    template = os.path.join(pathTemplates, "source.cpp")
elif ext == ".c":
    template = os.path.join(pathTemplates, "source.c")    
else:
    print("unknown file type")
    sys.exit(-1)
    
with open(template, "r") as fid1:
    text = fid1.read()
    text = text.replace("CLASSNAME_H", name.upper() + "_H")
    text = text.replace("CLASSNAME", name)

    with open(fn, "w") as fid2:
        fid2.write(text)