def app(request): """Create application for the tests.""" datastore_path = "./test-datastore" try: os.mkdir(datastore_path) except FileExistsError: pass try: os.unlink("{}/url-watches.json".format(datastore_path)) except FileNotFoundError: pass app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore( datastore_path=app_config['datastore_path'], include_default_watches=False) app = changedetection_app(app_config, datastore) app.config['STOP_THREADS'] = True def teardown(): datastore.stop_thread = True app.config.exit.set() try: os.unlink("{}/url-watches.json".format(datastore_path)) except FileNotFoundError: # This is fine in the case of a failure. pass assert 1 == 1 request.addfinalizer(teardown) yield app
def app(request): """Create application for the tests.""" datastore_path = "./test-datastore" try: os.mkdir(datastore_path) except FileExistsError: pass # Enable a BASE_URL for notifications to work (so we can look for diff/ etc URLs) os.environ["BASE_URL"] = "http://mysite.com/" cleanup(datastore_path) app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore( datastore_path=app_config['datastore_path'], include_default_watches=False) app = changedetection_app(app_config, datastore) app.config['STOP_THREADS'] = True def teardown(): datastore.stop_thread = True app.config.exit.set() cleanup(datastore_path) request.addfinalizer(teardown) yield app
def main(argv): ssl_mode = False port = 5000 # Must be absolute so that send_from_directory doesnt try to make it relative to backend/ datastore_path = os.path.join(os.getcwd(), "datastore") try: opts, args = getopt.getopt(argv, "sd:p:", "purge") except getopt.GetoptError: print('backend.py -s SSL enable -p [port] -d [datastore path]') sys.exit(2) for opt, arg in opts: # if opt == '--purge': # Remove history, the actual files you need to delete manually. # for uuid, watch in datastore.data['watching'].items(): # watch.update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'previous_md5': None}) if opt == '-s': ssl_mode = True if opt == '-p': port = int(arg) if opt == '-d': datastore_path = arg # threads can read from disk every x seconds right? # front end can just save # We just need to know which threads are looking at which UUIDs # isnt there some @thingy to attach to each route to tell it, that this route needs a datastore app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore( datastore_path=app_config['datastore_path']) app = backend.changedetection_app(app_config, datastore) @app.context_processor def inject_version(): return dict(version=datastore.data['version_tag']) @app.context_processor def inject_new_version_available(): return dict(new_version_available=app.config['NEW_VERSION_AVAILABLE']) if ssl_mode: # @todo finalise SSL config, but this should get you in the right direction if you need it. eventlet.wsgi.server( eventlet.wrap_ssl(eventlet.listen(('', port)), certfile='cert.pem', keyfile='privkey.pem', server_side=True), app) else: eventlet.wsgi.server(eventlet.listen(('', port)), app)
def main(argv): ssl_mode = False port = os.environ.get('PORT') or 5000 do_cleanup = False # Must be absolute so that send_from_directory doesnt try to make it relative to backend/ datastore_path = os.path.join(os.getcwd(), "datastore") try: opts, args = getopt.getopt(argv, "csd:p:", "port") except getopt.GetoptError: print('backend.py -s SSL enable -p [port] -d [datastore path]') sys.exit(2) for opt, arg in opts: # if opt == '--purge': # Remove history, the actual files you need to delete manually. # for uuid, watch in datastore.data['watching'].items(): # watch.update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'previous_md5': None}) if opt == '-s': ssl_mode = True if opt == '-p': port = int(arg) if opt == '-d': datastore_path = arg # Cleanup (remove text files that arent in the index) if opt == '-c': do_cleanup = True # isnt there some @thingy to attach to each route to tell it, that this route needs a datastore app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path']) app = backend.changedetection_app(app_config, datastore) # Go into cleanup mode if do_cleanup: datastore.remove_unused_snapshots() app.config['datastore_path'] = datastore_path @app.context_processor def inject_version(): return dict(right_sticky="v{}".format(datastore.data['version_tag']), new_version_available=app.config['NEW_VERSION_AVAILABLE'], has_password=datastore.data['settings']['application']['password'] != False ) # Proxy sub-directory support # Set environment var USE_X_SETTINGS=1 on this script # And then in your proxy_pass settings # # proxy_set_header Host "localhost"; # proxy_set_header X-Forwarded-Prefix /app; if os.getenv('USE_X_SETTINGS'): print ("USE_X_SETTINGS is ENABLED\n") from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1, x_host=1) if ssl_mode: # @todo finalise SSL config, but this should get you in the right direction if you need it. eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', port)), certfile='cert.pem', keyfile='privkey.pem', server_side=True), app) else: eventlet.wsgi.server(eventlet.listen(('', port)), app)