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