| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2011 Google Inc. All Rights Reserved. | 2 # Copyright 2011 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 from gslib.command import OLD_ALIAS_MAP | 34 from gslib.command import OLD_ALIAS_MAP |
| 35 from gslib.command import ShutDownGsutil | 35 from gslib.command import ShutDownGsutil |
| 36 import gslib.commands | 36 import gslib.commands |
| 37 from gslib.cs_api_map import ApiSelector | 37 from gslib.cs_api_map import ApiSelector |
| 38 from gslib.cs_api_map import GsutilApiClassMapFactory | 38 from gslib.cs_api_map import GsutilApiClassMapFactory |
| 39 from gslib.cs_api_map import GsutilApiMapFactory | 39 from gslib.cs_api_map import GsutilApiMapFactory |
| 40 from gslib.exception import CommandException | 40 from gslib.exception import CommandException |
| 41 from gslib.gcs_json_api import GcsJsonApi | 41 from gslib.gcs_json_api import GcsJsonApi |
| 42 from gslib.no_op_credentials import NoOpCredentials | 42 from gslib.no_op_credentials import NoOpCredentials |
| 43 from gslib.tab_complete import MakeCompleter | 43 from gslib.tab_complete import MakeCompleter |
| 44 from gslib.util import CheckMultiprocessingAvailableAndInit |
| 44 from gslib.util import CompareVersions | 45 from gslib.util import CompareVersions |
| 45 from gslib.util import GetGsutilVersionModifiedTime | 46 from gslib.util import GetGsutilVersionModifiedTime |
| 46 from gslib.util import GSUTIL_PUB_TARBALL | 47 from gslib.util import GSUTIL_PUB_TARBALL |
| 47 from gslib.util import IsRunningInteractively | 48 from gslib.util import IsRunningInteractively |
| 48 from gslib.util import LAST_CHECKED_FOR_GSUTIL_UPDATE_TIMESTAMP_FILE | 49 from gslib.util import LAST_CHECKED_FOR_GSUTIL_UPDATE_TIMESTAMP_FILE |
| 49 from gslib.util import LookUpGsutilVersion | 50 from gslib.util import LookUpGsutilVersion |
| 50 from gslib.util import MultiprocessingIsAvailable | |
| 51 from gslib.util import RELEASE_NOTES_URL | 51 from gslib.util import RELEASE_NOTES_URL |
| 52 from gslib.util import SECONDS_PER_DAY | 52 from gslib.util import SECONDS_PER_DAY |
| 53 from gslib.util import UTF8 | 53 from gslib.util import UTF8 |
| 54 | 54 |
| 55 | 55 |
| 56 def HandleArgCoding(args): | 56 def HandleArgCoding(args): |
| 57 """Handles coding of command-line args. | 57 """Handles coding of command-line args. |
| 58 | 58 |
| 59 Args: | 59 Args: |
| 60 args: array of command-line args. | 60 args: array of command-line args. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 for subcommand, arguments in subcommand_argument_dict.iteritems(): | 192 for subcommand, arguments in subcommand_argument_dict.iteritems(): |
| 193 subcommand_parser = subcommand_parsers.add_parser( | 193 subcommand_parser = subcommand_parsers.add_parser( |
| 194 subcommand, add_help=False) | 194 subcommand, add_help=False) |
| 195 self._ConfigureCommandArgumentParserArguments( | 195 self._ConfigureCommandArgumentParserArguments( |
| 196 subcommand_parser, arguments, gsutil_api) | 196 subcommand_parser, arguments, gsutil_api) |
| 197 else: | 197 else: |
| 198 self._ConfigureCommandArgumentParserArguments( | 198 self._ConfigureCommandArgumentParserArguments( |
| 199 command_parser, command.command_spec.argparse_arguments, gsutil_api) | 199 command_parser, command.command_spec.argparse_arguments, gsutil_api) |
| 200 | 200 |
| 201 def RunNamedCommand(self, command_name, args=None, headers=None, debug=0, | 201 def RunNamedCommand(self, command_name, args=None, headers=None, debug=0, |
| 202 parallel_operations=False, test_method=None, | 202 trace_token=None, parallel_operations=False, |
| 203 skip_update_check=False, logging_filters=None, | 203 skip_update_check=False, logging_filters=None, |
| 204 do_shutdown=True): | 204 do_shutdown=True): |
| 205 """Runs the named command. | 205 """Runs the named command. |
| 206 | 206 |
| 207 Used by gsutil main, commands built atop other commands, and tests. | 207 Used by gsutil main, commands built atop other commands, and tests. |
| 208 | 208 |
| 209 Args: | 209 Args: |
| 210 command_name: The name of the command being run. | 210 command_name: The name of the command being run. |
| 211 args: Command-line args (arg0 = actual arg, not command name ala bash). | 211 args: Command-line args (arg0 = actual arg, not command name ala bash). |
| 212 headers: Dictionary containing optional HTTP headers to pass to boto. | 212 headers: Dictionary containing optional HTTP headers to pass to boto. |
| 213 debug: Debug level to pass in to boto connection (range 0..3). | 213 debug: Debug level to pass in to boto connection (range 0..3). |
| 214 trace_token: Trace token to pass to the underlying API. |
| 214 parallel_operations: Should command operations be executed in parallel? | 215 parallel_operations: Should command operations be executed in parallel? |
| 215 test_method: Optional general purpose method for testing purposes. | |
| 216 Application and semantics of this method will vary by | |
| 217 command and test type. | |
| 218 skip_update_check: Set to True to disable checking for gsutil updates. | 216 skip_update_check: Set to True to disable checking for gsutil updates. |
| 219 logging_filters: Optional list of logging.Filters to apply to this | 217 logging_filters: Optional list of logging.Filters to apply to this |
| 220 command's logger. | 218 command's logger. |
| 221 do_shutdown: Stop all parallelism framework workers iff this is True. | 219 do_shutdown: Stop all parallelism framework workers iff this is True. |
| 222 | 220 |
| 223 Raises: | 221 Raises: |
| 224 CommandException: if errors encountered. | 222 CommandException: if errors encountered. |
| 225 | 223 |
| 226 Returns: | 224 Returns: |
| 227 Return value(s) from Command that was run. | 225 Return value(s) from Command that was run. |
| 228 """ | 226 """ |
| 227 command_changed_to_update = False |
| 229 if (not skip_update_check and | 228 if (not skip_update_check and |
| 230 self.MaybeCheckForAndOfferSoftwareUpdate(command_name, debug)): | 229 self.MaybeCheckForAndOfferSoftwareUpdate(command_name, debug)): |
| 231 command_name = 'update' | 230 command_name = 'update' |
| 231 command_changed_to_update = True |
| 232 args = ['-n'] | 232 args = ['-n'] |
| 233 | 233 |
| 234 if not args: | 234 if not args: |
| 235 args = [] | 235 args = [] |
| 236 | 236 |
| 237 # Include api_version header in all commands. | 237 # Include api_version header in all commands. |
| 238 api_version = boto.config.get_value('GSUtil', 'default_api_version', '1') | 238 api_version = boto.config.get_value('GSUtil', 'default_api_version', '1') |
| 239 if not headers: | 239 if not headers: |
| 240 headers = {} | 240 headers = {} |
| 241 headers['x-goog-api-version'] = api_version | 241 headers['x-goog-api-version'] = api_version |
| (...skipping 22 matching lines...) Expand all Loading... |
| 264 if arg in subcommands: | 264 if arg in subcommands: |
| 265 new_args.append(arg) | 265 new_args.append(arg) |
| 266 break # Take the first match and throw away the rest. | 266 break # Take the first match and throw away the rest. |
| 267 args = new_args | 267 args = new_args |
| 268 command_name = 'help' | 268 command_name = 'help' |
| 269 | 269 |
| 270 args = HandleArgCoding(args) | 270 args = HandleArgCoding(args) |
| 271 | 271 |
| 272 command_class = self.command_map[command_name] | 272 command_class = self.command_map[command_name] |
| 273 command_inst = command_class( | 273 command_inst = command_class( |
| 274 self, args, headers, debug, parallel_operations, | 274 self, args, headers, debug, trace_token, parallel_operations, |
| 275 self.bucket_storage_uri_class, self.gsutil_api_class_map_factory, | 275 self.bucket_storage_uri_class, self.gsutil_api_class_map_factory, |
| 276 test_method, logging_filters, command_alias_used=command_name) | 276 logging_filters, command_alias_used=command_name) |
| 277 return_code = command_inst.RunCommand() | 277 return_code = command_inst.RunCommand() |
| 278 | 278 |
| 279 if MultiprocessingIsAvailable()[0] and do_shutdown: | 279 if CheckMultiprocessingAvailableAndInit().is_available and do_shutdown: |
| 280 ShutDownGsutil() | 280 ShutDownGsutil() |
| 281 if GetFailureCount() > 0: | 281 if GetFailureCount() > 0: |
| 282 return_code = 1 | 282 return_code = 1 |
| 283 if command_changed_to_update: |
| 284 # If the command changed to update, the user's original command was |
| 285 # not executed. |
| 286 return_code = 1 |
| 287 print '\n'.join(textwrap.wrap( |
| 288 'Update was successful. Exiting with code 1 as the original command ' |
| 289 'issued prior to the update was not executed and should be re-run.')) |
| 283 return return_code | 290 return return_code |
| 284 | 291 |
| 285 def MaybeCheckForAndOfferSoftwareUpdate(self, command_name, debug): | 292 def MaybeCheckForAndOfferSoftwareUpdate(self, command_name, debug): |
| 286 """Checks the last time we checked for an update and offers one if needed. | 293 """Checks the last time we checked for an update and offers one if needed. |
| 287 | 294 |
| 288 Offer is made if the time since the last update check is longer | 295 Offer is made if the time since the last update check is longer |
| 289 than the configured threshold offers the user to update gsutil. | 296 than the configured threshold offers the user to update gsutil. |
| 290 | 297 |
| 291 Args: | 298 Args: |
| 292 command_name: The name of the command being run. | 299 command_name: The name of the command being run. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 'A newer version of gsutil (%s) is available than the version you ' | 379 'A newer version of gsutil (%s) is available than the version you ' |
| 373 'are running (%s). A detailed log of gsutil release changes is ' | 380 'are running (%s). A detailed log of gsutil release changes is ' |
| 374 'available at %s if you would like to read them before updating.' | 381 'available at %s if you would like to read them before updating.' |
| 375 % (cur_ver, gslib.VERSION, RELEASE_NOTES_URL))) | 382 % (cur_ver, gslib.VERSION, RELEASE_NOTES_URL))) |
| 376 if gslib.IS_PACKAGE_INSTALL: | 383 if gslib.IS_PACKAGE_INSTALL: |
| 377 return False | 384 return False |
| 378 print | 385 print |
| 379 answer = raw_input('Would you like to update [Y/n]? ') | 386 answer = raw_input('Would you like to update [Y/n]? ') |
| 380 return not answer or answer.lower()[0] != 'n' | 387 return not answer or answer.lower()[0] != 'n' |
| 381 return False | 388 return False |
| OLD | NEW |