diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-05-04 13:55:00 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-05-04 13:55:00 +0300 |
commit | 5a29601684554e6758056de871bf4d82d6cf9289 (patch) | |
tree | b44110aeb26cf9eea45693432647668e1abd2992 | |
parent | b2e9edb26d4fd170d0d0be59028d84efd92df936 (diff) | |
download | ql-ikiwiki-publish-5a29601684554e6758056de871bf4d82d6cf9289.tar.gz |
Add first version of script
-rw-r--r-- | ql-ikiwiki-publish | 58 |
1 files changed, 58 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. +# +# =*= 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 |