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

Side by Side Diff: gslib/commands/version.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « gslib/commands/update.py ('k') | gslib/commands/versioning.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*-
1 # Copyright 2011 Google Inc. All Rights Reserved. 2 # Copyright 2011 Google Inc. All Rights Reserved.
2 # 3 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # Licensed under the Apache License, Version 2.0 (the "License");
4 # 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.
5 # You may obtain a copy of the License at 6 # You may obtain a copy of the License at
6 # 7 #
7 # http://www.apache.org/licenses/LICENSE-2.0 8 # http://www.apache.org/licenses/LICENSE-2.0
8 # 9 #
9 # Unless required by applicable law or agreed to in writing, software 10 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and 13 # See the License for the specific language governing permissions and
13 # limitations under the License. 14 # limitations under the License.
15 """Implementation of gsutil version command."""
16
17 from __future__ import absolute_import
18
19 from hashlib import md5
20 import os
21 import platform
22 import re
23 import sys
14 24
15 import boto 25 import boto
16 import crcmod 26 import crcmod
17 import os
18 import re
19 import sys
20
21 import gslib 27 import gslib
22 from gslib.command import Command 28 from gslib.command import Command
23 from gslib.command import COMMAND_NAME
24 from gslib.command import COMMAND_NAME_ALIASES
25 from gslib.command import FILE_URIS_OK
26 from gslib.command import MAX_ARGS
27 from gslib.command import MIN_ARGS
28 from gslib.command import PROVIDER_URIS_OK
29 from gslib.command import SUPPORTED_SUB_ARGS
30 from gslib.command import URIS_START_ARG
31 from gslib.help_provider import HELP_NAME
32 from gslib.help_provider import HELP_NAME_ALIASES
33 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
34 from gslib.help_provider import HELP_TEXT
35 from gslib.help_provider import HelpType
36 from gslib.help_provider import HELP_TYPE
37 from gslib.util import GetConfigFilePath 29 from gslib.util import GetConfigFilePath
30 from gslib.util import MultiprocessingIsAvailable
38 from gslib.util import UsingCrcmodExtension 31 from gslib.util import UsingCrcmodExtension
39 from hashlib import md5
40 32
41 _detailed_help_text = (""" 33 _DETAILED_HELP_TEXT = ("""
42 <B>SYNOPSIS</B> 34 <B>SYNOPSIS</B>
43 gsutil version 35 gsutil version
44 36
45 37
46 <B>DESCRIPTION</B> 38 <B>DESCRIPTION</B>
47 Prints information about the version of gsutil. 39 Prints information about the version of gsutil.
48 40
49 <B>OPTIONS</B> 41 <B>OPTIONS</B>
50 -l Prints additional information, such as the version of Python 42 -l Prints additional information, such as the version of Python
51 being used, the version of the Boto library, a checksum of the 43 being used, the version of the Boto library, a checksum of the
52 code, the path to gsutil, and the path to gsutil's configuration 44 code, the path to gsutil, and the path to gsutil's configuration
53 file. 45 file.
54 """) 46 """)
55 47
56 48
57 class VersionCommand(Command): 49 class VersionCommand(Command):
58 """Implementation of gsutil version command.""" 50 """Implementation of gsutil version command."""
59 51
60 # Command specification (processed by parent class). 52 # Command specification. See base class for documentation.
61 command_spec = { 53 command_spec = Command.CreateCommandSpec(
62 # Name of command. 54 'version',
63 COMMAND_NAME : 'version', 55 command_name_aliases=['ver'],
64 # List of command name aliases. 56 min_args=0,
65 COMMAND_NAME_ALIASES : ['ver'], 57 max_args=0,
66 # Min number of args required by this command. 58 supported_sub_args='l',
67 MIN_ARGS : 0, 59 file_url_ok=False,
68 # Max number of args required by this command, or NO_MAX. 60 provider_url_ok=False,
69 MAX_ARGS : 0, 61 urls_start_arg=0,
70 # Getopt-style string specifying acceptable sub args. 62 )
71 SUPPORTED_SUB_ARGS : 'l', 63 # Help specification. See help_provider.py for documentation.
72 # True if file URIs acceptable for this command. 64 help_spec = Command.HelpSpec(
73 FILE_URIS_OK : False, 65 help_name='version',
74 # True if provider-only URIs acceptable for this command. 66 help_name_aliases=['ver'],
75 PROVIDER_URIS_OK : False, 67 help_type='command_help',
76 # Index in args of first URI arg. 68 help_one_line_summary='Print version info about gsutil',
77 URIS_START_ARG : 0, 69 help_text=_DETAILED_HELP_TEXT,
78 } 70 subcommand_help_text={},
79 help_spec = { 71 )
80 # Name of command or auxiliary help info for which this help applies.
81 HELP_NAME : 'version',
82 # List of help name aliases.
83 HELP_NAME_ALIASES : ['ver'],
84 # Type of help:
85 HELP_TYPE : HelpType.COMMAND_HELP,
86 # One line summary of this help.
87 HELP_ONE_LINE_SUMMARY : 'Print version info about gsutil',
88 # The full help text.
89 HELP_TEXT : _detailed_help_text,
90 }
91 72
92 # Command entry point.
93 def RunCommand(self): 73 def RunCommand(self):
74 """Command entry point for the version command."""
94 long_form = False 75 long_form = False
95 if self.sub_opts: 76 if self.sub_opts:
96 for o, a in self.sub_opts: 77 for o, _ in self.sub_opts:
97 if o == '-l': 78 if o == '-l':
98 long_form = True 79 long_form = True
99 80
100 config_path = GetConfigFilePath() 81 config_path = GetConfigFilePath()
101 82
102 shipped_checksum = gslib.CHECKSUM 83 shipped_checksum = gslib.CHECKSUM
103 try: 84 try:
104 cur_checksum = self._ComputeCodeChecksum() 85 cur_checksum = self._ComputeCodeChecksum()
105 except IOError: 86 except IOError:
106 cur_checksum = 'MISSING FILES' 87 cur_checksum = 'MISSING FILES'
107 if shipped_checksum == cur_checksum: 88 if shipped_checksum == cur_checksum:
108 checksum_ok_str = 'OK' 89 checksum_ok_str = 'OK'
109 else: 90 else:
110 checksum_ok_str = '!= %s' % shipped_checksum 91 checksum_ok_str = '!= %s' % shipped_checksum
111 92
112 sys.stdout.write('gsutil version %s\n' % gslib.VERSION) 93 sys.stdout.write('gsutil version: %s\n' % gslib.VERSION)
113 94
114 if long_form: 95 if long_form:
115 96
116 long_form_output = ( 97 long_form_output = (
117 'checksum {checksum} ({checksum_ok})\n' 98 'checksum: {checksum} ({checksum_ok})\n'
118 'boto version {boto_version}\n' 99 'boto version: {boto_version}\n'
119 'python version {python_version}\n' 100 'python version: {python_version}\n'
101 'OS: {os_version}\n'
102 'multiprocessing available: {multiprocessing_available}\n'
103 'using cloud sdk: {cloud_sdk}\n'
120 'config path: {config_path}\n' 104 'config path: {config_path}\n'
121 'gsutil path: {gsutil_path}\n' 105 'gsutil path: {gsutil_path}\n'
122 'compiled crcmod: {compiled_crcmod}\n' 106 'compiled crcmod: {compiled_crcmod}\n'
123 'installed via package manager: {is_package_install}\n' 107 'installed via package manager: {is_package_install}\n'
124 'editable install: {is_editable_install}\n' 108 'editable install: {is_editable_install}\n'
125 ) 109 )
126 110
127 sys.stdout.write(long_form_output.format( 111 sys.stdout.write(long_form_output.format(
128 checksum=cur_checksum, 112 checksum=cur_checksum,
129 checksum_ok=checksum_ok_str, 113 checksum_ok=checksum_ok_str,
130 boto_version=boto.__version__, 114 boto_version=boto.__version__,
131 python_version=sys.version, 115 python_version=sys.version.replace('\n', ''),
116 os_version='%s %s' % (platform.system(), platform.release()),
117 multiprocessing_available=MultiprocessingIsAvailable()[0],
118 cloud_sdk=(os.environ.get('CLOUDSDK_WRAPPER') == '1'),
132 config_path=config_path, 119 config_path=config_path,
133 gsutil_path=gslib.GSUTIL_PATH, 120 gsutil_path=gslib.GSUTIL_PATH,
134 compiled_crcmod=UsingCrcmodExtension(crcmod), 121 compiled_crcmod=UsingCrcmodExtension(crcmod),
135 is_package_install=gslib.IS_PACKAGE_INSTALL, 122 is_package_install=gslib.IS_PACKAGE_INSTALL,
136 is_editable_install=gslib.IS_EDITABLE_INSTALL, 123 is_editable_install=gslib.IS_EDITABLE_INSTALL,
137 )) 124 ))
138 125
139 return 0 126 return 0
140 127
141 def _ComputeCodeChecksum(self): 128 def _ComputeCodeChecksum(self):
142 """ 129 """Computes a checksum of gsutil code.
143 Computes a checksum of gsutil code so we can see if users locally modified 130
131 This checksum can be used to determine if users locally modified
144 gsutil when requesting support. (It's fine for users to make local mods, 132 gsutil when requesting support. (It's fine for users to make local mods,
145 but when users ask for support we ask them to run a stock version of 133 but when users ask for support we ask them to run a stock version of
146 gsutil so we can reduce possible variables.) 134 gsutil so we can reduce possible variables.)
135
136 Returns:
137 MD5 checksum of gsutil code.
147 """ 138 """
148 if gslib.IS_PACKAGE_INSTALL: 139 if gslib.IS_PACKAGE_INSTALL:
149 return 'PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS' 140 return 'PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS'
150 m = md5() 141 m = md5()
151 # Checksum gsutil and all .py files under gslib directory. 142 # Checksum gsutil and all .py files under gslib directory.
152 files_to_checksum = [gslib.GSUTIL_PATH] 143 files_to_checksum = [gslib.GSUTIL_PATH]
153 for root, sub_folders, files in os.walk(gslib.GSLIB_DIR): 144 for root, _, files in os.walk(gslib.GSLIB_DIR):
154 for file in files: 145 for filepath in files:
155 if file[-3:] == '.py': 146 if filepath.endswith('.py'):
156 files_to_checksum.append(os.path.join(root, file)) 147 files_to_checksum.append(os.path.join(root, filepath))
157 # Sort to ensure consistent checksum build, no matter how os.walk 148 # Sort to ensure consistent checksum build, no matter how os.walk
158 # orders the list. 149 # orders the list.
159 for file in sorted(files_to_checksum): 150 for filepath in sorted(files_to_checksum):
160 f = open(file, 'r') 151 f = open(filepath, 'r')
161 content = f.read() 152 content = f.read()
162 content = re.sub(r'(\r\n|\r|\n)', '\n', content) 153 content = re.sub(r'(\r\n|\r|\n)', '\n', content)
163 m.update(content) 154 m.update(content)
164 f.close() 155 f.close()
165 return m.hexdigest() 156 return m.hexdigest()
OLDNEW
« no previous file with comments | « gslib/commands/update.py ('k') | gslib/commands/versioning.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698