| Index: gslib/commands/version.py
|
| ===================================================================
|
| --- gslib/commands/version.py (revision 33376)
|
| +++ gslib/commands/version.py (working copy)
|
| @@ -1,3 +1,4 @@
|
| +# -*- coding: utf-8 -*-
|
| # Copyright 2011 Google Inc. All Rights Reserved.
|
| #
|
| # Licensed under the Apache License, Version 2.0 (the "License");
|
| @@ -11,34 +12,25 @@
|
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| # See the License for the specific language governing permissions and
|
| # limitations under the License.
|
| +"""Implementation of gsutil version command."""
|
|
|
| -import boto
|
| -import crcmod
|
| +from __future__ import absolute_import
|
| +
|
| +from hashlib import md5
|
| import os
|
| +import platform
|
| import re
|
| import sys
|
|
|
| +import boto
|
| +import crcmod
|
| import gslib
|
| from gslib.command import Command
|
| -from gslib.command import COMMAND_NAME
|
| -from gslib.command import COMMAND_NAME_ALIASES
|
| -from gslib.command import FILE_URIS_OK
|
| -from gslib.command import MAX_ARGS
|
| -from gslib.command import MIN_ARGS
|
| -from gslib.command import PROVIDER_URIS_OK
|
| -from gslib.command import SUPPORTED_SUB_ARGS
|
| -from gslib.command import URIS_START_ARG
|
| -from gslib.help_provider import HELP_NAME
|
| -from gslib.help_provider import HELP_NAME_ALIASES
|
| -from gslib.help_provider import HELP_ONE_LINE_SUMMARY
|
| -from gslib.help_provider import HELP_TEXT
|
| -from gslib.help_provider import HelpType
|
| -from gslib.help_provider import HELP_TYPE
|
| from gslib.util import GetConfigFilePath
|
| +from gslib.util import MultiprocessingIsAvailable
|
| from gslib.util import UsingCrcmodExtension
|
| -from hashlib import md5
|
|
|
| -_detailed_help_text = ("""
|
| +_DETAILED_HELP_TEXT = ("""
|
| <B>SYNOPSIS</B>
|
| gsutil version
|
|
|
| @@ -57,43 +49,32 @@
|
| class VersionCommand(Command):
|
| """Implementation of gsutil version command."""
|
|
|
| - # Command specification (processed by parent class).
|
| - command_spec = {
|
| - # Name of command.
|
| - COMMAND_NAME : 'version',
|
| - # List of command name aliases.
|
| - COMMAND_NAME_ALIASES : ['ver'],
|
| - # Min number of args required by this command.
|
| - MIN_ARGS : 0,
|
| - # Max number of args required by this command, or NO_MAX.
|
| - MAX_ARGS : 0,
|
| - # Getopt-style string specifying acceptable sub args.
|
| - SUPPORTED_SUB_ARGS : 'l',
|
| - # True if file URIs acceptable for this command.
|
| - FILE_URIS_OK : False,
|
| - # True if provider-only URIs acceptable for this command.
|
| - PROVIDER_URIS_OK : False,
|
| - # Index in args of first URI arg.
|
| - URIS_START_ARG : 0,
|
| - }
|
| - help_spec = {
|
| - # Name of command or auxiliary help info for which this help applies.
|
| - HELP_NAME : 'version',
|
| - # List of help name aliases.
|
| - HELP_NAME_ALIASES : ['ver'],
|
| - # Type of help:
|
| - HELP_TYPE : HelpType.COMMAND_HELP,
|
| - # One line summary of this help.
|
| - HELP_ONE_LINE_SUMMARY : 'Print version info about gsutil',
|
| - # The full help text.
|
| - HELP_TEXT : _detailed_help_text,
|
| - }
|
| + # Command specification. See base class for documentation.
|
| + command_spec = Command.CreateCommandSpec(
|
| + 'version',
|
| + command_name_aliases=['ver'],
|
| + min_args=0,
|
| + max_args=0,
|
| + supported_sub_args='l',
|
| + file_url_ok=False,
|
| + provider_url_ok=False,
|
| + urls_start_arg=0,
|
| + )
|
| + # Help specification. See help_provider.py for documentation.
|
| + help_spec = Command.HelpSpec(
|
| + help_name='version',
|
| + help_name_aliases=['ver'],
|
| + help_type='command_help',
|
| + help_one_line_summary='Print version info about gsutil',
|
| + help_text=_DETAILED_HELP_TEXT,
|
| + subcommand_help_text={},
|
| + )
|
|
|
| - # Command entry point.
|
| def RunCommand(self):
|
| + """Command entry point for the version command."""
|
| long_form = False
|
| if self.sub_opts:
|
| - for o, a in self.sub_opts:
|
| + for o, _ in self.sub_opts:
|
| if o == '-l':
|
| long_form = True
|
|
|
| @@ -109,14 +90,17 @@
|
| else:
|
| checksum_ok_str = '!= %s' % shipped_checksum
|
|
|
| - sys.stdout.write('gsutil version %s\n' % gslib.VERSION)
|
| + sys.stdout.write('gsutil version: %s\n' % gslib.VERSION)
|
|
|
| if long_form:
|
|
|
| long_form_output = (
|
| - 'checksum {checksum} ({checksum_ok})\n'
|
| - 'boto version {boto_version}\n'
|
| - 'python version {python_version}\n'
|
| + 'checksum: {checksum} ({checksum_ok})\n'
|
| + 'boto version: {boto_version}\n'
|
| + 'python version: {python_version}\n'
|
| + 'OS: {os_version}\n'
|
| + 'multiprocessing available: {multiprocessing_available}\n'
|
| + 'using cloud sdk: {cloud_sdk}\n'
|
| 'config path: {config_path}\n'
|
| 'gsutil path: {gsutil_path}\n'
|
| 'compiled crcmod: {compiled_crcmod}\n'
|
| @@ -128,7 +112,10 @@
|
| checksum=cur_checksum,
|
| checksum_ok=checksum_ok_str,
|
| boto_version=boto.__version__,
|
| - python_version=sys.version,
|
| + python_version=sys.version.replace('\n', ''),
|
| + os_version='%s %s' % (platform.system(), platform.release()),
|
| + multiprocessing_available=MultiprocessingIsAvailable()[0],
|
| + cloud_sdk=(os.environ.get('CLOUDSDK_WRAPPER') == '1'),
|
| config_path=config_path,
|
| gsutil_path=gslib.GSUTIL_PATH,
|
| compiled_crcmod=UsingCrcmodExtension(crcmod),
|
| @@ -139,25 +126,29 @@
|
| return 0
|
|
|
| def _ComputeCodeChecksum(self):
|
| - """
|
| - Computes a checksum of gsutil code so we can see if users locally modified
|
| + """Computes a checksum of gsutil code.
|
| +
|
| + This checksum can be used to determine if users locally modified
|
| gsutil when requesting support. (It's fine for users to make local mods,
|
| but when users ask for support we ask them to run a stock version of
|
| gsutil so we can reduce possible variables.)
|
| +
|
| + Returns:
|
| + MD5 checksum of gsutil code.
|
| """
|
| if gslib.IS_PACKAGE_INSTALL:
|
| return 'PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS'
|
| m = md5()
|
| # Checksum gsutil and all .py files under gslib directory.
|
| files_to_checksum = [gslib.GSUTIL_PATH]
|
| - for root, sub_folders, files in os.walk(gslib.GSLIB_DIR):
|
| - for file in files:
|
| - if file[-3:] == '.py':
|
| - files_to_checksum.append(os.path.join(root, file))
|
| + for root, _, files in os.walk(gslib.GSLIB_DIR):
|
| + for filepath in files:
|
| + if filepath.endswith('.py'):
|
| + files_to_checksum.append(os.path.join(root, filepath))
|
| # Sort to ensure consistent checksum build, no matter how os.walk
|
| # orders the list.
|
| - for file in sorted(files_to_checksum):
|
| - f = open(file, 'r')
|
| + for filepath in sorted(files_to_checksum):
|
| + f = open(filepath, 'r')
|
| content = f.read()
|
| content = re.sub(r'(\r\n|\r|\n)', '\n', content)
|
| m.update(content)
|
|
|