Skip to content

Instantly share code, notes, and snippets.

@Back2Basics
Last active January 4, 2016 18:59
Show Gist options
  • Save Back2Basics/8664205 to your computer and use it in GitHub Desktop.
Save Back2Basics/8664205 to your computer and use it in GitHub Desktop.
webserver
from multiprocessing import Process
import webbrowser as wb
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
def webserver():
""" Collects info from a webform
to put on the server and later to write the landesk custom data file"""
app = Flask(__name__)
from flask import request
@app.route('/shutdown', methods=['GET'])
def shutdown():
shutdown_server()
return 'Server shutting down...'
@app.route("/", methods=['POST', 'GET'])
def hello(name=None):
if request.method == 'POST':
computer_info = {
# macaddress isn't asked for
'ask_for_stuff' : request.form['Stuff_asked_for']
#...
}
put_data_on_server(computer_info)
return redirect("http://localhost:5000/shutdown", code=302)
#shutdown() #didn't work
else:
#macaddress is a generated value
data = {
'Stuff_asked_for' : '',
#...
}
return render_template('index.html', data=data)
try:
app.run()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
computer_info=get_data_from_server()
if not computer_info:
#then ask the user for the info
q = Process(target=wb.open, args=['http://localhost:5000/'])
q.start()
webserver()
q.terminate()
#this call should block until the webserver is closed
write_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment