Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Side by Side Diff: tools/pyutils/gs_utils.py

Issue 381933002: import google-api-python-client using DEPS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« DEPS ('K') | « DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2014 Google Inc. 4 Copyright 2014 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Utilities for accessing Google Cloud Storage. 9 Utilities for accessing Google Cloud Storage.
10
11 TODO(epoger): move this into tools/utils for broader use?
12 """ 10 """
13 11
14 # System-level imports 12 # System-level imports
15 import os 13 import os
16 import posixpath 14 import posixpath
17 import sys 15 import sys
16
17 # Imports from third-party code
18 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
19 for import_subdir in ['google-api-python-client', 'oauth2client']:
20 import_dirpath = os.path.join(
21 TRUNK_DIRECTORY, 'third_party', 'externals', import_subdir)
22 if import_dirpath not in sys.path:
23 # We need to insert at the beginning of the path, to make sure that our
24 # imported versions are favored over others that might be in the path.
25 # Also, the google-api-python-client checkout contains an empty
26 # oauth2client directory, which will confuse things unless we insert
27 # our checked-out oauth2client in front of it in the path.
28 sys.path.insert(0, import_dirpath)
18 try: 29 try:
19 from apiclient.discovery import build as build_service 30 from googleapiclient.discovery import build as build_service
20 except ImportError: 31 except ImportError:
21 print ('Missing google-api-python-client. Please install it; directions ' 32 # TODO(epoger): We are moving toward not needing any dependencies to be
33 # installed at a system level, but in the meanwhile, if developers run into
34 # trouble they can install those system-level dependencies to get unblocked.
35 print ('Missing dependencies of google-api-python-client. Please install '
36 'google-api-python-client to get those dependencies; directions '
22 'can be found at https://developers.google.com/api-client-library/' 37 'can be found at https://developers.google.com/api-client-library/'
23 'python/start/installation') 38 'python/start/installation . More details in http://skbug.com/2641 ')
24 raise 39 raise
25 40
26 # Local imports 41 # Local imports
27 import url_utils 42 import url_utils
28 43
29 44
30 def download_file(source_bucket, source_path, dest_path, 45 def download_file(source_bucket, source_path, dest_path,
31 create_subdirs_if_needed=False): 46 create_subdirs_if_needed=False):
32 """ Downloads a single file from Google Cloud Storage to local disk. 47 """ Downloads a single file from Google Cloud Storage to local disk.
33 48
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 dirs = [] 87 dirs = []
73 for dir_fullpath in results.get('prefixes', []): 88 for dir_fullpath in results.get('prefixes', []):
74 dir_basename = dir_fullpath[subdir_length:] 89 dir_basename = dir_fullpath[subdir_length:]
75 dirs.append(dir_basename[:-1]) # strip trailing slash 90 dirs.append(dir_basename[:-1]) # strip trailing slash
76 files = [] 91 files = []
77 for file_properties in results.get('items', []): 92 for file_properties in results.get('items', []):
78 file_fullpath = file_properties['name'] 93 file_fullpath = file_properties['name']
79 file_basename = file_fullpath[subdir_length:] 94 file_basename = file_fullpath[subdir_length:]
80 files.append(file_basename) 95 files.append(file_basename)
81 return (dirs, files) 96 return (dirs, files)
OLDNEW
« DEPS ('K') | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698