Home | History | Annotate | Download | only in bin
      1 #!/usr/bin/env python
      2 # Copyright 2016 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 import argparse
      7 import os
      8 import sys
      9 
     10 sys.path.append(
     11     os.path.abspath(os.path.join(os.path.dirname(__file__),
     12                                  '..', '..', '..', 'dependency_manager')))
     13 from dependency_manager import base_config # pylint: disable=import-error
     14 
     15 
     16 _SUPPORTED_ARCHS = [
     17     'linux2_x86_64', 'darwin_x86_64', 'win_AMD64', 'win32_AMD64', 'win32_x86',
     18     'default'
     19 ]
     20 _DEFAULT_DEP = 'battor_agent_binary'
     21 _DEFAULT_CONFIG = os.path.join(os.path.dirname(__file__), '..', 'battor',
     22                                'battor_binary_dependencies.json')
     23 
     24 
     25 def UploadBinary(arch, path, config, dep):
     26   print 'Uploading binary:'
     27   print '  arch: %s' % arch
     28   print '  path: %s' % path
     29   print '  config: %s' % config
     30   print '  dep: %s' % dep
     31   c = base_config.BaseConfig(config, writable=True)
     32   c.AddCloudStorageDependencyUpdateJob(
     33       dep, arch, path, version=None, execute_job=True)
     34   print 'Upload complete.'
     35 
     36 
     37 def main():
     38   parser = argparse.ArgumentParser()
     39   parser.add_argument('--arch', '--architecture', required=True,
     40                       help='Architecture binary is built for.')
     41   parser.add_argument('--path', required=True, help='Path to binary.')
     42   parser.add_argument('--config', default=_DEFAULT_CONFIG,
     43                       help='Path to dependency manager config')
     44   parser.add_argument('--dep', default=_DEFAULT_DEP,
     45                       help='Name of dependency to update.')
     46   args = parser.parse_args()
     47   if args.arch not in _SUPPORTED_ARCHS:
     48     print 'Arch must be one of: %s' % _SUPPORTED_ARCHS
     49     return 1
     50   UploadBinary(args.arch, args.path, args.config, args.dep)
     51   return 0
     52 
     53 if __name__ == '__main__':
     54   sys.exit(main())
     55