From: Karim Hamidou Date: Thu, 25 Feb 2016 05:02:24 +0000 (-0800) Subject: WIP X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=12920345149918b666b9c3b8fbfcd2dc9b58fc3b;p=rfcspot.git WIP --- diff --git a/convert_txt_rfc_to_html.py b/convert_txt_rfc_to_html.py new file mode 100644 index 00000000..b7178981 --- /dev/null +++ b/convert_txt_rfc_to_html.py @@ -0,0 +1,52 @@ +# 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, filter_fn=None): + # returns a list of + files = listdir(directory) + + if filter_fn is not None: + files = filter(filter_fn, files) + + l = [splitext(f)[0] for f in files if isfile(join(directory, f))] + return l + + +def build_file(infile, outfile): + with open(outfile, 'w+') as fd: + command = ['python', 'src/rfcmarkup', dirname(infile), basename(infile)] + subprocess.call(command, stdout=fd) + + +def main(): + if len(sys.argv) != 3: + print "usage: convert_txt_to_html " + sys.exit(-1) + + src_dir = sys.argv[1] + dest_dir = sys.argv[2] + + src_files = {filename: join(src_dir, filename) for filename in list_files(src_dir, lambda x: True if splitext(x)[1] == '.txt' else False)} + 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) + '.html' + + if filename not in dest_files: + build_file(src_path, dest_path) + + if getmtime(src_path) > getmtime(dest_path): + build_file(src_path, dest_path) + + +if __name__ == '__main__': + main() diff --git a/src/rfcmarkup b/src/rfcmarkup old mode 100644 new mode 100755 index 77d05c11..68a234df --- a/src/rfcmarkup +++ b/src/rfcmarkup @@ -400,7 +400,7 @@ def version(): def usage(): print usagetext -def markup(): +def markup(cmdline_args): global args # sys.stderr = sys.stdout extra = "" @@ -412,9 +412,9 @@ def markup(): charter = None info = {} attribs = {} - fields = cgi.FieldStorage() + fields = cmdline_args for key in fields.keys(): - attribs[key] = fields[key].value + attribs[key] = fields[key] script = os.environ.get("SCRIPT_NAME", sys.argv[0]) @@ -439,14 +439,7 @@ def markup(): ids = fields["repository"].value + "/internet-drafts" extra = extra + "repository=%s&" % fields["repository"].value else: - if os.path.exists("/home/ietf/rfc"): - rfcs = "file:///home/ietf/rfc" - else: - rfcs = "http://tools.ietf.org/rfc" - if os.path.exists("/home/ietf/id"): - ids = "file:///home/ietf/id" - else: - ids = "http://tools.ietf.org/id" + rfcs = fields['folder'] if fields.has_key("rfc-repository"): rfcs = fields["rfc-repository"].value @@ -498,9 +491,9 @@ def markup(): # if not url[-4:] == ".txt": # url = url + ".txt" elif fields.has_key("rfc"): - rfc = fields["rfc"].value - url = "%s/rfc%s.txt" % (rfcs, rfc) - args["title"] = "rfc "+fields["rfc"].value + rfc = fields["rfc"] + url = "%s" % rfc + args["title"] = "rfc "+fields["rfc"] args["doc"] = "rfc"+rfc elif fields.has_key("bcp"): bcp = fields["bcp"].value @@ -1356,4 +1349,4 @@ if __name__ == "__main__": usage() sys.exit() - markup() + markup({"folder": sys.argv[1], "rfc": sys.argv[2]})