bh@68: #! /usr/bin/python2.4 bh@68: # Copyright (C) 2007 by Intevation GmbH bh@68: # Authors: bh@68: # Bernhard Herzog bh@68: # bh@68: # This program is free software under the GPL (>=v2) bh@68: # Read the file COPYING coming with the software for details. bh@68: bh@68: """Publishes a static web-site with a status report""" bh@68: bh@68: import os bh@68: from optparse import OptionParser bh@68: from ConfigParser import SafeConfigParser bh@68: bh@68: from treepkg.readconfig import read_config_section bh@68: from treepkg.run import call bh@68: from treepkg.cmdexpand import cmdexpand bh@68: bh@68: def remove_trailing_slashes(s): bh@68: return s.rstrip("/") bh@68: bh@68: staticweb_desc = ["build_user", "build_host", "build_create", bh@68: ("build_dir", remove_trailing_slashes), bh@68: "publish_user", "publish_host", bh@68: ("publish_dir", remove_trailing_slashes), bh@68: ("cachedir", remove_trailing_slashes)] bh@68: bh@68: def read_config(filename): bh@68: parser = SafeConfigParser() bh@68: parser.read([filename]) bh@68: return read_config_section(parser, "staticweb", staticweb_desc) bh@68: bh@68: def parse_commandline(): bh@68: parser = OptionParser() bh@68: dirname = os.path.dirname(__file__) bh@68: parser.set_defaults(config_file=os.path.join(dirname, "staticweb.cfg")) bh@68: parser.add_option("--config-file", bh@68: help=("The tree packager config file." bh@68: " Default staticweb.cfg")) bh@68: return parser.parse_args() bh@68: bh@68: def publish_static_site(treepkg_config): bh@68: config = read_config(treepkg_config) bh@68: bh@68: # create web-page on build host bh@68: call(cmdexpand("ssh $build_user$@$build_host $build_create $build_dir", bh@68: **config)) bh@68: bh@68: # rsync the new web-pages to the local cache bh@68: call(cmdexpand("rsync -rL --delete $build_user$@$build_host:$build_dir/" bh@68: " $cachedir", bh@68: **config)) bh@68: bh@68: # rsync the web pages from the local cache to the publishing host bh@68: call(cmdexpand("rsync -rL --delete $cachedir/" bh@68: " $publish_user$@$publish_host:$publish_dir", bh@68: **config)) bh@68: bh@68: bh@68: def main(): bh@68: options, args = parse_commandline() bh@68: publish_static_site(options.config_file) bh@68: bh@68: main()