def freeze_flask_app(app, config, target): target = os.path.abspath(target) freezer = Freezer(app) @freezer.register_generator def page(): for fn in os.listdir(os.path.join(config["_root"], "pages")): if fn.startswith("404"): continue _tmp = fn.rsplit(".", 1) if len(_tmp) == 1: yield {"name": _tmp[0]} else: if _tmp[1] in utils.ACCEPTED_EXTENSIONS: yield {"name": _tmp[0]} if config["blog"]: @freezer.register_generator def blog(): for i in xrange(1, app.blog.total_pages + 1): yield {"current_page": i} @freezer.register_generator def post(): for postid in app.blog.postid_to_index.keys(): yield {"postid": postid} app.config["FREEZER_DESTINATION"] = target app.config["FREEZER_DESTINATION_IGNORE"] = (".git*", "CNAME") freezer.freeze()
def freeze(test): """ Freezes application into a set of static files. """ freezer = Freezer(app) if test: freezer.run() else: freezer.freeze()
def saveFiles(): from app import updateDB, app, matches if matches: matches = matches['matches'] print matches updateDB() freezer = Freezer(app) # Create static html files freezer.freeze() with open('build/index.html','r') as html: output = fromString(html.read()) with open('build/send.html','w') as send_file: send_file.write(output) with open('build/send.txt','wb') as f: keys = matches[0].keys() dict_writer = csv.DictWriter(f, keys) dict_writer.writeheader() dict_writer.writerows(matches) return True else: print 'Looks like something wrong with date in initial URL, nothing saved' return False
def setup_freezer(app): """FIXME: not used and currently broken.""" def url_generator(): # URLs as strings yield '/fr/' freezer = Freezer(app) app.extensions['freezer'] = freezer freezer.register_generator(url_generator)
def freezer(app): blogposts = BlogPostCollection(os.path.join(os.environ['CONTENT_DIR'], 'blog')) blogposts.build() app.blogposts = blogposts freezer = Freezer(app) freezer.register_generator(url_generators.static.js) freezer.register_generator(url_generators.static.css) freezer.register_generator(url_generators.static.img) freezer.register_generator(url_generators.blog.article_list) freezer.freeze()
def build(build_destination=None): """Create a static version of the site with Frozen-Flask""" try: from flask.ext.frozen import Freezer except ImportError: import sys sys.exit("To create a static version of the site you need the " "Frozen-Flask package") if build_destination is not None: current_app.config['FREEZER_DESTINATION'] = build_destination else: current_app.config['FREEZER_DESTINATION'] = os.path.join( current_app.config["SOURCE"], "_build") freezer = Freezer(current_app) freezer.freeze()
def __init__(self, app=None, db=None, freezer=None): self.db = db or SQLAlchemy() self.freezer = freezer or Freezer(with_static_files=False) self.Model = create_model_base(self.db) self.app = app self._models = {} if app is not None: self.init_app(app)
def freeze(cls): buildPath = tempfile.mkdtemp() app.config.update( FREEZER_DESTINATION=PATH.RENDERED, FREEZER_RELATIVE_URLS=True, FREEZER_REMOVE_EXTRA_FILES=True, FREEZER_DESTINATION_IGNORE=['.git*', '*.idea']) freezer = Freezer(app) freezer.register_generator(fridge.path_route) with local.cwd(PATH.PROJECT): log.info("freezing %s", freezer) with open(PATH.LAST_UPDATE, 'w', encoding='utf') as f: f.write(date_from_timestamp()) seenUrls = freezer.freeze() log.info("frozen urls are:\n%s", '\n'.join(seenUrls)) cls.copytree(buildPath, PATH.RENDERED) cls.deliver_static_root_files() cls.remove_clutter() cls.write_bbcode_sources() if not INFO.IS_DEV_BOX: AdfdFixStagingPaths.fix_staging_paths() print("ADFD site successfully frozen!")
def build_pages(): ignored = [bundle.output for bundle in assets] app.config['FREEZER_DESTINATION'] = os.path.abspath("static") app.config['FREEZER_BASE_URL'] = "http://dabo.guru/" app.config['FREEZER_DESTINATION_IGNORE'] = ignored app.config['FREEZER_IGNORE_ENDPOINTS'] = ['oauth_respond', 'mc_api_name', 'mc_api_uuid', 'serve_markdown', 'uuid_api'] freezer = Freezer(app=app, with_static_files=False, with_no_argument_rules=False, log_url_for=True) freezer.register_generator(no_argument_rules_urls_with_ignore) freezer.register_generator(lambda: ("/favicon.ico",)) print("Freezing") freezer.freeze()
def main(self): freezer = Freezer(app) freezer.freeze()
def url(self, _external=False): return url_for('post', path=self.urlpath, _external = _external) def _initialize_metadata(self): content = '' with open(self.filepath, 'r') as fin: for line in fin: if not line.strip(): break content += line self.__dict__.update(yaml.load(content)) app = Flask(__name__) blog = Blog(app, root_dir = 'posts') freezer = Freezer(app) @app.template_filter('date') def format_date(value, format='%B %d, %Y'): return value.strftime(format) @app.route('/') def index(): return render_template('index.html', posts=blog.posts) @app.route('/series/<path:path>/') def post(path): post = blog.get_post_or_404(path) return render_template('post.html', post=post)
from flask.ext.frozen import Freezer from app import blog FREEZER_IGNORE_MIMETYPE_WARNINGS = True FREEZER_DESTINATION='/data/web/blog/build' FREEZER_BASE_URL = '/data/web/blog' freezer = Freezer(blog) if __name__ == '__main__': freezer.freeze()
#Flask class instance app = Flask(__name__) #app.config.from_object(__name__) # Search for configurations in current module/file #app.config.from_object(Configurations) # Use config class for configurations import settings app.config.from_object( settings) # Use the setting.py module/file with config values #app.config.from_pyfile('settings.py') # Use the setting.py module/file with config values #app.config.from_envvar('SETTINGS_FILE') # Set an env var SETTINGS_FILE with the absolute path of our settings file # List of posts posts = Posts(app, root_dir=app.config['POST_FILES_DIRECTORY']) freezer = Freezer(app) #Format dates @app.template_filter('date') def format_date(value, format='%B %d, %Y'): #Default format: %B %d, %Y return value.strftime(format) # Register function as a Jinja filter #app.jinja_env.filters['date'] = format_date # This context processor was used to pass the function - or any other value - to the template #@app.context_processor #def inject_format_date() :
import os import mimetypes from . import app, pages, redirects, serve_static from .filters import slugify from flask.ext.frozen import Freezer # Seems to be available only on some systems... mimetypes.add_type('application/atom+xml', '.atom') freezer = Freezer(app) @freezer.register_generator def redirect_url_generator(): return redirects.keys() @freezer.register_generator def static_url_generator(): return serve_static @freezer.register_generator def people_page(): for person in pages: if person.path.startswith('people/'): yield {'slug': slugify(person['name'])}
from flask.ext.frozen import Freezer from yalgaar.yalgaar import app from yalgaar.data.collect_tweets import collect_tweets f = Freezer(app) if __name__ == '__main__': #first get fresh tweets collect_tweets(tweet_type='recent', hashtag='#SaveTheInternet', limit=100) collect_tweets(tweet_type='popular', hashtag='#SaveTheInternet', limit=100) #now freeze them! f.freeze()
from flask.ext.frozen import Freezer from yalgaar import app f = Freezer(app) if __name__ == '__main__': f.freeze()
from flask import Flask, render_template from flask.ext.frozen import Freezer import os.path import sys import random # create app app = Flask(__name__) app.config['DEBUG'] = True app.config['FREEZER_BASE_URL'] = '/sei' app.config['FREEZER_DESTINATION'] = os.path.join('build', app.config['FREEZER_BASE_URL'][1:]) # create freezer freezer = Freezer(app, with_static_files=False) # variable random_url_version = str(random.randrange(1,1000000)) # add views @app.route('/') def index(): return render_template('index.html') # @app.route('/theory.html') # def theory(): # return render_template('theory.html') @app.route('/setup.html') def setup(): return render_template('setup.html')
from flask import Flask from flask.ext.flatpages import FlatPages from flask.ext.frozen import Freezer from flask.ext.bootstrap import Bootstrap from config import config pages = FlatPages() freezer = Freezer() bootstrap = Bootstrap() def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) freezer.init_app(app) pages.init_app(app) bootstrap.init_app(app) #register blueprints: from .main import main as main_blueprint app.register_blueprint(main_blueprint) return app
def freeze(): freezer = Freezer(current_app) freezer.freeze()
#!/usr/bin/env python2 from flask.ext.frozen import Freezer import main freezer = Freezer(main.APP) if __name__ == "__main__": freezer.freeze()
def freeze(): from flask.ext.frozen import Freezer freezer = Freezer(flask.current_app) freezer.freeze()
def serve_frozen(): freezer = Freezer(current_app) freezer.serve(host='0.0.0.0')