OLD | NEW |
---|---|
1 # Copyright 2010 Google Inc. All Rights Reserved. | 1 # Copyright 2010 Google Inc. All Rights Reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 """ | 162 """ |
163 test_steps = [] | 163 test_steps = [] |
164 | 164 |
165 # Define a convenience property for command name, since it's used many places. | 165 # Define a convenience property for command name, since it's used many places. |
166 def _GetDefaultCommandName(self): | 166 def _GetDefaultCommandName(self): |
167 return self.command_spec[COMMAND_NAME] | 167 return self.command_spec[COMMAND_NAME] |
168 command_name = property(_GetDefaultCommandName) | 168 command_name = property(_GetDefaultCommandName) |
169 | 169 |
170 def __init__(self, command_runner, args, headers, debug, parallel_operations, | 170 def __init__(self, command_runner, args, headers, debug, parallel_operations, |
171 gsutil_bin_dir, boto_lib_dir, config_file_list, gsutil_ver, | 171 gsutil_bin_dir, boto_lib_dir, config_file_list, gsutil_ver, |
172 bucket_storage_uri_class, test_method=None): | 172 bucket_storage_uri_class, test_method=None, |
173 bypass_prodaccess=True): | |
Vadim Sh.
2013/12/03 01:33:41
nit: add it to Args section in doc string.
Ryan Tseng
2013/12/03 22:57:11
Done.
| |
173 """ | 174 """ |
174 Args: | 175 Args: |
175 command_runner: CommandRunner (for commands built atop other commands). | 176 command_runner: CommandRunner (for commands built atop other commands). |
176 args: Command-line args (arg0 = actual arg, not command name ala bash). | 177 args: Command-line args (arg0 = actual arg, not command name ala bash). |
177 headers: Dictionary containing optional HTTP headers to pass to boto. | 178 headers: Dictionary containing optional HTTP headers to pass to boto. |
178 debug: Debug level to pass in to boto connection (range 0..3). | 179 debug: Debug level to pass in to boto connection (range 0..3). |
179 parallel_operations: Should command operations be executed in parallel? | 180 parallel_operations: Should command operations be executed in parallel? |
180 gsutil_bin_dir: Bin dir from which gsutil is running. | 181 gsutil_bin_dir: Bin dir from which gsutil is running. |
181 boto_lib_dir: Lib dir where boto runs. | 182 boto_lib_dir: Lib dir where boto runs. |
182 config_file_list: Config file list returned by _GetBotoConfigFileList(). | 183 config_file_list: Config file list returned by _GetBotoConfigFileList(). |
(...skipping 19 matching lines...) Expand all Loading... | |
202 self.parallel_operations = parallel_operations | 203 self.parallel_operations = parallel_operations |
203 self.gsutil_bin_dir = gsutil_bin_dir | 204 self.gsutil_bin_dir = gsutil_bin_dir |
204 self.boto_lib_dir = boto_lib_dir | 205 self.boto_lib_dir = boto_lib_dir |
205 self.config_file_list = config_file_list | 206 self.config_file_list = config_file_list |
206 self.gsutil_ver = gsutil_ver | 207 self.gsutil_ver = gsutil_ver |
207 self.bucket_storage_uri_class = bucket_storage_uri_class | 208 self.bucket_storage_uri_class = bucket_storage_uri_class |
208 self.test_method = test_method | 209 self.test_method = test_method |
209 self.exclude_symlinks = False | 210 self.exclude_symlinks = False |
210 self.recursion_requested = False | 211 self.recursion_requested = False |
211 self.all_versions = False | 212 self.all_versions = False |
213 self.bypass_prodaccess = bypass_prodaccess | |
212 | 214 |
213 # Process sub-command instance specifications. | 215 # Process sub-command instance specifications. |
214 # First, ensure subclass implementation sets all required keys. | 216 # First, ensure subclass implementation sets all required keys. |
215 for k in self.REQUIRED_SPEC_KEYS: | 217 for k in self.REQUIRED_SPEC_KEYS: |
216 if k not in self.command_spec or self.command_spec[k] is None: | 218 if k not in self.command_spec or self.command_spec[k] is None: |
217 raise CommandException('"%s" command implementation is missing %s ' | 219 raise CommandException('"%s" command implementation is missing %s ' |
218 'specification' % (self.command_name, k)) | 220 'specification' % (self.command_name, k)) |
219 # Now override default command_spec with subclass-specified values. | 221 # Now override default command_spec with subclass-specified values. |
220 tmp = self._default_command_spec | 222 tmp = self._default_command_spec |
221 tmp.update(self.command_spec) | 223 tmp.update(self.command_spec) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 storage_uri = self.UrisAreForSingleProvider(uri_args) | 338 storage_uri = self.UrisAreForSingleProvider(uri_args) |
337 if not storage_uri: | 339 if not storage_uri: |
338 raise CommandException('"%s" command spanning providers not allowed.' % | 340 raise CommandException('"%s" command spanning providers not allowed.' % |
339 self.command_name) | 341 self.command_name) |
340 | 342 |
341 # Determine whether acl_arg names a file containing XML ACL text vs. the | 343 # Determine whether acl_arg names a file containing XML ACL text vs. the |
342 # string name of a canned ACL. | 344 # string name of a canned ACL. |
343 if os.path.isfile(acl_arg): | 345 if os.path.isfile(acl_arg): |
344 acl_file = open(acl_arg, 'r') | 346 acl_file = open(acl_arg, 'r') |
345 acl_arg = acl_file.read() | 347 acl_arg = acl_file.read() |
346 | 348 |
347 # TODO: Remove this workaround when GCS allows | 349 # TODO: Remove this workaround when GCS allows |
348 # whitespace in the Permission element on the server-side | 350 # whitespace in the Permission element on the server-side |
349 acl_arg = re.sub(r'<Permission>\s*(\S+)\s*</Permission>', | 351 acl_arg = re.sub(r'<Permission>\s*(\S+)\s*</Permission>', |
350 r'<Permission>\1</Permission>', acl_arg) | 352 r'<Permission>\1</Permission>', acl_arg) |
351 | 353 |
352 acl_file.close() | 354 acl_file.close() |
353 self.canned = False | 355 self.canned = False |
354 else: | 356 else: |
355 # No file exists, so expect a canned ACL string. | 357 # No file exists, so expect a canned ACL string. |
356 canned_acls = storage_uri.canned_acls() | 358 canned_acls = storage_uri.canned_acls() |
357 if acl_arg not in canned_acls: | 359 if acl_arg not in canned_acls: |
358 raise CommandException('Invalid canned ACL "%s".' % acl_arg) | 360 raise CommandException('Invalid canned ACL "%s".' % acl_arg) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 True if args_to_check contains any provider URIs. | 637 True if args_to_check contains any provider URIs. |
636 """ | 638 """ |
637 for uri_str in args_to_check: | 639 for uri_str in args_to_check: |
638 if re.match('^[a-z]+://$', uri_str): | 640 if re.match('^[a-z]+://$', uri_str): |
639 return True | 641 return True |
640 return False | 642 return False |
641 | 643 |
642 def _ConfigureNoOpAuthIfNeeded(self): | 644 def _ConfigureNoOpAuthIfNeeded(self): |
643 """Sets up no-op auth handler if no boto credentials are configured.""" | 645 """Sets up no-op auth handler if no boto credentials are configured.""" |
644 config = boto.config | 646 config = boto.config |
645 if not util.HasConfiguredCredentials(): | 647 if not util.HasConfiguredCredentials(self.bypass_prodaccess): |
646 if self.config_file_list: | 648 if self.config_file_list: |
647 if (config.has_option('Credentials', 'gs_oauth2_refresh_token') | 649 if (config.has_option('Credentials', 'gs_oauth2_refresh_token') |
648 and not HAVE_OAUTH2): | 650 and not HAVE_OAUTH2): |
649 raise CommandException( | 651 raise CommandException( |
650 'Your gsutil is configured with OAuth2 authentication ' | 652 'Your gsutil is configured with OAuth2 authentication ' |
651 'credentials.\nHowever, OAuth2 is only supported when running ' | 653 'credentials.\nHowever, OAuth2 is only supported when running ' |
652 'under Python 2.6 or later\n(unless additional dependencies are ' | 654 'under Python 2.6 or later\n(unless additional dependencies are ' |
653 'installed, see README for details); you are running Python %s.' % | 655 'installed, see README for details); you are running Python %s.' % |
654 sys.version) | 656 sys.version) |
655 raise CommandException('You have no storage service credentials in any ' | 657 raise CommandException('You have no storage service credentials in any ' |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 if num_threads > 1: | 715 if num_threads > 1: |
714 thread_pool.WaitCompletion() | 716 thread_pool.WaitCompletion() |
715 finally: | 717 finally: |
716 if num_threads > 1: | 718 if num_threads > 1: |
717 thread_pool.Shutdown() | 719 thread_pool.Shutdown() |
718 # If any shared variables (which means we are running in a separate OS | 720 # If any shared variables (which means we are running in a separate OS |
719 # process), increment value for each shared variable. | 721 # process), increment value for each shared variable. |
720 if shared_vars: | 722 if shared_vars: |
721 for (name, var) in shared_vars.items(): | 723 for (name, var) in shared_vars.items(): |
722 var.value += getattr(self, name) | 724 var.value += getattr(self, name) |
OLD | NEW |