#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Runs the daily build of the Python docs on dinsdale.python.org.
#
# Usages:
#
#   dailybuild.py
#
# without any arguments builds docs for all branches configured in the global
# BRANCHES value.
#
#   dailybuild.py [-d] <checkout> <target>
#
# builds one version, where <checkout> is an SVN checkout directory of the
# Python branch to build docs for, and <target> is the directory where the
# result should be placed.  If -d is given, the docs are built even if the
# branch is in development mode (i.e. version contains a, b or c).
#
# This script is not run from the checkout, so if you want to change how the
# daily build is run, you must replace it on dinsdale.  This is necessary, for
# example, after the release of a new minor version.
#
# 03/2010, Georg Brandl

import os
import sys
import getopt


BUILDROOT = '/home/gbrandl/docbuild'
WWWROOT = '/data/ftp.python.org/pub/docs.python.org'

BRANCHES = [
    # checkout, target, isdev
    (BUILDROOT + '/python33', WWWROOT + '/py3k', False),
    (BUILDROOT + '/python34', WWWROOT + '/dev', True),
    (BUILDROOT + '/python27', WWWROOT, False),
]


def build_one(checkout, target, isdev):
    print 'Doc autobuild started in %s' % checkout
    os.chdir(checkout)
    print 'Running hg pull --update'
    os.system('/usr/local/bin/hg pull --update')
    print 'Running make autobuild'
    if os.WEXITSTATUS(os.system(
        'cd Doc; make autobuild-%s' % (isdev and 'dev' or 'stable'))) == 2:
        print '*' * 80
        return
    print 'Copying HTML files'
    os.system('cp -a Doc/build/html/* %s' % target)
    print 'Copying dist files'
    os.system('mkdir -p %s/archives' % target)
    os.system('cp -a Doc/dist/* %s/archives' % target)
    print 'Finished'
    print '=' * 80

def usage():
    print 'Usage:'
    print '  %s' % sys.argv[0]
    print 'or'
    print '  %s [-d] <checkout> <target>' % sys.argv[0]
    sys.exit(1)


if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'd')
    except getopt.error:
        usage()
    if opts and not args:
        usage()
    if args:
        if len(args) != 2:
            usage()
        build_one(args[0], args[1], bool(opts))
    else:
        for branch in BRANCHES:
            build_one(*branch)

@@ -137,16 +137,21 @@
 build.py
+ %5B-q%5D
 %0A#%0A# wit
@@ -240,16 +240,74 @@
 S value.
+ -q selects %22quick build%22, which means to build only HTML.
 %0A#%0A#   d
@@ -318,16 +318,21 @@
 build.py
+ %5B-q%5D
  %5B-d%5D %3Cc
@@ -1252,16 +1252,23 @@
 t, isdev
+, quick
 ):%0A    p
@@ -1457,16 +1457,135 @@
 obuild'%0A
+    maketarget = 'autobuild-' + ('html' if quick else%0A                                 ('dev' if isdev else 'stable'))%0A
     if o
@@ -1608,25 +1608,16 @@
 .system(
-%0A        
 'cd Doc;
@@ -1626,53 +1626,24 @@
 ake 
-autobuild-%25s' %25 (isdev and 'dev' or 'stable')
+%25s' %25 maketarget
 )) =
@@ -1710,25 +1710,40 @@
 g HTML files
-'
+ to %25s' %25 target
 %0A    os.syst
@@ -1775,32 +1775,54 @@
 * %25s' %25 target)%0A
+    if not quick:%0A    
     print 'Copyi
@@ -1836,16 +1836,20 @@
  files'%0A
+    
     os.s
@@ -1883,24 +1883,28 @@
 ' %25 target)%0A
+    
     os.syste
@@ -2226,16 +2226,17 @@
 %5B1:%5D, 'd
+q
 ')%0A    e
@@ -2279,15 +2279,164 @@
     
-if opts
+quick = devel = False%0A    for opt, _ in opts:%0A        if opt == '-q':%0A            quick = True%0A        if opt == '-d':%0A            devel = True%0A    if devel
  and
@@ -2562,18 +2562,20 @@
 1%5D, 
-bool(opts)
+devel, quick
 )%0A  
@@ -2594,22 +2594,37 @@
     for 
-branch
+checkout, dest, devel
  in BRAN
@@ -2655,13 +2655,34 @@
 one(
-*branch
+checkout, dest, devel, quick
 )%0A

Update current version of the "dailybuild" script.