def main(self): """ creates a new thread for the web server and starts it Waits for stop requested to stop the web server thread """ flask_app = create_app() web_server = make_server('localhost', 8002, flask_app) web_server_process = Thread( target=web_server.serve_forever) try: web_server_process.start() self.logger.info('Started Web server on port 8002') except: self.logger.error('Couldn\'t start web server on port 8002, stopping') # start service loop while 1: time.sleep(2) if self.stop_requested: self.logger.info('Shutting down web server') web_server.shutdown() self.logger.info('Shutting down web server2') web_server_process.join(timeout=2) self.logger.info('Shutting down web server3') break # break out of service loop as stop requested
def main(): """ creates a new thread for the web server and starts it Waits for stop requested to stop the web server thread Also creates the systray aspect of the agent software """ logger = setup_logging() flask_app = create_app() server = make_server('0.0.0.0', 8002, flask_app) process = Thread(target=server.serve_forever) process.start() logger.info('Started Webserver on port 8002') connected_icon = 'connected.ico' disconnected_icon = 'disconnected.ico' hover_text = 'SELAgent' def hello(var): """ The hello test function """ print "Hello world." menu_options = (('About', None, hello), ('Switch Icon', None, hello), ('Tools', None, (('Example1', None, hello), ('Example2', None, hello)))) def bye(var): """ Callback from when the application is requested to quit """ server.shutdown() process.join(timeout=2) logger.info('Shutting down webserver') SysTrayIcon(connected_icon, hover_text, menu_options, on_quit=bye, default_menu_index=1)
from webapp.factory import create_app app = create_app() app.run(host='0.0.0.0', port=5000, debug=True)
def create_app(self): # pass in test configuration os.environ['APP_SETTINGS_FILE'] = 'settings/local.py' return create_app()
# coding=utf-8 # Set the settings file to the local version and run the app. import os from webapp import factory from webapp.views import services from flask_cors import CORS from flask_restful import Resource, Api, reqparse from webapp.models import generate_data os.environ['APP_SETTINGS_FILE'] = 'settings/local.py' app = factory.create_app() CORS(app) api = Api(app) parser = reqparse.RequestParser() parser.add_argument('politicianid', type=int) parser.add_argument('jail', type=bool) parser.add_argument('amount', type=int) class Services(Resource): def get(self): return services.get_data() def post(self): args = parser.parse_args() politician_id = str(args['politicianid']) jail = args['jail'] services.createEvent(politician_id, jail) return {"success": 'true'}
import os, sys PROJECT_DIR = '/home/vjousse/usr/fac/decodeur/voxolab_api' activate_this = os.path.join(PROJECT_DIR, 'env', 'bin', 'activate_this.py') #execfile(activate_this, dict(__file__=activate_this)) exec(compile(open(activate_this, "rb").read(), activate_this, 'exec'), dict(__file__=activate_this)) sys.path.append(PROJECT_DIR) from webapp.factory import create_app application = create_app()
"""Test app run.""" import webapp from webapp import factory if __name__ == "__main__": app = factory.create_app(celery=webapp.celery) app.run()