From 47007713cac964d9a50ce814178f54f13bb54b98 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Mon, 15 Feb 2016 21:30:25 -0800 Subject: [PATCH] add a build script --- build.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 build.py diff --git a/build.py b/build.py new file mode 100644 index 00000000..2c649cda --- /dev/null +++ b/build.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# a simple incremental build script. +# usage build.py src_dir/ output_dir +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)) and f.endswith('.html')] + + +def build_file(infile, outfile): + command = ['python', 'src/format-rfc.py', infile, outfile] + print " ".join(command) + return subprocess.call(command) + + +def main(): + if len(sys.argv) != 3: + print "usage: build.py " + 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)} + 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 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() -- 2.43.0