venv
test.html
out/
+html_rfcs/*
--- /dev/null
+Building instructions:
+
+1. Download the latest RFC archives from rfc-editor.org:
+ `rsync -avz ftp.rfc-editor.org::rfcs-text-only .`
+
+2. Run build.py
#!/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
+from convert_txt_rfc_to_html import convert_rfc_html
+from src.format_rfc import format_rfc, ProcessingError
+TMP_DIR = 'html_rfcs'
def list_files(directory):
return [f for f in listdir(directory)
return subprocess.call(command)
def build_file(infile, outfile):
- command = ['python', 'src/format-rfc.py', infile, outfile]
- execute(command)
+ print "Building {}".format(outfile)
+
+ try:
+ format_rfc(infile, outfile)
+ except ProcessingError:
+ print "Skipping {}".format(infile)
def copy_css(out_dir):
print "Copying CSS."
command = ['python', 'src/generate-site-index.py', out_dir, join(out_dir, 'index.html')]
execute(command)
-def main():
- if len(sys.argv) != 3:
- print "usage: build.py <src dir> <output dir>"
- sys.exit(-1)
-
- src_dir = sys.argv[1]
- dest_dir = sys.argv[2]
-
+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)}
if filename not in dest_files:
build_file(src_path, dest_path)
- if getmtime(src_path) > getmtime(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 <src dir> <output dir>"
+ sys.exit(-1)
+
+ src_dir = sys.argv[1]
+ dest_dir = sys.argv[2]
+
+ convert_rfc_html(src_dir, TMP_DIR)
+ build_rfcs(TMP_DIR, dest_dir)
copy_css(dest_dir)
generate_site_index(dest_dir)
def build_file(infile, outfile):
with open(outfile, 'w+') as fd:
- command = ['python', 'src/rfcmarkup', dirname(infile), splitext(basename(infile))[0]]
+ command = ['python', 'src/rfcmarkup', dirname(infile), infile]
subprocess.call(command, stdout=fd)
-
-def main():
- if len(sys.argv) != 3:
- print "usage: convert_txt_to_html <src dir> <output dir>"
- sys.exit(-1)
-
- src_dir = sys.argv[1]
- dest_dir = sys.argv[2]
-
+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')}
src_path = join(src_dir, filename) + '.txt'
dest_path = join(dest_dir, filename) + '.html'
- if filename not in dest_files:
- build_file(src_path, dest_path)
-
- if getmtime(src_path) > getmtime(dest_path):
+ if filename not in dest_files or getmtime(src_path) > getmtime(dest_path):
+ print "Building {}".format(src_path)
build_file(src_path, dest_path)
from bs4 import BeautifulSoup, Tag, Comment
from jinja2 import Environment, FileSystemLoader
-class ProcessingException(Exception):
+class ProcessingError(Exception):
pass
-def process_file(infile, outfile):
+def format_rfc(infile, outfile):
data = ''
with open(infile) as fd:
data = fd.read()
soup = BeautifulSoup(contents, 'html.parser')
# Finally, extract the body:
- body_contents = soup.body.find('div', class_='content')
+ body_contents = soup.body # .find('div', class_='content')
if body_contents is None:
- raise ProcessingException("Couldn't find a content block")
+ raise ProcessingError("Couldn't find a content block")
dct = dict(rfc=body_contents.prettify(), title=title)
if len(sys.argv) != 3:
print "usage: format-rfc rfc.html pretty_rfc.html"
- process_file(sys.argv[1], sys.argv[2])
+ format_rfc(sys.argv[1], sys.argv[2])
if __name__ == '__main__':
main()