From 64ddd8263165a9c67deff13d340ef681f2cbf013 Mon Sep 17 00:00:00 2001 From: Kyle Marek-Spartz Date: Tue, 28 Jan 2014 13:56:49 -0600 Subject: [PATCH] Recopy css if it has been modified. --- script/generate_docs.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/script/generate_docs.py b/script/generate_docs.py index 1e2561de..4233364a 100755 --- a/script/generate_docs.py +++ b/script/generate_docs.py @@ -8,12 +8,7 @@ import sys import time from datetime import datetime -def format_file(path, skip_up_to_date): - basename = os.path.basename(path) - basename = basename.split('.')[0] - - out_path = "build/docs/" + basename + ".html" - +def compare_modification_times(path, out_path): # See if it's up to date. source_mod = os.path.getmtime(path) source_mod = max(source_mod, os.path.getmtime('doc/site/template.html')) @@ -21,8 +16,16 @@ def format_file(path, skip_up_to_date): dest_mod = 0 if os.path.exists(out_path): dest_mod = os.path.getmtime(out_path) + return source_mod < dest_mod - if skip_up_to_date and source_mod < dest_mod: +def format_file(path, skip_up_to_date): + basename = os.path.basename(path) + basename = basename.split('.')[0] + + out_path = "build/site/" + basename + ".html" + + if skip_up_to_date and compare_modification_times(path, out_path): + # It's up to date. return title = "" @@ -67,6 +70,14 @@ def format_file(path, skip_up_to_date): def format_files(skip_up_to_date): for f in glob.iglob("doc/site/*.markdown"): format_file(f, skip_up_to_date) + # Copy the CSS file. + css_in = "doc/site/style.css" + css_out = "build/site/style.css" + if skip_up_to_date and compare_modification_times(css_in, css_out): + pass + else: + shutil.copyfile(css_in, css_out) + print "copied css" # Clean the output directory. @@ -80,10 +91,7 @@ os.mkdir("build/docs") # Process each markdown file. format_files(False) -# Copy the CSS file. -shutil.copyfile("doc/site/style.css", "build/docs/style.css") - -# TODO(bob): Check for CSS modification. +# Watch files if len(sys.argv) == 2 and sys.argv[1] == '--watch': while True: format_files(True)