annotate publishstaticweb.py @ 69:b52779523392

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