def test_all_together(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_folder("static") appcache.add_urls("/") appcache.add_urls("/test") @app.route("/") def main(): return "yay" @app.route("/test") def test(): return "yay!!" urls = appcache.urls self.assertEquals(4, len(urls)) self.assertTrue("/" in urls) self.assertTrue("/test" in urls) self.assertTrue("/static/static1.js" in urls) self.assertTrue("/static/static2.css" in urls) # so there is a hash.. hash, updated = appcache.hash() self.assertTrue(hash) self.assertTrue(updated)
def test_excluded_urls(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_excluded_urls("/static/develop") appcache.add_urls("/static/develop/js.js") self.assertEquals(0, len(appcache.urls)) appcache.add_urls("/static/js.js") self.assertEquals(1, len(appcache.urls)) app = Flask(__name__) appcache = Appcache(app) appcache.add_excluded_urls("/static/ignored") appcache.add_folder("test_ignore", base="/static") urls = list(appcache.urls) self.assertEquals(1, len(urls)) self.assertEquals("/static/not_ignored", urls[0])
def test_add_folders(self): app = Flask(__name__) appcache = Appcache(app) appcache.add_folder("static", base="/static") urls = appcache.urls self.assertEquals(2, len(urls)) self.assertTrue("/static/static1.js" in urls) self.assertTrue("/static/static2.css" in urls) app = Flask(__name__) appcache = Appcache(app) appcache.add_folder("static", base="/media") urls = appcache.urls self.assertEquals(2, len(urls)) self.assertTrue("/media/static1.js" in urls) self.assertTrue("/media/static2.css" in urls)
filename), content=content) # Sets up Appcache appcache = Appcache(app) if app.debug: appcache.add_excluded_urls('/static/js/app.min.js', '/static/css/app.min.css') else: appcache.add_excluded_urls('/static/js/develop') appcache.add_excluded_urls('/static/css/develop') appcache.add_excluded_urls('/static/partials') appcache.add_excluded_urls('/static/js/tests') appcache.add_excluded_urls('/static/.webassets-cache') appcache.add_folder('static') appcache.add_urls('/meta.js', '/') @app.before_request def before_request(): app.jinja_env.globals['partials'] = PARTIALS @app.route('/manifest.webapp') def manifest_webapp(): return send_file('manifest.webapp', mimetype='application/x-web-app-manifest+json') @app.route('/images')
tuner.power_off() logger.info(" tuner off {}") return str(status) def exit_handler(): print('Flask is exiting') mqttc.loop_stop() if os.uname()[4].startswith("arm"): print('cleanup') GPIO.cleanup() appcache.add_urls("/") appcache.add_folder(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static'), base="/static") mqttc = mosquitto.Mosquitto() mosquittoHandler = MosquittoHandler(projector, tuner) mqttc.on_message = mosquittoHandler.on_message mqttc.on_connect = mosquittoHandler.on_connect mqttc.connect("127.0.0.1", 1883, 60) if __name__ == '__main__': # app.run() atexit.register(exit_handler) port = 5000 if os.uname()[4].startswith("arm"): port = 80
import os # BeautifulSoup for legacy reasons. This code is old! from BeautifulSoup import BeautifulSoup from flask import Flask, render_template, jsonify, send_file from flask.ext.appcache import Appcache VERSION = "2.0" app = Flask(__name__) app.config.from_pyfile("settings.py") app.config.from_pyfile("settings_local.py", silent=True) appcache = Appcache(app) appcache.add_urls("/") appcache.add_folder(os.path.join(os.path.dirname(os.path.abspath(__file__)), "static"), base="/static") class AppURLOpener(urllib.FancyURLopener): version = "BetterSudburyBusTracker/{}".format(VERSION) urllib._urlopener = AppURLOpener() # Ogod. This is code from 2011! With some mods and commentary. class StopNotFoundError(Exception): pass class BusStop(object): """A stop object, hides all the details of interacting with the city's site""" # URL to get details about the stop QUERY_URL = "http://mybus.sudbury.ca/MobileQuery.aspx?hpl={}" # Regex for finding the stop name. heh