From 30c41674a713d5d5cd732b6705ad20eaa50bcbf9 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 30 Jun 2021 16:22:51 -0400 Subject: [PATCH] add argparse & the ability to deploy site --- build.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/build.py b/build.py index c226369..3a2831b 100644 --- a/build.py +++ b/build.py @@ -1,21 +1,14 @@ #!/usr/bin/env python3 -# Usage: -# -# cd ~/src/www-builder -# python3 build.py -# cd output -# cp -r * ~/src/www-home -# cd ~/src/www-home -# git status -# git add [some stuff] -# git commit -# git push +# Assumes that there's a directory named ~/src/www-home which is a git repo +# that the contents of output/ can be copied to, committed, & pushed to the +# production server. # TODO: replace gallery.tinyletterapp.com images with locally hosted content. # TODO: in template.html, add apple touch icon, maybe other favicon sizes. # TODO: local mirrors of all papers in publications.html +import argparse import glob import markdown import os @@ -26,6 +19,7 @@ import shutil input_directory = 'content' static_directory = 'static' output_directory = 'output' +deploy_directory = '~/src/www-home' md_extensions = ['fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify'] @@ -104,13 +98,39 @@ def make_rss(): # TODO: implement. pass +def deploy_site(): + os.system('cp -r output/* %s' % deploy_directory) + os.chdir(os.path.expanduser(deploy_directory)) + os.system('git add .') + os.system('git commit -m "automated update from build.py"') + os.system('git push') + + def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + '--clean', action='store_true', + help='wipe the output directory before running') + parser.add_argument( + '--fast', action='store_true', + help='only rebuild content files') + parser.add_argument( + '--deploy', action='store_true', + help='deploy the site by pushing to the www-home git repo') + args = parser.parse_args() + + if args.clean: + shutil.rmtree(output_directory) os.makedirs(output_directory, exist_ok=True) - copy_static_files() + if not args.fast: + copy_static_files() process_markdown_files() make_sitemap() make_rss() + if args.deploy: + deploy_site() + if __name__ == '__main__': main()