-
Notifications
You must be signed in to change notification settings - Fork 1
/
createFlask.py
63 lines (59 loc) · 2.38 KB
/
createFlask.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
import subprocess
import sys
pathRoot = "/Users/lucyzhang/github/"
def createFlask():
print "Create a flask app? (y/n)"
userInput = sys.stdin.readline().strip()
if (userInput == 'y'):
print "Name of project folder: "
appName = sys.stdin.readline().strip()
appRoot = pathRoot + appName
print "Making a folder in "+appRoot
subprocess.call(["mkdir",appRoot])
print "Making internal folders and files"
subprocess.call(["mkdir",appRoot+"/static"])
subprocess.call(["mkdir",appRoot+"/static/css"])
subprocess.call(["touch",appRoot+"/static/css/style.css"])
subprocess.call(["mkdir",appRoot+"/static/js"])
subprocess.call(["touch",appRoot+"/static/js/script.js"])
subprocess.call(["mkdir",appRoot+"/static/img"])
subprocess.call(["mkdir",appRoot+"/static/plugins"])
subprocess.call(["mkdir",appRoot+"/templates"])
subprocess.call(["touch",appRoot+"/templates/index.html"])
#subprocess.call(["touch",appRoot+"/app.py"])
f = open(appRoot+"/app.py", "w")
subprocess.call(["echo", "from flask import Flask, render_template\napp = Flask(__name__)\nif __name__ == \"__main__\":\n port = int(os.environ.get(\"PORT\", 5000))\n app.run(host='0.0.0.0', port=port)"], stdout=f)
#subprocess.call(["touch",appRoot+"/Procfile"])
p=open(appRoot+"/Procfile","w")
subprocess.call(["echo","web: python app.py"],stdout=p)
subprocess.call(["cd",appRoot])
print "Creating virtualenv"
subprocess.call(["virtualenv", appRoot+"/venv"])
subprocess.call(["touch", appRoot+"/requirements.txt"])
print "Would you like to initialize your git repo here? (y/n)"
gitrepo = sys.stdin.readline().strip()
if (gitrepo=="y"):
appRoot = appRoot+"/"
print appRoot
print "Please input the git repo URL:"
remoteURL = sys.stdin.readline().strip()
p1=subprocess.Popen(["git","init"],cwd=appRoot)
p1.wait()
p2=subprocess.Popen(["git","add","-A"],cwd=appRoot)
p2.wait()
p3=subprocess.Popen(["git","config","user.email","[email protected]"],cwd=appRoot)
p3.wait()
p4=subprocess.Popen(["git","commit","-am","Added files"],cwd=appRoot)
p4.wait()
p5=subprocess.Popen(["git","remote","add","origin",remoteURL],cwd=appRoot)
p5.wait()
p6=subprocess.Popen(["git","push","-u","origin","master"],cwd=appRoot)
p6.wait()
print("Pushed code to repo")
elif (gitrepo=="n"):
print "Done"
return
elif (userInput=="n"):
print "Bye"
if __name__ == "__main__":
createFlask()