-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
executable file
·92 lines (66 loc) · 1.78 KB
/
init.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3.4
# init.py
#
# Initialize a new Growler application
#
from sys import (argv)
import os
import stat
if len(argv) < 2:
print ("Please specify a destination")
print ("usage : %s <project_directory>" % (argv[0]))
exit()
dirname = argv[1]
if not os.path.exists(dirname):
os.mkdir(dirname)
else:
if os.path.isfile(dirname):
print ("Provided name '%s' is a file. Aborting." % (dirname))
exit()
elif not os.path.isdir(dirname) or len(os.listdir(dirname)) != 0:
print ("Provided name '%s' is a nonempty directory. Aborting." % (dirname))
exit()
print ("Initializing directory '%s'" % (dirname))
config_filename = "config.ini"
run_filename = "run.py"
app_fileanme = "app.py"
app_classname = "%sApp" % (dirname)
os.chdir(dirname)
runfile = open(run_filename, "w")
runfile_contents = """#!/usr/bin/env python3
#
# run.py
#
from configparser import ConfigParser
from app import {0}
conf = ConfigParser()
conf.read('config.ini')
app = {0}(conf)
app.run()
""".format(app_classname)
runfile.write(runfile_contents)
runfile.close()
conffile = open(config_filename, "w")
conffile.write("""#
# Configuration for project {}
#
[server]
host=localhost
port=8080
""".format(dirname))
conffile.close()
appfile = open("app.py", "w")
appfile.write("""
from growler import App
class {0}(App):
def __init__(self, config):
super().__init__(__class__.__name__, settings = config)
self.get("/", self.get_index)
def get_index(self, req, res, next):
print('[get_index]')
res.send_text("{0}");
""".format(app_classname))
appfile.close()
os.chmod(config_filename, stat.S_IRUSR | stat.S_IWUSR)
os.chmod(run_filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IROTH)
print ("*** Finished initializing new growler project : %s" % (dirname))