]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
works relatively okay
authorKarim Hamidou <karim@MacBook.local>
Sun, 28 Feb 2016 07:01:38 +0000 (23:01 -0800)
committerKarim Hamidou <karim@MacBook.local>
Sun, 28 Feb 2016 07:01:38 +0000 (23:01 -0800)
.gitignore
README.md [new file with mode: 0644]
build.py
convert_txt_rfc_to_html.py
src/__init__.py [new file with mode: 0644]
src/format_rfc.py [moved from src/format-rfc.py with 94% similarity]

index a18eb177a7795dd23c59f7d1411ea7f190ccc24a..fcc084e06778c66f9587c5a09d6041cece7963c2 100644 (file)
@@ -8,3 +8,4 @@ source_rfcs/*
 venv
 test.html
 out/
+html_rfcs/*
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..619ab78
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+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
index 1dd40d2cc69976a7fbf1b563220a691fea5ede33..239a945cb572e411db7059a12a691083620709d7 100644 (file)
--- a/build.py
+++ b/build.py
@@ -1,11 +1,15 @@
 #!/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)
@@ -15,8 +19,12 @@ def execute(command):
     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."
@@ -28,14 +36,7 @@ def generate_site_index(out_dir):
     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)}
 
@@ -46,9 +47,20 @@ def main():
         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)
 
index 0703559a5d32555532d12af8a8da7a5084aa1079..3c84260c6034ae42e47b3aab247151dfa8857aa7 100644 (file)
@@ -22,18 +22,10 @@ def list_files(directory, extension=''):
 
 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')}
 
@@ -41,10 +33,8 @@ def main():
         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)
 
 
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
similarity index 94%
rename from src/format-rfc.py
rename to src/format_rfc.py
index b66d0ec0ed1c062b4fa8db50011bfc2382b732c9..f2e28d41cf4307b1b1b91e83bd353883e4c87b57 100644 (file)
@@ -7,10 +7,10 @@ import sys
 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()
@@ -107,10 +107,10 @@ def process_file(infile, outfile):
     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)
 
@@ -126,7 +126,7 @@ def main():
     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()