forked from Maproom/qmapshack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkfile
executable file
·41 lines (30 loc) · 820 Bytes
/
mkfile
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
#!/usr/bin/python
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)
fid = file(template,"r")
text = fid.read()
fid.close()
text = text.replace("CLASSNAME_H", name.upper() + "_H")
text = text.replace("CLASSNAME", name)
fid = file(fn,"w")
fid.write(text)
fid.close()