Create a (possibly compressed) tar file from all the files under 'base_dir'. 'compress' must be "gzip" (the default), "bzip2", "xz", "zst", or None. 'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owne
(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None, logger=None, root_dir=None)
| 990 | return None |
| 991 | |
| 992 | def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0, |
| 993 | owner=None, group=None, logger=None, root_dir=None): |
| 994 | """Create a (possibly compressed) tar file from all the files under |
| 995 | 'base_dir'. |
| 996 | |
| 997 | 'compress' must be "gzip" (the default), "bzip2", "xz", "zst", or None. |
| 998 | |
| 999 | 'owner' and 'group' can be used to define an owner and a group for the |
| 1000 | archive that is being built. If not provided, the current owner and group |
| 1001 | will be used. |
| 1002 | |
| 1003 | The output tar file will be named 'base_name' + ".tar", possibly plus |
| 1004 | the appropriate compression extension (".gz", ".bz2", ".xz", or ".zst"). |
| 1005 | |
| 1006 | Returns the output filename. |
| 1007 | """ |
| 1008 | if compress is None: |
| 1009 | tar_compression = '' |
| 1010 | elif _ZLIB_SUPPORTED and compress == 'gzip': |
| 1011 | tar_compression = 'gz' |
| 1012 | elif _BZ2_SUPPORTED and compress == 'bzip2': |
| 1013 | tar_compression = 'bz2' |
| 1014 | elif _LZMA_SUPPORTED and compress == 'xz': |
| 1015 | tar_compression = 'xz' |
| 1016 | elif _ZSTD_SUPPORTED and compress == 'zst': |
| 1017 | tar_compression = 'zst' |
| 1018 | else: |
| 1019 | raise ValueError("bad value for 'compress', or compression format not " |
| 1020 | "supported : {0}".format(compress)) |
| 1021 | |
| 1022 | import tarfile # late import for breaking circular dependency |
| 1023 | |
| 1024 | compress_ext = '.' + tar_compression if compress else '' |
| 1025 | archive_name = base_name + '.tar' + compress_ext |
| 1026 | archive_dir = os.path.dirname(archive_name) |
| 1027 | |
| 1028 | if archive_dir and not os.path.exists(archive_dir): |
| 1029 | if logger is not None: |
| 1030 | logger.info("creating %s", archive_dir) |
| 1031 | if not dry_run: |
| 1032 | os.makedirs(archive_dir) |
| 1033 | |
| 1034 | # creating the tarball |
| 1035 | if logger is not None: |
| 1036 | logger.info('Creating tar archive') |
| 1037 | |
| 1038 | uid = _get_uid(owner) |
| 1039 | gid = _get_gid(group) |
| 1040 | |
| 1041 | def _set_uid_gid(tarinfo): |
| 1042 | if gid is not None: |
| 1043 | tarinfo.gid = gid |
| 1044 | tarinfo.gname = group |
| 1045 | if uid is not None: |
| 1046 | tarinfo.uid = uid |
| 1047 | tarinfo.uname = owner |
| 1048 | return tarinfo |
| 1049 |
nothing calls this directly
no test coverage detected
searching dependent graphs…