auto-scripts/auto-bottlepy
#!/usr/bin/env python3
import sys,os,stat
main= '''#!/usr/bin/python3
import subprocess, os
from bottle import Bottle,route, run, template, static_file
from globals_vars import app
from extra import *
global app
header='<!DOCTYPE HTML>\
<html>\
<head>\
<title>Titolo</title>\
<meta http-equiv="content-type" content="text/html;charset=utf-8" />\
</head>\
\
<body><h1>Welcome to Bottle</h1><p>Example page</p>\
'
footer="</body></html> "
html=header+footer
def start_server():
run(app,host='0.0.0.0', port=8080, reloader=True,debug=True)
@app.route('/static/<filename:path>')
def static_html(filename):
return static_file(filename, root=os.path.dirname(os.path.realpath(__file__))+'/static/')
@app.route('/')
def home():
yield html
start_server()
'''
globals_vars='''from bottle import Bottle
app=Bottle()
'''
extra='''from bottle import Bottle,route, run, template, static_file
from globals_vars import app
global app
@app.route('/ext')
def ext():
yield 'file extra.py'
'''
try:
os.mkdir(sys.argv[1])
os.chdir(sys.argv[1])
os.mkdir("static")
os.mkdir("static/js")
os.mkdir("static/img")
os.mkdir("static/css")
os.mkdir("views")
f_globals = open("globals_vars.py", "w")
f_globals.write(globals_vars)
f_globals.close()
f_extra = open("extra.py", "w")
f_extra.write(extra)
f_extra.close()
f = open("start.py", "w")
f.write(main)
f.close()
os.chmod("start.py", stat.S_IWRITE|stat.S_IXUSR|stat.S_IREAD)
except FileExistsError:
print("Esiste giĆ una cartella con questo nome!")