1# This Source Code Form is subject to the terms of the Mozilla Public
2# License, v. 2.0. If a copy of the MPL was not distributed with this
3# file, # You can obtain one at http://mozilla.org/MPL/2.0/.
4
5from __future__ import absolute_import, unicode_literals
6
7import os
8
9from mozpack.archive import create_tar_gz_from_files
10from mozpack.files import FileFinder
11
12
13def distribution_files(root):
14    """Find all files suitable for distributing.
15
16    Given the path to generated Sphinx documentation, returns an iterable
17    of (path, BaseFile) for files that should be archived, uploaded, etc.
18    Paths are relative to given root directory.
19    """
20    finder = FileFinder(root, ignore=('_staging', '_venv'))
21    return finder.find('**')
22
23
24def create_tarball(filename, root):
25    """Create a tar.gz archive of docs in a directory."""
26    files = dict(distribution_files(root))
27
28    with open(filename, 'wb') as fh:
29        create_tar_gz_from_files(fh, files, filename=os.path.basename(filename),
30                                 compresslevel=6)
31