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

Side by Side Diff: gsutil.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 | « gsutil ('k') | scripts/bucket_relocate.sh » ('j') | 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/env python 1 #!/usr/bin/env python
2 # coding=utf8 2 # -*- coding: utf-8 -*-
3 # Copyright 2010 Google Inc. All Rights Reserved. 3 # Copyright 2010 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
11 # Unless required by applicable law or agreed to in writing, software 11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, 12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and 14 # See the License for the specific language governing permissions and
15 # limitations under the License. 15 # limitations under the License.
16 16
17 """Wrapper module for running gslib.__main__.main() from the command line.""" 17 """Wrapper module for running gslib.__main__.main() from the command line."""
18 18
19 import os 19 import os
20 import sys 20 import sys
21 import warnings 21 import warnings
22 22
23 # TODO: gsutil-beta: Distribute a pylint rc file.
23 24
24 if not (2, 6) <= sys.version_info[:3] < (3,): 25 if not (2, 6) <= sys.version_info[:3] < (3,):
25 sys.exit('gsutil requires python 2.6 or 2.7.') 26 sys.exit('gsutil requires python 2.6 or 2.7.')
26 27
27 28
28 def UsingCrcmodExtension(crcmod): 29 def UsingCrcmodExtension(crcmod_module):
29 return (getattr(crcmod, 'crcmod', None) and 30 return (getattr(crcmod_module, 'crcmod', None) and
30 getattr(crcmod.crcmod, '_usingExtension', None)) 31 getattr(crcmod_module.crcmod, '_usingExtension', None))
31 32
32 33
33 def _OutputAndExit(message): 34 def OutputAndExit(message):
34 sys.stderr.write('%s\n' % message) 35 sys.stderr.write('%s\n' % message)
35 sys.exit(1) 36 sys.exit(1)
36 37
37 38
38 GSUTIL_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) 39 GSUTIL_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
39 if not GSUTIL_DIR: 40 if not GSUTIL_DIR:
40 _OutputAndExit('Unable to determine where gsutil is installed. Sorry, ' 41 OutputAndExit('Unable to determine where gsutil is installed. Sorry, '
41 'cannot run correctly without this.\n') 42 'cannot run correctly without this.\n')
42 43
43 # The wrapper script adds all third_party libraries to the Python path, since 44 # The wrapper script adds all third_party libraries to the Python path, since
44 # we don't assume any third party libraries are installed system-wide. 45 # we don't assume any third party libraries are installed system-wide.
45 THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party') 46 THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party')
46 47
47 48
48 # Filter out "module was already imported" warnings that get printed after we 49 # Filter out "module was already imported" warnings that get printed after we
49 # add our bundled version of modules to the Python path. 50 # add our bundled version of modules to the Python path.
50 warnings.filterwarnings('ignore', category=UserWarning, 51 warnings.filterwarnings('ignore', category=UserWarning,
51 message=r'.* httplib2 was already imported from') 52 message=r'.* httplib2 was already imported from')
52 warnings.filterwarnings('ignore', category=UserWarning, 53 warnings.filterwarnings('ignore', category=UserWarning,
53 message=r'.* oauth2client was already imported from') 54 message=r'.* oauth2client was already imported from')
54 55
55 56
56 # List of third-party libraries. The first element of the tuple is the name of 57 # List of third-party libraries. The first element of the tuple is the name of
57 # the directory under third_party and the second element is the subdirectory 58 # the directory under third_party and the second element is the subdirectory
58 # that needs to be added to sys.path. 59 # that needs to be added to sys.path.
59 THIRD_PARTY_LIBS = [ 60 THIRD_PARTY_LIBS = [
61 ('google-api-python-client', ''), # Must be before boto.
62 ('boto', ''),
63 ('gcs-oauth2-boto-plugin', ''),
64 ('httplib2', 'python2'),
60 ('python-gflags', ''), 65 ('python-gflags', ''),
61 ('google-api-python-client', ''), 66 ('retry-decorator', ''),
62 ('httplib2', 'python2'),
63 ('boto', ''),
64 ('socksipy-branch', ''), 67 ('socksipy-branch', ''),
65 ('retry-decorator', ''),
66 ] 68 ]
67 for libdir, subdir in THIRD_PARTY_LIBS: 69 for libdir, subdir in THIRD_PARTY_LIBS:
68 if not os.path.isdir(os.path.join(THIRD_PARTY_DIR, libdir)): 70 if not os.path.isdir(os.path.join(THIRD_PARTY_DIR, libdir)):
69 _OutputAndExit( 71 OutputAndExit(
70 'There is no %s library under the gsutil third-party directory (%s).\n' 72 'There is no %s library under the gsutil third-party directory (%s).\n'
71 'The gsutil command cannot work properly when installed this way.\n' 73 'The gsutil command cannot work properly when installed this way.\n'
72 'Please re-install gsutil per the installation instructions.' % ( 74 'Please re-install gsutil per the installation instructions.' % (
73 libdir, THIRD_PARTY_DIR)) 75 libdir, THIRD_PARTY_DIR))
74 sys.path.insert(0, os.path.join(THIRD_PARTY_DIR, libdir, subdir)) 76 sys.path.insert(0, os.path.join(THIRD_PARTY_DIR, libdir, subdir))
75 77
76 # The wrapper script adds all third_party libraries to the Python path, since 78 # The wrapper script adds all third_party libraries to the Python path, since
77 # we don't assume any third party libraries are installed system-wide. 79 # we don't assume any third party libraries are installed system-wide.
78 THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party') 80 THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party')
79 81
80 CRCMOD_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod', 'python2') 82 CRCMOD_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod', 'python2')
81 CRCMOD_OSX_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod_osx') 83 CRCMOD_OSX_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod_osx')
82 84
83 try: 85 try:
86 # pylint: disable=g-import-not-at-top
84 import crcmod 87 import crcmod
85 except ImportError: 88 except ImportError:
86 crcmod = None 89 crcmod = None
87 90
88 if not UsingCrcmodExtension(crcmod): 91 if not UsingCrcmodExtension(crcmod):
89 local_crcmod_path = (CRCMOD_OSX_PATH 92 local_crcmod_path = (CRCMOD_OSX_PATH
90 if 'darwin' in str(sys.platform).lower() 93 if 'darwin' in str(sys.platform).lower()
91 else CRCMOD_PATH) 94 else CRCMOD_PATH)
92 sys.path.insert(0, local_crcmod_path) 95 sys.path.insert(0, local_crcmod_path)
93 96
97
94 def RunMain(): 98 def RunMain():
99 # pylint: disable=g-import-not-at-top
95 import gslib.__main__ 100 import gslib.__main__
96 sys.exit(gslib.__main__.main()) 101 sys.exit(gslib.__main__.main())
97 102
98 if __name__ == '__main__': 103 if __name__ == '__main__':
99 RunMain() 104 RunMain()
OLDNEW
« no previous file with comments | « gsutil ('k') | scripts/bucket_relocate.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698