1
0
forked from Mirror/wren

Recopy css if it has been modified.

This commit is contained in:
Kyle Marek-Spartz
2014-01-28 13:56:49 -06:00
parent 25a6565f9f
commit 64ddd82631

View File

@ -8,12 +8,7 @@ import sys
import time import time
from datetime import datetime from datetime import datetime
def format_file(path, skip_up_to_date): def compare_modification_times(path, out_path):
basename = os.path.basename(path)
basename = basename.split('.')[0]
out_path = "build/docs/" + basename + ".html"
# See if it's up to date. # See if it's up to date.
source_mod = os.path.getmtime(path) source_mod = os.path.getmtime(path)
source_mod = max(source_mod, os.path.getmtime('doc/site/template.html')) 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 dest_mod = 0
if os.path.exists(out_path): if os.path.exists(out_path):
dest_mod = os.path.getmtime(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 return
title = "" title = ""
@ -67,6 +70,14 @@ def format_file(path, skip_up_to_date):
def format_files(skip_up_to_date): def format_files(skip_up_to_date):
for f in glob.iglob("doc/site/*.markdown"): for f in glob.iglob("doc/site/*.markdown"):
format_file(f, skip_up_to_date) 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. # Clean the output directory.
@ -80,10 +91,7 @@ os.mkdir("build/docs")
# Process each markdown file. # Process each markdown file.
format_files(False) format_files(False)
# Copy the CSS file. # Watch files
shutil.copyfile("doc/site/style.css", "build/docs/style.css")
# TODO(bob): Check for CSS modification.
if len(sys.argv) == 2 and sys.argv[1] == '--watch': if len(sys.argv) == 2 and sys.argv[1] == '--watch':
while True: while True:
format_files(True) format_files(True)