add argparse & the ability to deploy site
This commit is contained in:
parent
ed93d0446b
commit
30c41674a7
44
build.py
44
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()
|
||||
|
Loading…
Reference in New Issue
Block a user