-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_cpp_project_template.py
70 lines (53 loc) · 2.81 KB
/
simple_cpp_project_template.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/python
import os
import subprocess
import helpers
project_help = "Project name to be created. The project folder will be names like this."
sourcefiles_help = "Source cpp files to be created."
mainfiles_help = "Main cpp files to be created."
headerfiles_help = "Header files to be created."
# license_help = "License type"
def run( arg ):
devnull = open( '/dev/null' , 'w' )
proc = subprocess.Popen( arg , stdout=devnull )
ret = proc.wait()
if ret != 0 :
print "Error while " + str( arg )
class simple_cpp_project_template():
def __init__( self ):
self.name = "SimpleCppProject"
self.description = "Simple cpp project with CMakelists.txt and several source and header files."
def register_in_arg_parser( self , subparsers ):
parser = helpers.create_subparser( self , subparsers )
parser.add_argument( "project" , help = project_help )
parser.add_argument( "-s" , "--sourcefiles" , nargs = "*" , help = sourcefiles_help )
parser.add_argument( "-m" , "--mainfiles" , nargs = "*" , help = mainfiles_help )
parser.add_argument( "-i" , "--headerfiles" , nargs = "*" , help = headerfiles_help )
# parser.add_argument( "-l" , "--license" , nargs=1 , help = license_help , default = "no" , choices = copyright_notes.copyrights.keys() )
def do_work( self , args , replacements ):
print "Creating " + self.name + " template(s) ..."
if not os.path.exists( args.project ):
print "* Creating project folder"
os.mkdir( args.project )
print "* Project folder already exist"
print "* Switching to project folder"
os.chdir( args.project )
print "* Creating build folder"
os.mkdir( "build" )
cmake_str = [ "code_template.py" , "SimpleCMake" , "-p" , args.project ]
if( hasattr( args , "mainfiles" ) ) and ( args.mainfiles is not None ) and ( len( args.mainfiles ) != 0 ) :
cmake_str.append( "-t" )
for m in args.mainfiles :
print "* Creating main file " + m
run( [ "code_template.py" , "SimpleMain" , m ] )
cmake_str.append( m )
if( hasattr( args , "headerfiles" ) ) and ( args.headerfiles is not None ) and ( len( args.headerfiles ) != 0 ) :
for h in args.headerfiles:
print "* Creating header file " + h
run( [ "code_template.py" , "SimpleHeader" , "-f" , h ] )
if( hasattr( args , "sourcefiles" ) ) and ( args.sourcefiles is not None ) and ( len( args.sourcefiles ) != 0 ) :
for s in args.sourcefiles :
print "* Creating source file " + s
run( [ "code_template.py" , "SimpleSource" , s ] )
print "Creating CMakelists.txt"
run( cmake_str )