diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/writer.py | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/writer.py')
-rw-r--r-- | build/scripts/writer.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/build/scripts/writer.py b/build/scripts/writer.py new file mode 100644 index 00000000000..21bb3006e58 --- /dev/null +++ b/build/scripts/writer.py @@ -0,0 +1,40 @@ +import sys +import argparse + +import process_command_files as pcf + + +def parse_args(): + args = pcf.get_args(sys.argv[1:]) + parser = argparse.ArgumentParser() + parser.add_argument('-f', '--file', dest='file_path') + parser.add_argument('-a', '--append', action='store_true', default=False) + parser.add_argument('-Q', '--quote', action='store_true', default=False) + parser.add_argument('-s', '--addspace', action='store_true', default=False) + parser.add_argument('-c', '--content', action='append', dest='content') + parser.add_argument('-m', '--content-multiple', nargs='*', dest='content') + parser.add_argument('-P', '--path-list', action='store_true', default=False) + return parser.parse_args(args) + + +def smart_shell_quote(v): + if v is None: + return None + if ' ' in v or '"' in v or "'" in v: + return "\"{0}\"".format(v.replace('"', '\\"')) + return v + +if __name__ == '__main__': + args = parse_args() + open_type = 'a' if args.append else 'w' + + content = args.content + if args.quote: + content = [smart_shell_quote(ln) for ln in content] if content is not None else None + content = '\n'.join(content) + + with open(args.file_path, open_type) as f: + if args.addspace: + f.write(' ') + if content is not None: + f.write(content) |