Mercurial > treepkg
comparison publishstaticweb.py @ 68:57a0b747ea3e
add publishstaticweb.py and demo config file
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 12 Apr 2007 20:05:18 +0200 |
parents | |
children | 43e6bdba84e2 |
comparison
equal
deleted
inserted
replaced
67:517253fa987f | 68:57a0b747ea3e |
---|---|
1 #! /usr/bin/python2.4 | |
2 # Copyright (C) 2007 by Intevation GmbH | |
3 # Authors: | |
4 # Bernhard Herzog <bh@intevation.de> | |
5 # | |
6 # This program is free software under the GPL (>=v2) | |
7 # Read the file COPYING coming with the software for details. | |
8 | |
9 """Publishes a static web-site with a status report""" | |
10 | |
11 import os | |
12 from optparse import OptionParser | |
13 from ConfigParser import SafeConfigParser | |
14 | |
15 from treepkg.readconfig import read_config_section | |
16 from treepkg.run import call | |
17 from treepkg.cmdexpand import cmdexpand | |
18 | |
19 def remove_trailing_slashes(s): | |
20 return s.rstrip("/") | |
21 | |
22 staticweb_desc = ["build_user", "build_host", "build_create", | |
23 ("build_dir", remove_trailing_slashes), | |
24 "publish_user", "publish_host", | |
25 ("publish_dir", remove_trailing_slashes), | |
26 ("cachedir", remove_trailing_slashes)] | |
27 | |
28 def read_config(filename): | |
29 parser = SafeConfigParser() | |
30 parser.read([filename]) | |
31 return read_config_section(parser, "staticweb", staticweb_desc) | |
32 | |
33 def parse_commandline(): | |
34 parser = OptionParser() | |
35 dirname = os.path.dirname(__file__) | |
36 parser.set_defaults(config_file=os.path.join(dirname, "staticweb.cfg")) | |
37 parser.add_option("--config-file", | |
38 help=("The tree packager config file." | |
39 " Default staticweb.cfg")) | |
40 return parser.parse_args() | |
41 | |
42 def publish_static_site(treepkg_config): | |
43 config = read_config(treepkg_config) | |
44 | |
45 # create web-page on build host | |
46 call(cmdexpand("ssh $build_user$@$build_host $build_create $build_dir", | |
47 **config)) | |
48 | |
49 # rsync the new web-pages to the local cache | |
50 call(cmdexpand("rsync -rL --delete $build_user$@$build_host:$build_dir/" | |
51 " $cachedir", | |
52 **config)) | |
53 | |
54 # rsync the web pages from the local cache to the publishing host | |
55 call(cmdexpand("rsync -rL --delete $cachedir/" | |
56 " $publish_user$@$publish_host:$publish_dir", | |
57 **config)) | |
58 | |
59 | |
60 def main(): | |
61 options, args = parse_commandline() | |
62 publish_static_site(options.config_file) | |
63 | |
64 main() |