1#!/usr/bin/env python 2# Copyright 2018 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6 7import os 8import sys 9import argparse 10 11TELEMETRY_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') 12sys.path.insert(1, TELEMETRY_DIR) 13 14from telemetry.internal.util import binary_manager 15 16from dependency_manager import base_config 17 18 19def AddBinaryDepdendency(binary_local_path, dependency_name, platform, 20 download_path): 21 config = base_config.BaseConfig( 22 binary_manager.TELEMETRY_PROJECT_CONFIG, writable=True) 23 24 if not dependency_name in config: 25 print ('%s is a new dependency. ' 26 'Do you want to add it to Telemetry binary dependencies?') 27 answer = raw_input("Enter 'y' to answer yes: ") 28 if answer == 'y': 29 config.AddNewDependency( 30 dependency_name, 31 binary_manager.TELEMETRY_BINARY_BASE_CS_FOLDER, 32 binary_manager.TELEMETRY_BINARY_CS_BUCKET) 33 else: 34 print 'Did not update binary for %s' % dependency_name 35 return 36 37 if not download_path: 38 download_path = '%s/%s' % ( 39 binary_manager.PLATFORMS_TO_DOWNLOAD_FOLDER_MAP[platform], 40 os.path.basename(binary_local_path)) 41 if platform.startswith('win'): 42 download_path += '.exe' 43 print "Download path wasn't specified. Using default download path: %s" % ( 44 download_path) 45 print 'Do you want to continue the binary update job?' 46 answer = raw_input("Enter 'y' to answer yes: ") 47 if answer != 'y': 48 print 'Did not update binary for %s' % dependency_name 49 return 50 config.SetDownloadPath(dependency_name, platform, 51 download_path=download_path) 52 53 config.AddCloudStorageDependencyUpdateJob( 54 dependency_name, platform, binary_local_path, execute_job=False) 55 56 config.ExecuteUpdateJobs() 57 58 59def main(args): 60 parser = argparse.ArgumentParser( 61 description='Add binary to Telemetry dependencies to store on cloud' 62 ' storage.') 63 parser.add_argument('binary_path', type=str, 64 help='Path to binary to be added to dependencies') 65 parser.add_argument('dependency_name', type=str, help='Dependency name') 66 parser.add_argument('platform', 67 choices=binary_manager.SUPPORTED_DEP_PLATFORMS, 68 help='Platform which this binary dep belong to') 69 parser.add_argument('--download-path', 70 help=( 71 'Download path of the binary dependency (relative to ' 72 'telemetry/telemetry/internal/ directory)')) 73 74 options = parser.parse_args(args) 75 76 binary_local_path = os.path.abspath(options.binary_path) 77 if not os.path.exists(binary_local_path): 78 raise ValueError('Path %s does not exist' % binary_local_path) 79 80 AddBinaryDepdendency( 81 binary_local_path, options.dependency_name, options.platform, 82 options.download_path) 83 84 85if __name__ == "__main__": 86 main(sys.argv[1:]) 87