add argparse & the ability to deploy site
This commit is contained in:
parent
ed93d0446b
commit
30c41674a7
42
build.py
42
build.py
@ -1,21 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Usage:
|
# 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
|
||||||
# cd ~/src/www-builder
|
# production server.
|
||||||
# python3 build.py
|
|
||||||
# cd output
|
|
||||||
# cp -r * ~/src/www-home
|
|
||||||
# cd ~/src/www-home
|
|
||||||
# git status
|
|
||||||
# git add [some stuff]
|
|
||||||
# git commit
|
|
||||||
# git push
|
|
||||||
|
|
||||||
# TODO: replace gallery.tinyletterapp.com images with locally hosted content.
|
# TODO: replace gallery.tinyletterapp.com images with locally hosted content.
|
||||||
# TODO: in template.html, add apple touch icon, maybe other favicon sizes.
|
# TODO: in template.html, add apple touch icon, maybe other favicon sizes.
|
||||||
# TODO: local mirrors of all papers in publications.html
|
# TODO: local mirrors of all papers in publications.html
|
||||||
|
|
||||||
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import markdown
|
import markdown
|
||||||
import os
|
import os
|
||||||
@ -26,6 +19,7 @@ import shutil
|
|||||||
input_directory = 'content'
|
input_directory = 'content'
|
||||||
static_directory = 'static'
|
static_directory = 'static'
|
||||||
output_directory = 'output'
|
output_directory = 'output'
|
||||||
|
deploy_directory = '~/src/www-home'
|
||||||
|
|
||||||
md_extensions = ['fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify']
|
md_extensions = ['fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify']
|
||||||
|
|
||||||
@ -104,13 +98,39 @@ def make_rss(): # TODO: implement.
|
|||||||
pass
|
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():
|
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)
|
os.makedirs(output_directory, exist_ok=True)
|
||||||
|
if not args.fast:
|
||||||
copy_static_files()
|
copy_static_files()
|
||||||
process_markdown_files()
|
process_markdown_files()
|
||||||
make_sitemap()
|
make_sitemap()
|
||||||
make_rss()
|
make_rss()
|
||||||
|
|
||||||
|
if args.deploy:
|
||||||
|
deploy_site()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user