def handle(self, app, serve, no_index): app.jinja_loader # ugly workaround app.blohg.init_repo(REVISION_DEFAULT) app.url_map = self.remap_rules(app.url_map, no_index) # That's a risky one, it woud be better to give a parameter to the # freezer app.root_path = app.config.get('REPO_PATH') freezer = Freezer(app) def static_generator(static_dir): for f in app.blohg.changectx.files: if f.startswith(static_dir): yield dict(filename=f[len(static_dir):] \ .strip(posixpath.sep)) @freezer.register_generator def static(): """Walk the static dir and freeze everything""" return static_generator('static') @freezer.register_generator def attachments(): """Walk the attachment dir and freeze everything""" return static_generator(app.config['ATTACHMENT_DIR']) freezer.freeze() if serve: freezer.serve()
def process_preview(args): args.base = 'http://localhost:' + str(args.port) args.dir = create_temp_dir() app.config['FREEZER_DESTINATION'] = args.dir process_build(args) print ' * Tempdir %s' % args.dir freezer = Freezer(app) freezer.serve(port=args.port) print' * Deleting %s' % args.dir delete_dir(args.dir)
def get_projects(): offset = 0 newdata = [] while True: print "Requesting", API_BASE % ("recipient-country=PH&limit=50", offset) try: req = urllib2.Request((API_BASE % ("recipient-country=PH&limit=50", offset))) out = urllib2.urlopen(req).read() print "Retrieved, loading data" data = json.loads(out) for d in data['iati-activities']: newdata.append((d['iati-activity']['iati-identifier'], d)) offset+=50 except urllib2.HTTPError: break except Exception: pass return dict(newdata) if __name__ == '__main__': projects = get_projects() print "Site ready." if len(sys.argv) > 1 and sys.argv[1] == "build": if len(sys.argv)>2: freezer.freeze() freezer.serve() else: freezer.freeze() else: app.run(port=8000, debug=True)
if args['serve']: app.run( debug=get_option('debug'), port=int(args['--port']), host=args['--host'] ) elif args['fetch']: for name, url in app.config['DATA'].items(): filepath = get_data_filepath(app, name) fetch_remote_data(url, filepath) fetch_exchange_rates(app) elif args['build']: freezer.freeze() elif args['static']: freezer.serve( debug=get_option('debug'), port=int(args['--port']), host=args['--host'] ) elif args['i18n']: if args['extract']: babel_args = ['', 'extract', '-F', 'babel.cfg', '-o', 'messages.pot', '.'] elif args['compile']: babel_args = ['', 'compile', '-d', 'piati/translations'] elif args['update']: babel_args = ['', 'update', '-i', 'messages.pot', '-d', 'piati/translations'] CommandLineInterface().run(babel_args) elif args['shell']: import IPython IPython.embed()
def freeze(repo_path, disable_embedded_extensions, serve, noindex): '''Freeze the blog into a set of static files.''' app = _create_app(repo_path, disable_embedded_extensions) def remap_rules(map, map_html): """remaping the rules with files extensions""" mapping = {'views.source': 'txt', 'views.atom': 'atom'} if map_html: mapping['views.tag'] = 'html' mapping['views.content'] = 'html' mapping['views.post_list'] = 'html' mapping['views.posts'] = 'html' mapping['views.home'] = 'html' rules = [] for rule in map.iter_rules(): rule = rule.empty() if rule.is_leaf: # Add the leafs without modif. rules.append(rule) continue # special treatment for the robot.txt url if rule.rule == '/source/': rules.append(rule) continue try: extension = mapping[rule.endpoint] except KeyError: # the rest can go through rules.append(rule) continue # It becomes a leaf rule.is_leaf = True # and we add an extension url = rule.rule[:-1] if url == '': url = '/index' rule.rule = url + '.' + extension # and we add the modified rule rules.append(rule) return Map(rules) app.blohg.init_repo(REVISION_DEFAULT) app.url_map = remap_rules(app.url_map, noindex) app.config.setdefault('FREEZER_DESTINATION', os.path.join(app.config.get('REPO_PATH'), 'build')) freezer = Freezer(app) def static_generator(static_dir): for f in app.blohg.changectx.files: if f.startswith(static_dir): yield dict(filename=f[len(static_dir):] \ .strip(posixpath.sep)) @freezer.register_generator def static(): '''Walk the static dir and freeze everything''' return static_generator('static') @freezer.register_generator def attachments(): '''Walk the attachment dir and freeze everything''' return static_generator(app.config['ATTACHMENT_DIR']) freezer.freeze() if serve: freezer.serve()
vdom['attrs']['viewBox'] = f'0 0 {w} {h}' vdom['attrs'].pop('width', None) vdom['attrs'].pop('height', None) else: new_children.append(child) vdom.pop('children', None) if new_children: vdom['children'] = new_children for attr in ('transform', 'clip-path'): vdom['attrs'].pop(attr, None) vdom_id = vdom['attrs'].pop('id', None) if vdom_id is not None: vdom['attrs']['class'] = " ".join(vdom_id.split("/")) vdom['attrs']['xmlns'] = "http://www.w3.org/2000/svg" with open(fname, 'w') as f: json.dump(vdom, f, indent=2) directory.append({'symbol': symbol, 'id': item, 'url': fname}) with open(directory_file, 'w') as f: json.dump(directory, f, indent=2) if __name__ == "__main__": generate_assets('open-peeps.svg', 'assets/peeps') freezer = Freezer(app) freezer.freeze() if 'debug' in sys.argv: freezer.serve()
def freeze(repo_path, disable_embedded_extensions, serve, noindex): '''Freeze the blog into a set of static files.''' app = _create_app(repo_path, disable_embedded_extensions) def remap_rules(map, map_html): """remaping the rules with files extensions""" mapping = {'views.source': 'txt', 'views.atom': 'atom'} if map_html: mapping['views.tag'] = 'html' mapping['views.content'] = 'html' mapping['views.post_list'] = 'html' mapping['views.posts'] = 'html' mapping['views.home'] = 'html' rules = [] for rule in map.iter_rules(): rule = rule.empty() if rule.is_leaf: # Add the leafs without modif. rules.append(rule) continue # special treatment for the robot.txt url if rule.rule == '/source/': rules.append(rule) continue try: extension = mapping[rule.endpoint] except KeyError: # the rest can go through rules.append(rule) continue # It becomes a leaf rule.is_leaf = True # and we add an extension url = rule.rule[:-1] if url == '': url = '/index' rule.rule = url + '.' + extension # and we add the modified rule rules.append(rule) return Map(rules) app.blohg.init_repo(REVISION_DEFAULT) app.url_map = remap_rules(app.url_map, noindex) app.config.setdefault('FREEZER_DESTINATION', os.path.join( app.config.get('REPO_PATH'), 'build')) freezer = Freezer(app) def static_generator(static_dir): for f in app.blohg.changectx.files: if f.startswith(static_dir): yield dict(filename=f[len(static_dir):] \ .strip(posixpath.sep)) @freezer.register_generator def static(): '''Walk the static dir and freeze everything''' return static_generator('static') @freezer.register_generator def attachments(): '''Walk the attachment dir and freeze everything''' return static_generator(app.config['ATTACHMENT_DIR']) freezer.freeze() if serve: freezer.serve()
parser = argparse.ArgumentParser() parser.add_argument('--host', '-ht', type=str) parser.add_argument('--port', '-p', type=str) parser.add_argument('--freeze', '-f', action='store_true', default=False) parser.add_argument('--norun', '-n', action='store_true', default=False) args = parser.parse_args() host_val = args.host port_val = args.port do_freeze = args.freeze run = not args.norun if host_val is not None: host = host_val else: host = '127.0.0.1' if port_val is not None: port = port_val else: port = 5050 if do_freeze: print("freezing") freezer.freeze() print("frozen") if run: freezer.serve(host=host, port=port, threaded=True) else: application.run(host=host, port=port, threaded=True) # run from the command line as follows # python run.py -ht <ip address of your choice>