From 715dde950a3ba6e414fdbe53666b1b3ee76dd592 Mon Sep 17 00:00:00 2001 From: David Thurstenson Date: Thu, 7 Oct 2021 07:06:57 -0500 Subject: [PATCH] replaced deploy script with management script --- .gitignore | 4 +-- deploy | 11 ------- tlwiki | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 13 deletions(-) delete mode 100755 deploy create mode 100755 tlwiki diff --git a/.gitignore b/.gitignore index daa8953..c77539a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,8 @@ # Content folder where the actual ...ya know... content lives !content/ -# Deploy script -!deploy +# Management script +!tlwiki # Themes directory !themes/ diff --git a/deploy b/deploy deleted file mode 100755 index 8efb8b3..0000000 --- a/deploy +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -# To auto-deploy this on git push, add a symlink at .git/hooks/pre-push that points to this script -# Example: ln -s ../../deploy .git/hooks/pre-push - -# Pull variables in from deploy_id -#source "$SCRIPT_DIR/deploy_id" -source "./deploy_id" - -# Generate and push the output to the server -hugo && rsync -avz --delete public/ ${USER}@${HOST}:${DIR} diff --git a/tlwiki b/tlwiki new file mode 100755 index 0000000..d1c5768 --- /dev/null +++ b/tlwiki @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 + + +import argparse +import yaml +import subprocess + + +# Valid commands +modecmds = [ + 'init', + 'deploy', + 'updeps', + 'clean', + 'reset', + 'nukepave'] + + +# Argument parsing setup +parser = argparse.ArgumentParser(description='Manage tlwiki source.') +parser.add_argument('mode', choices=modecmds, + help='Operation mode for this script') +parser.add_argument('--config', '-c', + default='tlwiki-conf.yaml', + type=argparse.FileType('r'), + help='Configuration file') + +args = parser.parse_args() + +# load config yaml into config dict +config = yaml.safe_load(args.config) + + +# General use functions + +def cmd_run(*cmdstr): + try: + subprocess.run(cmdstr, check=True) + except subprocess.CalledProcessError: + print('E: Running `' + ' '.join(cmdstr) + '` failed') + exit + + +# Mode functions + +def mode_clean(cfg): + cmd_run('git', 'clean', '-fd') + + +def mode_reset(cfg): + cmd_run('git', 'reset', '--hard', + cfg['repo']['remoteName'] + '/' + cfg['repo']['branch']) + + +def mode_init(cfg): + subprocess.run(['hugo', 'new', 'site', '.', '--force']) + + +def mode_updeps(cfg): + cmd_run('git', 'pull') + cmd_run('git', 'submodule', 'update', '--init', '--recursive') + + +def mode_deploy(cfg): + cmd_run('hugo') + deployid = cfg['deployID'] + cmd_run('rsync', '-avz', '--delete', + 'public/', + deployid['user'] + '@' + deployid['host'] + ':' + deployid['dir']) + + +# Mode switching + +if args.mode == 'init': + mode_init(config) +elif args.mode == 'deploy': + mode_init(config) + mode_deploy(config) +elif args.mode == 'updeps': + mode_updeps(config) +elif args.mode == 'clean': + mode_clean(config) +elif args.mode == 'reset': + mode_reset(config) +elif args.mode == 'nukepave': + mode_reset(config) + mode_clean(config) + mode_updeps(config) + mode_init(config) +else: + raise Exception("Invalid mode: " + args.mode) + exit