#!/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] dirname = sys.argv[2] rsync_target = 'static@{}:/srv/http/{}/.'.format(static_http, dirname) 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 else: shutil.rmtree(T)