Debian Codegraph @

infra/bots/assets/cockroachdb/create.py

raw
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Create the cockroachDB asset."""
10
11
12 import argparse
13 import os
14 import shutil
15 import subprocess
16 import sys
17
18 FILE_DIR = os.path.dirname(os.path.abspath(__file__))
19 INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
20 sys.path.insert(0, INFRA_BOTS_DIR)
21 import utils
22
23
24 URL = "https://binaries.cockroachdb.com/cockroach-v20.2.8.linux-amd64.tgz"
25
26 def create_asset(target_dir):
27 """Create the asset."""
28 with utils.tmp_dir():
29 p1 = subprocess.Popen(["curl", URL], stdout=subprocess.PIPE)
30 p2 = subprocess.Popen(["tar", "-xzf" "-"], stdin=p1.stdout)
31 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
32 _,_ = p2.communicate()
33 shutil.move('./cockroach-v20.2.8.linux-amd64/cockroach', target_dir)
34
35
36 def main():
37 parser = argparse.ArgumentParser()
38 parser.add_argument('--target_dir', '-t', required=True)
39 args = parser.parse_args()
40 create_asset(args.target_dir)
41
42
43 if __name__ == '__main__':
44 main()