diff options
author | spreis <spreis@yandex-team.com> | 2023-10-13 06:41:33 +0300 |
---|---|---|
committer | spreis <spreis@yandex-team.com> | 2023-10-13 07:08:24 +0300 |
commit | 94d77db087cf83003ca0c6f276dbb827099688ad (patch) | |
tree | 1adeb0e4918307588f1fad4898b7d3e2deca69dc /build/scripts/gen_py_protos.py | |
parent | 7bf454679ed7688910a47b369875c0ebdd77f53c (diff) | |
download | ydb-94d77db087cf83003ca0c6f276dbb827099688ad.tar.gz |
support dash in Python version of PROTO_LIBRARY
Diffstat (limited to 'build/scripts/gen_py_protos.py')
-rw-r--r-- | build/scripts/gen_py_protos.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/build/scripts/gen_py_protos.py b/build/scripts/gen_py_protos.py index 08397472f9..606f50dfb6 100644 --- a/build/scripts/gen_py_protos.py +++ b/build/scripts/gen_py_protos.py @@ -10,9 +10,16 @@ import re OUT_DIR_ARG = '--python_out=' + +def _noext(fname): + return fname[:fname.rfind('.')] + + def main(): parser = argparse.ArgumentParser() parser.add_argument("--suffixes", nargs="*", default=[]) + parser.add_argument("--input") + parser.add_argument("--ns") parser.add_argument("protoc_args", nargs=argparse.REMAINDER) script_args = parser.parse_args() @@ -46,20 +53,27 @@ def main(): 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 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)) + temp_name = out_dir_temp + orig_name = out_dir_orig + dir_name, file_name = path.split(script_args.input[len(script_args.ns) - 1:]) + for part in dir_name.split('/'): + temp_part = part.replace('-','_') + temp_name = path.join(temp_name, temp_part) + assert(path.exists(temp_name)) + + orig_name = path.join(orig_name, part) + if not path.exists(orig_name): + os.mkdir(orig_name) + + orig_base_name = _noext(file_name) + temp_base_name = orig_base_name.replace('-','_') + for suf in script_args.suffixes: + temp_file_name = path.join(temp_name, temp_base_name + suf) + assert(path.exists(temp_file_name)) + + orig_file_name = path.join(orig_name, orig_base_name + '__int__' + suf) + os.rename(temp_file_name, orig_file_name) + shutil.rmtree(out_dir_temp) |