aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpg <pg@yandex-team.com>2024-10-18 21:59:31 +0300
committerpg <pg@yandex-team.com>2024-10-18 22:10:04 +0300
commit2a43a3e9b68e16667f292702458482a8e6539e50 (patch)
tree6af0805dca33779646fd848f428919df9f4aaac4
parent0b6a2c94a69320772fb4944d6a2c39657f10b7b6 (diff)
downloadydb-2a43a3e9b68e16667f292702458482a8e6539e50.tar.gz
add generic json command executor for external bs
commit_hash:0833419ebee283a1fb0e0a41f615b0bf7b61f548
-rw-r--r--build/scripts/generic_cmd.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/build/scripts/generic_cmd.py b/build/scripts/generic_cmd.py
new file mode 100644
index 0000000000..c850d244e8
--- /dev/null
+++ b/build/scripts/generic_cmd.py
@@ -0,0 +1,31 @@
+import os
+import sys
+import json
+import base64
+import subprocess
+
+
+if __name__ == '__main__':
+ p = sys.argv.index('--')
+ ctx = base64.b64decode(sys.argv[p + 1].encode()).decode()
+ kv = {}
+
+ for x in sys.argv[1:p]:
+ k, v = x.split('=')
+ ctx = ctx.replace(f'$({k})', v)
+ kv[k] = v
+
+ cmd = json.loads(ctx)
+
+ args = cmd['cmd_args']
+ cwd = cmd.get('cwd', kv['B'])
+
+ env = dict(**os.environ)
+ env['ARCADIA_ROOT_DISTBUILD'] = kv['S']
+ env.update(cmd['env'])
+
+ out = subprocess.check_output(args, env=env, cwd=cwd)
+
+ if stdout := cmd.get('stdout'):
+ with open(stdout, 'wb') as f:
+ f.write(out)