/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/package_docs.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-08 16:37:05 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090908163705-50olbndnrr2x2389
moce most of the sphinx configuration settings into a central place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
# Copyright 2009 Canonical Ltd.
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 
 
19
import os
 
20
import sys
 
21
from optparse import OptionParser
 
22
from shutil import copy2, copytree, rmtree
 
23
 
 
24
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
 
25
 
 
26
 
 
27
def package_docs(section, src_build, dest_html, dest_downloads):
 
28
    """Package docs from a Sphinx _build directory into target directories.
 
29
 
 
30
    :param section: section in the website being built
 
31
    :param src_build: the _build directory
 
32
    :param dest_html: the directory where html should go
 
33
    :param downloads: the directory where downloads should go
 
34
    """
 
35
    # Copy across the HTML. Explicitly delete the html destination
 
36
    # directory first though because copytree insists on it not existing.
 
37
    src_html = os.path.join(src_build, 'html')
 
38
    if os.path.exists(dest_html):
 
39
        rmtree(dest_html)
 
40
    copytree(src_html, dest_html)
 
41
 
 
42
    # TODO: package the html as a downloadable archive
 
43
 
 
44
    # TODO: copy across the PDF docs, if any, including the quick ref card
 
45
    pdf_files = []
 
46
    quick_ref = os.path.join(src_html,
 
47
        '_static/%s/bzr-quick-reference.pdf' % (section,))
 
48
    if os.path.exists(quick_ref):
 
49
        pdf_files.append(quick_ref)
 
50
    src_pdf = os.path.join(src_build, 'latex')
 
51
    if os.path.exists(src_pdf):
 
52
        for name in os.listdir(src_pdf):
 
53
            if name.endswith('.pdf'):
 
54
                pdf_files.append(os.path.join(src_pdf, name))
 
55
    if pdf_files:
 
56
        dest_pdf = os.path.join(dest_downloads, 'pdf-%s' % (section,))
 
57
        if not os.path.exists(dest_pdf):
 
58
            os.mkdir(dest_pdf)
 
59
        for pdf in pdf_files:
 
60
            copy2(pdf, dest_pdf)
 
61
 
 
62
    # TODO: copy across the CHM files, if any
 
63
 
 
64
 
 
65
def main(argv):
 
66
    # Check usage. The first argument is the parent directory of
 
67
    # the Sphinx _build directory. It will typically be 'doc/xx'.
 
68
    # The second argument is the website build directory.
 
69
    parser = OptionParser(usage="%prog SOURCE-DIR WEBSITE-BUILD-DIR")
 
70
    (options, args) = parser.parse_args(argv)
 
71
    if len(args) != 2:
 
72
        parser.print_help()
 
73
        sys.exit(1)
 
74
 
 
75
    # Get the section - locale code or 'developers'
 
76
    src_dir = args[0]
 
77
    section = os.path.basename(src_dir)
 
78
    src_build = os.path.join(src_dir, '_build')
 
79
 
 
80
    # Create the destination directories if they doesn't exist.
 
81
    dest_dir = args[1]
 
82
    dest_html = os.path.join(dest_dir, section)
 
83
    dest_downloads = os.path.join(dest_dir, 'downloads')
 
84
    for d in [dest_dir, dest_downloads]:
 
85
        if not os.path.exists(d):
 
86
            print "creating directory %s ..." % (d,)
 
87
            os.mkdir(d)
 
88
 
 
89
    # Package and copy the files across
 
90
    package_docs(section, src_build, dest_html, dest_downloads)
 
91
 
 
92
 
 
93
if __name__ == '__main__':
 
94
    main(sys.argv[1:])