diff options
author | mkolom <mkolom@yandex-team.ru> | 2022-02-10 16:46:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:07 +0300 |
commit | 5cc85744b35577ef3ca2214128c9e0c41927119e (patch) | |
tree | fba9b982a07e2e19a253f5d9a8ef1226a726919a /build/scripts/gen_py_protos.py | |
parent | dbd3185956979f21ea16ef90c1ba4aa2d6a75fae (diff) | |
download | ydb-5cc85744b35577ef3ca2214128c9e0c41927119e.tar.gz |
Restoring authorship annotation for <mkolom@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'build/scripts/gen_py_protos.py')
-rw-r--r-- | build/scripts/gen_py_protos.py | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/build/scripts/gen_py_protos.py b/build/scripts/gen_py_protos.py index 08397472f9..1bfbc52cdd 100644 --- a/build/scripts/gen_py_protos.py +++ b/build/scripts/gen_py_protos.py @@ -1,15 +1,15 @@ -import os -from os import path -import shutil -import subprocess -import sys -import tempfile +import os +from os import path +import shutil +import subprocess +import sys +import tempfile import argparse import re - - -OUT_DIR_ARG = '--python_out=' - + + +OUT_DIR_ARG = '--python_out=' + def main(): parser = argparse.ArgumentParser() parser.add_argument("--suffixes", nargs="*", default=[]) @@ -21,15 +21,15 @@ def main(): if args[0] == "--": args = args[1:] - out_dir_orig = None - out_dir_temp = None + out_dir_orig = None + out_dir_temp = None plugin_out_dirs_orig = {} - for i in range(len(args)): - if args[i].startswith(OUT_DIR_ARG): - assert not out_dir_orig, 'Duplicate "{0}" param'.format(OUT_DIR_ARG) - out_dir_orig = args[i][len(OUT_DIR_ARG):] - out_dir_temp = tempfile.mkdtemp(dir=out_dir_orig) - args[i] = OUT_DIR_ARG + out_dir_temp + for i in range(len(args)): + if args[i].startswith(OUT_DIR_ARG): + assert not out_dir_orig, 'Duplicate "{0}" param'.format(OUT_DIR_ARG) + out_dir_orig = args[i][len(OUT_DIR_ARG):] + out_dir_temp = tempfile.mkdtemp(dir=out_dir_orig) + args[i] = OUT_DIR_ARG + out_dir_temp continue match = re.match(r"^(--(\w+)_out=).*", args[i]) @@ -41,27 +41,27 @@ def main(): assert plugin_out_dirs_orig[plugin] == out_dir_orig, 'Params "{0}" and "{1}" expected to have the same value'.format(OUT_DIR_ARG, plugin_out_dir_arg) args[i] = plugin_out_dir_arg + out_dir_temp - assert out_dir_temp, 'Param "{0}" not found'.format(OUT_DIR_ARG) - - retcode = subprocess.call(args) + assert out_dir_temp, 'Param "{0}" not found'.format(OUT_DIR_ARG) + + retcode = subprocess.call(args) assert not retcode, 'Protoc failed for command {}'.format(' '.join(args)) - - for root_temp, dirs, files in os.walk(out_dir_temp): - sub_dir = path.relpath(root_temp, out_dir_temp) - root_orig = path.join(out_dir_orig, sub_dir) - for d in dirs: - d_orig = path.join(root_orig, d) - if not path.exists(d_orig): - os.mkdir(d_orig) - for f in files: - f_orig = f + + for root_temp, dirs, files in os.walk(out_dir_temp): + sub_dir = path.relpath(root_temp, out_dir_temp) + root_orig = path.join(out_dir_orig, sub_dir) + for d in dirs: + d_orig = path.join(root_orig, d) + if not path.exists(d_orig): + os.mkdir(d_orig) + for f in files: + f_orig = f for suf in script_args.suffixes: if f.endswith(suf): f_orig = f[:-len(suf)] + "__int__" + suf - break - os.rename(path.join(root_temp, f), path.join(root_orig, f_orig)) - shutil.rmtree(out_dir_temp) - - -if __name__ == '__main__': + break + os.rename(path.join(root_temp, f), path.join(root_orig, f_orig)) + shutil.rmtree(out_dir_temp) + + +if __name__ == '__main__': main() |