diff options
-rwxr-xr-x | make_guides.py | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/make_guides.py b/make_guides.py index 40c2c3b..42ce90b 100755 --- a/make_guides.py +++ b/make_guides.py @@ -15,8 +15,33 @@ def basename(fname): def build_latex(guide): '''Builds the LaTeX source for the guide''' + src_dir = os.path.join('guides',guide) + tools_dir = 'tools' build_dir = os.path.join('build',guide) tex_name = guide+'.tex' + # Check if we need to (re)build + rebuild = False + try: + tex_time = os.stat(os.path.join(build_dir,tex_name)).st_mtime + # the source has changed? + for dirpath, dirnames, filenames in os.walk(src_dir): + for src_file in filenames: + src_time = os.stat(os.path.join(dirpath,src_file)).st_mtime + if src_time > tex_time: + rebuild = True + break + # a template has changed? + for dirpath, dirnames, filenames in os.walk(tools_dir): + for src_file in filenames: + src_time = os.stat(os.path.join(dirpath,src_file)).st_mtime + if src_time > tex_time: + rebuild = True + break + except (IOError,OSError): + rebuild = True + if not rebuild: + return None + # Build the LaTeX source # DEBUG print('Building LaTeX...') if not os.path.isdir(build_dir): @@ -31,8 +56,15 @@ def build_pdf(guide): tex_name = guide+'.tex' pdf_name = guide+'.pdf' # check for prerequisites - if not os.path.isfile(os.path.join(build_dir,tex_name)): - build_latex(guide) + build_latex(guide) + # Check if we need to (re)build + tex_time = os.stat(os.path.join(build_dir,tex_name)).st_mtime + try: + pdf_time = os.stat(os.path.join(dist_dir,pdf_name)).st_mtime + if pdf_time > tex_time: + return None + except OSError: + pass # DEBUG print('Building PDF...') if not os.path.isdir(dist_dir): @@ -46,8 +78,15 @@ def build_nup_pdf(guide): pdf_name = guide+'.pdf' nup_name = guide+'-A6suA4.pdf' # check for prerequisites - if not os.path.isfile(os.path.join(dist_dir,pdf_name)): - build_pdf(guide) + build_pdf(guide) + # Check if we need to (re)build + pdf_time = os.stat(os.path.join(dist_dir,pdf_name)).st_mtime + try: + nup_time = os.stat(os.path.join(dist_dir,nup_name)).st_mtime + if nup_time > pdf_time: + return None + except OSError: + pass # DEBUG print('Building nup PDF...') if not os.path.isdir(dist_dir): @@ -56,7 +95,8 @@ def build_nup_pdf(guide): fp.close() def main(): - parser = argparse.ArgumentParser(description='Build a distribution format of a 1800 words article') + parser = argparse.ArgumentParser(description='Build a distribution format of a 1800 words article', + epilog='Prerequisites of required formats are build automatically, but you may want to build the LaTeX source first, edit it by hand and then build the rest.') parser.add_argument('guide', nargs='+', type=basename, help='Source directory of the article') parser.add_argument('-l','--latex',action='store_true', |