From 5a29601684554e6758056de871bf4d82d6cf9289 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 4 May 2016 13:55:00 +0300 Subject: Add first version of script --- ql-ikiwiki-publish | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ql-ikiwiki-publish diff --git a/ql-ikiwiki-publish b/ql-ikiwiki-publish new file mode 100644 index 0000000..1e2e2e6 --- /dev/null +++ b/ql-ikiwiki-publish @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# Copyright 2016 QvarnLabs Ab +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# =*= License: GPL-3+ =*= + + +import os +import shutil +import subprocess +import sys +import tempfile + + +def mangle_setup(src, dest, html): + with open(src) as f: + text = f.read() + + lines = [ + line + for line in text.splitlines() + if not line.startswith('destdir:') + ] + + lines.append('destdir: {}'.format(html)) + + mangled = ''.join(line + '\n' for line in lines) + + with open(dest, 'w') as f: + f.write(mangled) + + +static_http = sys.argv[1] +rsync_target = 'static@{}:/srv/http/www.qvarn.org/.'.format(static_http) + +T = tempfile.mkdtemp() +try: + setup = os.path.join(T, 'ikiwiki.setup') + html = os.path.join(T, 'html') + mangle_setup('ikiwiki.setup', setup, html) + subprocess.check_call(['ikiwiki', '--setup', setup]) + subprocess.check_call( + ['rsync', '-ahHSvs', '--delete', html + '/.', rsync_target]) +except BaseException as e: + shutil.rmtree(T) + raise -- cgit v1.2.1