File: update_third_party_deps.py

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (131 lines) | stat: -rwxr-xr-x 4,296 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Uploads or downloads third party libraries to or from google cloud storage.
"""

import argparse
import logging
import os
import sys


sys.path.append(os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir)))
from pylib import constants
from pylib.constants import host_paths

sys.path.append(os.path.abspath(
    os.path.join(host_paths.DIR_SOURCE_ROOT, 'build')))
import find_depot_tools  # pylint: disable=import-error,unused-import
import download_from_google_storage
import upload_to_google_storage


def _AddBasicArguments(parser):
  parser.add_argument(
      '--sdk-root', default=constants.ANDROID_SDK_ROOT,
      help='base path to the Android SDK root')
  parser.add_argument(
      '-v', '--verbose', action='store_true', help='print debug information')
  parser.add_argument(
      '-b', '--bucket-path', required=True,
      help='The path of the lib file in Google Cloud Storage.')
  parser.add_argument(
      '-l', '--local-path', required=True,
      help='The base path of the third_party directory')


def _CheckPaths(bucket_path, local_path):
  if bucket_path.startswith('gs://'):
    bucket_url = bucket_path
  else:
    bucket_url = 'gs://%s' % bucket_path
  local_path = os.path.join(host_paths.DIR_SOURCE_ROOT, local_path)
  if not os.path.isdir(local_path):
    raise IOError(
        'The library local path is not a valid directory: %s' % local_path)
  return bucket_url, local_path


def _CheckFileList(local_path, file_list):
  local_path = os.path.abspath(local_path)
  abs_path_list = [os.path.abspath(f) for f in file_list]
  for f in abs_path_list:
    if os.path.commonprefix([f, local_path]) != local_path:
      raise IOError(
          '%s in the arguments are not decendants of the specified directory %s'
          % (f, local_path))
  return abs_path_list


def Upload(arguments):
  """Upload files in a third_party directory to google storage"""
  bucket_url, local_path = _CheckPaths(arguments.bucket_path,
                                       arguments.local_path)
  file_list = _CheckFileList(local_path, arguments.file_list)
  upload_to_google_storage.upload_to_google_storage(
      input_filenames=file_list,
      base_url=bucket_url,
      gsutil=arguments.gsutil,
      force=False,
      use_md5=False,
      num_threads=1,
      skip_hashing=False,
      gzip=None)


def Download(arguments):
  """Download files based on sha1 files in a third_party dir from gcs"""
  bucket_url, local_path = _CheckPaths(arguments.bucket_path,
                                       arguments.local_path)
  download_from_google_storage.download_from_google_storage(
      local_path,
      bucket_url,
      gsutil=arguments.gsutil,
      num_threads=1,
      directory=True,
      recursive=True,
      force=False,
      output=None,
      ignore_errors=False,
      sha1_file=None,
      verbose=arguments.verbose,
      auto_platform=False,
      extract=False)


def main(argv):
  parser = argparse.ArgumentParser()
  subparsers = parser.add_subparsers(title='commands')
  download_parser = subparsers.add_parser(
      'download', help='download the library from the cloud storage')
  _AddBasicArguments(download_parser)
  download_parser.set_defaults(func=Download)

  upload_parser = subparsers.add_parser(
      'upload', help='find all jar files in a third_party directory and ' +
                     'upload them to cloud storage')
  _AddBasicArguments(upload_parser)
  upload_parser.set_defaults(func=Upload)
  upload_parser.add_argument(
      '-f', '--file-list', nargs='+', required=True,
      help='A list of base paths for files in third_party to upload.')

  arguments = parser.parse_args(argv)
  if not os.path.isdir(arguments.sdk_root):
    logging.debug('Did not find the Android SDK root directory at "%s".',
                  arguments.sdk_root)
    logging.info('Skipping, not on an android checkout.')
    return 0

  arguments.gsutil = download_from_google_storage.Gsutil(
      download_from_google_storage.GSUTIL_DEFAULT_PATH)
  return arguments.func(arguments)


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))