From c88c2f8df789b129870351f192ce3aa11fce45d7 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Wed, 16 Mar 2016 18:45:45 -0700 Subject: [PATCH] Add heroku files --- Procfile | 1 + app.py | 46 +++++++++++++++++++++++++++ build.py | 64 -------------------------------------- convert_txt_rfc_to_html.py | 42 ------------------------- requirements.txt | 3 ++ 5 files changed, 50 insertions(+), 106 deletions(-) create mode 100644 Procfile create mode 100644 app.py delete mode 100644 build.py delete mode 100644 convert_txt_rfc_to_html.py diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..91f7f3be --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn -w 4 -b 0.0.0.0:$PORT -k gevent app:app diff --git a/app.py b/app.py new file mode 100644 index 00000000..bb211f9e --- /dev/null +++ b/app.py @@ -0,0 +1,46 @@ +import os +from flask import Flask, render_template, request, redirect, url_for + +app = Flask(__name__) +app.config['SECRET_KEY'] = os.environ['SECRET_KEY'] + +### +# Routing for your application. +### + +@app.route('/') +def home(): + """Render website's home page.""" + return render_template('index.html') + + +### +# The functions below should be applicable to all Flask apps. +### + +@app.route('/.txt') +def send_text_file(file_name): + """Send your static text file.""" + file_dot_text = file_name + '.txt' + return app.send_static_file(file_dot_text) + + +@app.after_request +def add_header(response): + """ + Add headers to both force latest IE rendering engine or Chrome Frame, + and also to cache the rendered page for 10 minutes. + """ + response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1' + response.headers['Cache-Control'] = 'public, max-age=600' + return response + + +@app.errorhandler(404) +def page_not_found(error): + """Custom 404 page.""" + return render_template('404.html'), 404 + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/build.py b/build.py deleted file mode 100644 index 210f52f9..00000000 --- a/build.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# a simple incremental build script. -# usage build.py src_dir/ output_dir -import os -import sys -import subprocess -from os import listdir -from os.path import isfile, join, getmtime - - -def list_files(directory): - return [f for f in listdir(directory) - if isfile(join(directory, f))] - -def execute(command): - return subprocess.call(command) - -def build_file(infile, outfile): - print "Building {}".format(outfile) - - execute(['python', 'src/render_rfc.py', infile, outfile]) - -def copy_static(out_dir): - print "Copying static files." - command = ['cp', '-r', 'static', out_dir] - execute(command) - -def generate_site_index(out_dir): - print "Creating index file." - command = ['python', 'src/generate-site-index.py', out_dir, join(out_dir, 'index.html')] - execute(command) - -def build_rfcs(src_dir, dest_dir): - src_files = {filename: join(src_dir, filename) for filename in list_files(src_dir)} - dest_files = {filename: join(dest_dir, filename) for filename in list_files(dest_dir)} - - for filename in src_files: - src_path = join(src_dir, filename) - dest_path = join(dest_dir, filename) - - if '.txt' in dest_path: - dest_path = dest_path.split('.txt')[0] + '.html' - - if filename not in dest_files: - build_file(src_path, dest_path) - - if os.path.exists(dest_path) and getmtime(src_path) > getmtime(dest_path): - build_file(src_path, dest_path) - - -def main(): - if len(sys.argv) != 3: - print "usage: build.py " - sys.exit(-1) - - src_dir = sys.argv[1] - dest_dir = sys.argv[2] - - #build_rfcs(src_dir, dest_dir) - copy_static(dest_dir) - generate_site_index(dest_dir) - -if __name__ == '__main__': - main() diff --git a/convert_txt_rfc_to_html.py b/convert_txt_rfc_to_html.py deleted file mode 100644 index 3c84260c..00000000 --- a/convert_txt_rfc_to_html.py +++ /dev/null @@ -1,42 +0,0 @@ -# We're getting RFCs from the IETF's rsync server. -# These RFCs are in text format, so we need to use the -# IETF's rfcmarkup to convert them to HTML. This html is -# then used by format-rfc to make a pretty rfc. -import sys -import subprocess -from os import listdir -from os.path import (isfile, join, getmtime, splitext, - basename, dirname) - - -def list_files(directory, extension=''): - l = [] - files = listdir(directory) - - for f in files: - filename, ext = splitext(f) - if isfile(join(directory, f)) and extension in ext: - l.append(filename) - return l - - -def build_file(infile, outfile): - with open(outfile, 'w+') as fd: - command = ['python', 'src/rfcmarkup', dirname(infile), infile] - subprocess.call(command, stdout=fd) - -def convert_rfc_html(src_dir, dest_dir): - src_files = {filename: join(src_dir, filename) for filename in list_files(src_dir, 'txt')} - dest_files = {filename: join(dest_dir, filename) for filename in list_files(dest_dir, 'html')} - - for filename in src_files: - src_path = join(src_dir, filename) + '.txt' - dest_path = join(dest_dir, filename) + '.html' - - if filename not in dest_files or getmtime(src_path) > getmtime(dest_path): - print "Building {}".format(src_path) - build_file(src_path, dest_path) - - -if __name__ == '__main__': - main() diff --git a/requirements.txt b/requirements.txt index 31c0090e..da9da8b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ jinja2==2.8 +flask==0.10.1 +gevent==1.1.0 +gunicorn==19.4.5 -- 2.43.0