3
# Copyright 2009 Canonical Ltd.
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.
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.
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
21
from optparse import OptionParser
22
from shutil import copy2, copytree, rmtree
24
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
27
def package_docs(section, src_build, dest_html, dest_downloads):
28
"""Package docs from a Sphinx _build directory into target directories.
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
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):
40
copytree(src_html, dest_html)
42
# TODO: package the html as a downloadable archive
44
# TODO: copy across the PDF docs, if any, including the quick ref card
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))
56
dest_pdf = os.path.join(dest_downloads, 'pdf-%s' % (section,))
57
if not os.path.exists(dest_pdf):
62
# TODO: copy across the CHM files, if any
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)
75
# Get the section - locale code or 'developers'
77
section = os.path.basename(src_dir)
78
src_build = os.path.join(src_dir, '_build')
80
# Create the destination directories if they doesn't exist.
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,)
89
# Package and copy the files across
90
package_docs(section, src_build, dest_html, dest_downloads)
93
if __name__ == '__main__':