comparison bin/publishstaticweb.py @ 78:9a602d8eaa60

initial revision of the subversion repository
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 24 Apr 2012 17:13:43 +0200
parents
children 8ec9ed76d67b
comparison
equal deleted inserted replaced
77:f0aa5a8af056 78:9a602d8eaa60
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 sys
12 import os
13 from optparse import OptionParser
14 from ConfigParser import SafeConfigParser
15
16 import treepkgcmd
17 from treepkg.readconfig import read_config_section
18 from treepkg.run import call
19 from treepkg.cmdexpand import cmdexpand
20 from treepkg.util import ensure_directory
21
22 def remove_trailing_slashes(s):
23 return s.rstrip("/")
24
25 def expand_filename(filename):
26 """
27 Applies os.path.expanduser and os.path.expandvars to filename
28 """
29 return os.path.expandvars(os.path.expanduser(filename))
30
31 staticweb_desc = ["build_user", "build_host", "build_create",
32 ("build_dir", remove_trailing_slashes),
33 "publish_user", "publish_host",
34 ("publish_dir", remove_trailing_slashes),
35 ("cachedir",
36 lambda s: expand_filename(remove_trailing_slashes(s)))]
37
38 def read_config(filename):
39 parser = SafeConfigParser()
40 parser.read([filename])
41 return read_config_section(parser, "staticweb", staticweb_desc)
42
43 def parse_commandline():
44 parser = OptionParser()
45 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir,
46 "staticweb.cfg"))
47 parser.add_option("--config-file",
48 help=("The tree packager config file."
49 " Default staticweb.cfg"))
50 return parser.parse_args()
51
52 def publish_static_site(config_filename):
53 config = read_config(config_filename)
54
55 # create web-page on build host
56 call(cmdexpand("ssh $build_user$@$build_host $build_create $build_dir",
57 **config))
58
59 # rsync the new web-pages to the local cache
60 ensure_directory(config["cachedir"])
61 call(cmdexpand("rsync -rL --delete $build_user$@$build_host:$build_dir/"
62 " $cachedir",
63 **config))
64
65 # rsync the web pages from the local cache to the publishing host
66 call(cmdexpand("rsync -rL --delete $cachedir/"
67 " $publish_user$@$publish_host:$publish_dir",
68 **config))
69
70
71 def main():
72 options, args = parse_commandline()
73 publish_static_site(options.config_file)
74
75 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)