diff options
author | akastornov <akastornov@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
commit | 3a2de774d91ca8d7325aaf81c200b1d2047725e6 (patch) | |
tree | 5674a780ce03a8bbd794733a19c7a70d587e4a14 /build/scripts/copy_to_dir.py | |
parent | 7bd11ff35e97544d119e43447e3e865f2588ee7f (diff) | |
download | ydb-3a2de774d91ca8d7325aaf81c200b1d2047725e6.tar.gz |
Restoring authorship annotation for <akastornov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'build/scripts/copy_to_dir.py')
-rw-r--r-- | build/scripts/copy_to_dir.py | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/build/scripts/copy_to_dir.py b/build/scripts/copy_to_dir.py index 9baeb5ffac..8044b0b0bf 100644 --- a/build/scripts/copy_to_dir.py +++ b/build/scripts/copy_to_dir.py @@ -2,19 +2,19 @@ import errno import sys import os import shutil -import optparse -import tarfile +import optparse +import tarfile -def parse_args(): - parser = optparse.OptionParser() - parser.add_option('--build-root') - parser.add_option('--dest-dir') - parser.add_option('--dest-arch') - return parser.parse_args() - - -def ensure_dir_exists(path): +def parse_args(): + parser = optparse.OptionParser() + parser.add_option('--build-root') + parser.add_option('--dest-dir') + parser.add_option('--dest-arch') + return parser.parse_args() + + +def ensure_dir_exists(path): try: os.makedirs(path) except OSError as e: @@ -24,52 +24,52 @@ def ensure_dir_exists(path): raise -def hardlink_or_copy(src, dst): - if os.name == 'nt': - shutil.copy(src, dst) - else: - try: - os.link(src, dst) - except OSError as e: - if e.errno == errno.EEXIST: - return - elif e.errno == errno.EXDEV: +def hardlink_or_copy(src, dst): + if os.name == 'nt': + shutil.copy(src, dst) + else: + try: + os.link(src, dst) + except OSError as e: + if e.errno == errno.EEXIST: + return + elif e.errno == errno.EXDEV: sys.stderr.write("Can't make cross-device hardlink - fallback to copy: {} -> {}\n".format(src, dst)) - shutil.copy(src, dst) - else: - raise - - + shutil.copy(src, dst) + else: + raise + + def main(): - opts, args = parse_args() - assert opts.build_root - assert opts.dest_dir - - dest_arch = None - if opts.dest_arch: - if opts.dest_arch.endswith('.tar'): + opts, args = parse_args() + assert opts.build_root + assert opts.dest_dir + + dest_arch = None + if opts.dest_arch: + if opts.dest_arch.endswith('.tar'): dest_arch = tarfile.open(opts.dest_arch, 'w', dereference=True) - elif opts.dest_arch.endswith('.tar.gz') or opts.dest_arch.endswith('.tgz'): + elif opts.dest_arch.endswith('.tar.gz') or opts.dest_arch.endswith('.tgz'): dest_arch = tarfile.open(opts.dest_arch, 'w:gz', dereference=True) - else: - # TODO: move check to graph generation stage - raise Exception('Unsopported archive type for {}. Use one of: tar, tar.gz, tgz.'.format(os.path.basename(opts.dest_arch))) - - for arg in args: + else: + # TODO: move check to graph generation stage + raise Exception('Unsopported archive type for {}. Use one of: tar, tar.gz, tgz.'.format(os.path.basename(opts.dest_arch))) + + for arg in args: dst = arg - if dst.startswith(opts.build_root): - dst = dst[len(opts.build_root) + 1:] + if dst.startswith(opts.build_root): + dst = dst[len(opts.build_root) + 1:] if dest_arch and not arg.endswith('.pkg.fake'): - dest_arch.add(arg, arcname=dst) - - dst = os.path.join(opts.dest_dir, dst) - ensure_dir_exists(os.path.dirname(dst)) - hardlink_or_copy(arg, dst) - - if dest_arch: - dest_arch.close() - + dest_arch.add(arg, arcname=dst) + dst = os.path.join(opts.dest_dir, dst) + ensure_dir_exists(os.path.dirname(dst)) + hardlink_or_copy(arg, dst) + + if dest_arch: + dest_arch.close() + + if __name__ == '__main__': sys.exit(main()) |