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 11import common # fixes python import path 12import argparse 13import shutil 14import subprocess 15import utils 16 17 18URL = "https://binaries.cockroachdb.com/cockroach-v20.2.8.linux-amd64.tgz" 19 20def create_asset(target_dir): 21 """Create the asset.""" 22 with utils.tmp_dir(): 23 p1 = subprocess.Popen(["curl", URL], stdout=subprocess.PIPE) 24 p2 = subprocess.Popen(["tar", "-xzf" "-"], stdin=p1.stdout) 25 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. 26 _,_ = p2.communicate() 27 shutil.move('./cockroach-v20.2.8.linux-amd64/cockroach', target_dir) 28 29 30def main(): 31 parser = argparse.ArgumentParser() 32 parser.add_argument('--target_dir', '-t', required=True) 33 args = parser.parse_args() 34 create_asset(args.target_dir) 35 36 37if __name__ == '__main__': 38 main() 39