diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-03-15 19:59:12 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-03-15 19:59:12 +0300 |
commit | 056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11 (patch) | |
tree | 4740980126f32e3af7937ba0ca5f83e59baa4ab0 /build/scripts/tar_directory.py | |
parent | 269126dcced1cc8b53eb4398b4a33e5142f10290 (diff) | |
download | ydb-056bb284ccf8dd6793ec3a54ffa36c4fb2b9ad11.tar.gz |
add library/cpp/actors, ymake build to ydb oss export
Diffstat (limited to 'build/scripts/tar_directory.py')
-rw-r--r-- | build/scripts/tar_directory.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/build/scripts/tar_directory.py b/build/scripts/tar_directory.py new file mode 100644 index 0000000000..a91889fa22 --- /dev/null +++ b/build/scripts/tar_directory.py @@ -0,0 +1,45 @@ +import os +import sys +import tarfile + + +def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + +def main(args): + if len(args) < 2 or len(args) > 3: + raise Exception("Illegal usage: `tar_directory.py archive.tar directory [skip prefix]` or `tar_directory.py archive.tar output_directory --extract`") + tar, directory, prefix, extract = args[0], args[1], None, False + if len(args) == 3: + if args[2] == '--extract': + extract = True + else: + prefix = args[2] + for tar_exe in ('/usr/bin/tar', '/bin/tar'): + if not is_exe(tar_exe): + continue + if extract: + dest = os.path.abspath(directory) + if not os.path.exists(dest): + os.makedirs(dest) + os.execv(tar_exe, [tar_exe, '-xf', tar, '-C', dest]) + else: + source = os.path.relpath(directory, prefix) if prefix else directory + os.execv(tar_exe, [tar_exe, '-cf', tar] + (['-C', prefix] if prefix else []) + [source]) + break + else: + if extract: + dest = os.path.abspath(directory) + if not os.path.exists(dest): + os.makedirs(dest) + with tarfile.open(tar, 'r') as tar_file: + tar_file.extractall(dest) + else: + source = directory + with tarfile.open(tar, 'w') as out: + out.add(os.path.abspath(source), arcname=os.path.relpath(source, prefix) if prefix else source) + + +if __name__ == '__main__': + main(sys.argv[1:]) |