Skip to content

Commit 91b1301

Browse files
jimcaddenBetsyRT
authored andcommitted
feat(appgen): Add native app template
Closes: #235 Approved by: jmcadden
1 parent 2b4d2ee commit 91b1301

15 files changed

Lines changed: 111 additions & 14 deletions

File tree

contrib/appgen/appgen.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
from jinja2 import Environment, FileSystemLoader
33
import os
44
import sys
5+
import argparse
56

6-
print "Generate files new EbbRT application in the currect working \
7-
directory."
8-
var = raw_input("Enter a name for the application \
9-
(one word, no spaces):\n> ").lower()
7+
parser = argparse.ArgumentParser(description='Generate EbbRT application',
8+
prog=sys.argv[0], usage='%(prog)s [options]')
9+
parser.add_argument('-n', metavar="NAME", default="app", help='new application name')
10+
parser.add_argument('-t', default="default", choices=['default', 'native'], help='application template')
11+
args = parser.parse_args()
1012

11-
# Capture our current directory
12-
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
13-
CONTEXT = { "title" : var, "CAP_TITLE": var.upper() }
14-
target_path = os.path.join(os.getcwd(), var)
15-
source_path = os.path.join(THIS_DIR, "template/helloworld")
13+
template = args.t
14+
appname = args.n
15+
16+
# Capture the script (source) directory
17+
source_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "template/"+template)
18+
target_path = os.getcwd()
19+
CONTEXT = { "title" : appname, "CAP_TITLE": appname.upper() }
1620

1721
def apply_template(source, target):
1822
if not os.path.exists(target):
1923
os.makedirs(target)
20-
else:
21-
print "Error, target directory already exists: "+target
22-
sys.exit()
2324
print "Building new application: "+target
2425
#print "Using template: "+source
2526
for path,sd,files in os.walk(source):
@@ -34,7 +35,7 @@ def apply_template(source, target):
3435
relative_path = os.path.join(relative_root, name)
3536
full_source_path = os.path.join(path, name)
3637
if name == "title.cc":
37-
full_target_path = os.path.join(target_root, var+".cc")
38+
full_target_path = os.path.join(target_root, appname+".cc")
3839
else:
3940
full_target_path = os.path.join(target_root, name)
4041
print "writing "+full_target_path
@@ -49,4 +50,4 @@ def render_template(fs, filename, context):
4950

5051
if __name__ == '__main__':
5152
apply_template(source_path, target_path)
52-
print "Build finished."
53+
print "New EbbRT application ("+appname+") generated in current working directory"
File renamed without changes.
File renamed without changes.

contrib/appgen/template/helloworld/cmake/FindCapnp.cmake renamed to contrib/appgen/template/default/cmake/FindCapnp.cmake

File renamed without changes.
File renamed without changes.
File renamed without changes.

contrib/appgen/template/helloworld/src/hosted/Printer.cc renamed to contrib/appgen/template/default/src/hosted/Printer.cc

File renamed without changes.

contrib/appgen/template/helloworld/src/hosted/Printer.h renamed to contrib/appgen/template/default/src/hosted/Printer.h

File renamed without changes.
File renamed without changes.

contrib/appgen/template/helloworld/src/native/Printer.cc renamed to contrib/appgen/template/default/src/native/Printer.cc

File renamed without changes.

0 commit comments

Comments
 (0)