Create tarball containing all files in root. Parameters ---------- output : str The target shared library. files : list List of files to be bundled.
(output, files)
| 26 | |
| 27 | |
| 28 | def tar(output, files): |
| 29 | """Create tarball containing all files in root. |
| 30 | |
| 31 | Parameters |
| 32 | ---------- |
| 33 | output : str |
| 34 | The target shared library. |
| 35 | |
| 36 | files : list |
| 37 | List of files to be bundled. |
| 38 | """ |
| 39 | cmd = ["tar"] |
| 40 | cmd += ["-czf"] |
| 41 | temp = utils.tempdir() |
| 42 | fset = set() |
| 43 | for fname in files: |
| 44 | base = os.path.basename(fname) |
| 45 | if base in fset: |
| 46 | raise ValueError(f"duplicate file name {base}") |
| 47 | fset.add(base) |
| 48 | shutil.copy(fname, temp.relpath(base)) |
| 49 | cmd += [output] |
| 50 | cmd += ["-C", temp.temp_dir] |
| 51 | cmd += temp.listdir() |
| 52 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 53 | (out, _) = proc.communicate() |
| 54 | |
| 55 | if proc.returncode != 0: |
| 56 | msg = "Tar error:\n" |
| 57 | msg += out.decode("utf-8", errors="replace") |
| 58 | raise RuntimeError(msg) |
| 59 | |
| 60 | |
| 61 | # assign output format |