|
6 | 6 | import os.path |
7 | 7 | import sys |
8 | 8 | import shutil |
9 | | -import gzip |
10 | | -import tarfile |
11 | | - |
12 | | -TARGZ_DEFAULT_COMPRESSION_LEVEL = 9 |
13 | | - |
14 | | -def make_tarball(tarball_path, sources, base_dir, prefix_dir=''): |
15 | | - """Parameters: |
16 | | - tarball_path: output path of the .tar.gz file |
17 | | - sources: list of sources to include in the tarball, relative to the current directory |
18 | | - base_dir: if a source file is in a sub-directory of base_dir, then base_dir is stripped |
19 | | - from path in the tarball. |
20 | | - prefix_dir: all files stored in the tarball be sub-directory of prefix_dir. Set to '' |
21 | | - to make them child of root. |
22 | | - """ |
23 | | - base_dir = os.path.normpath( os.path.abspath( base_dir ) ) |
24 | | - def archive_name( path ): |
25 | | - """Makes path relative to base_dir.""" |
26 | | - path = os.path.normpath( os.path.abspath( path ) ) |
27 | | - common_path = os.path.commonprefix( (base_dir, path) ) |
28 | | - archive_name = path[len(common_path):] |
29 | | - if os.path.isabs( archive_name ): |
30 | | - archive_name = archive_name[1:] |
31 | | - return os.path.join( prefix_dir, archive_name ) |
32 | | - def visit(tar, dirname, names): |
33 | | - for name in names: |
34 | | - path = os.path.join(dirname, name) |
35 | | - if os.path.isfile(path): |
36 | | - path_in_tar = archive_name(path) |
37 | | - tar.add(path, path_in_tar ) |
38 | | - compression = TARGZ_DEFAULT_COMPRESSION_LEVEL |
39 | | - fileobj = gzip.GzipFile( tarball_path, 'wb', compression ) |
40 | | - tar = tarfile.TarFile(os.path.splitext(tarball_path)[0], 'w', fileobj) |
41 | | - for source in sources: |
42 | | - source_path = source |
43 | | - if os.path.isdir( source ): |
44 | | - os.path.walk(source_path, visit, tar) |
45 | | - else: |
46 | | - path_in_tar = archive_name(source_path) |
47 | | - tar.add(source_path, path_in_tar ) # filename, arcname |
48 | | - tar.close() |
49 | | - |
| 9 | +from devtools import tarball |
50 | 10 |
|
51 | 11 | def find_program(filename): |
52 | 12 | """find a program in folders path_lst, and sets env[var] |
@@ -171,7 +131,7 @@ def yesno( bool ): |
171 | 131 | 'version' |
172 | 132 | ] |
173 | 133 | tarball_basedir = os.path.join( full_output_dir, html_output_dirname ) |
174 | | - make_tarball( tarball_path, tarball_sources, tarball_basedir, html_output_dirname ) |
| 134 | + tarball.make_tarball( tarball_path, tarball_sources, tarball_basedir, html_output_dirname ) |
175 | 135 |
|
176 | 136 | def main(): |
177 | 137 | usage = """%prog |
|
0 commit comments