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

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: added httplib2 and uritemplate to DEPS 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
« no previous file with comments | « 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', 'httplib2', 'oauth2client',
20 'uritemplate-py']:
21 import_dirpath = os.path.join(
22 TRUNK_DIRECTORY, 'third_party', 'externals', import_subdir)
23 if import_dirpath not in sys.path:
24 # We need to insert at the beginning of the path, to make sure that our
25 # imported versions are favored over others that might be in the path.
26 # Also, the google-api-python-client checkout contains an empty
27 # oauth2client directory, which will confuse things unless we insert
28 # our checked-out oauth2client in front of it in the path.
29 sys.path.insert(0, import_dirpath)
18 try: 30 try:
19 from apiclient.discovery import build as build_service 31 from googleapiclient.discovery import build as build_service
20 except ImportError: 32 except ImportError:
21 print ('Missing google-api-python-client. Please install it; directions ' 33 # TODO(epoger): We are moving toward not needing any dependencies to be
34 # installed at a system level, but in the meanwhile, if developers run into
35 # trouble they can install those system-level dependencies to get unblocked.
36 print ('Missing dependencies of google-api-python-client. Please install '
37 'google-api-python-client to get those dependencies; directions '
22 'can be found at https://developers.google.com/api-client-library/' 38 'can be found at https://developers.google.com/api-client-library/'
23 'python/start/installation') 39 'python/start/installation . More details in http://skbug.com/2641 ')
24 raise 40 raise
25 41
26 # Local imports 42 # Local imports
27 import url_utils 43 import url_utils
28 44
29 45
30 def download_file(source_bucket, source_path, dest_path, 46 def download_file(source_bucket, source_path, dest_path,
31 create_subdirs_if_needed=False): 47 create_subdirs_if_needed=False):
32 """ Downloads a single file from Google Cloud Storage to local disk. 48 """ Downloads a single file from Google Cloud Storage to local disk.
33 49
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 dirs = [] 88 dirs = []
73 for dir_fullpath in results.get('prefixes', []): 89 for dir_fullpath in results.get('prefixes', []):
74 dir_basename = dir_fullpath[subdir_length:] 90 dir_basename = dir_fullpath[subdir_length:]
75 dirs.append(dir_basename[:-1]) # strip trailing slash 91 dirs.append(dir_basename[:-1]) # strip trailing slash
76 files = [] 92 files = []
77 for file_properties in results.get('items', []): 93 for file_properties in results.get('items', []):
78 file_fullpath = file_properties['name'] 94 file_fullpath = file_properties['name']
79 file_basename = file_fullpath[subdir_length:] 95 file_basename = file_fullpath[subdir_length:]
80 files.append(file_basename) 96 files.append(file_basename)
81 return (dirs, files) 97 return (dirs, files)
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698