2 # -*- coding: utf-8 -*-
3 # Copyright 2010 Google Inc. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (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
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Wrapper module for running gslib.__main__.main() from the command line."""
23 # TODO: gsutil-beta: Distribute a pylint rc file.
25 if not (2, 6) <= sys
.version_info
[:3] < (3,):
26 sys
.exit('gsutil requires python 2.6 or 2.7.')
29 def UsingCrcmodExtension(crcmod_module
):
30 return (getattr(crcmod_module
, 'crcmod', None) and
31 getattr(crcmod_module
.crcmod
, '_usingExtension', None))
34 def OutputAndExit(message
):
35 sys
.stderr
.write('%s\n' % message
)
39 GSUTIL_DIR
= os
.path
.dirname(os
.path
.abspath(os
.path
.realpath(__file__
)))
41 OutputAndExit('Unable to determine where gsutil is installed. Sorry, '
42 'cannot run correctly without this.\n')
44 # The wrapper script adds all third_party libraries to the Python path, since
45 # we don't assume any third party libraries are installed system-wide.
46 THIRD_PARTY_DIR
= os
.path
.join(GSUTIL_DIR
, 'third_party')
49 # Filter out "module was already imported" warnings that get printed after we
50 # add our bundled version of modules to the Python path.
51 warnings
.filterwarnings('ignore', category
=UserWarning,
52 message
=r
'.* httplib2 was already imported from')
53 warnings
.filterwarnings('ignore', category
=UserWarning,
54 message
=r
'.* oauth2client was already imported from')
57 # List of third-party libraries. The first element of the tuple is the name of
58 # the directory under third_party and the second element is the subdirectory
59 # that needs to be added to sys.path.
61 ('oauth2client', ''), # oauth2client and dependencies must be before boto.
62 ('pyasn1', ''), # oauth2client dependency
63 ('pyasn1-modules', ''), # oauth2client dependency
64 ('rsa', ''), # oauth2client dependency
67 ('gcs-oauth2-boto-plugin', ''),
68 ('httplib2', 'python2'),
70 ('python-gflags', ''),
71 ('retry-decorator', ''),
73 ('socksipy-branch', ''),
75 for libdir
, subdir
in THIRD_PARTY_LIBS
:
76 if not os
.path
.isdir(os
.path
.join(THIRD_PARTY_DIR
, libdir
)):
78 'There is no %s library under the gsutil third-party directory (%s).\n'
79 'The gsutil command cannot work properly when installed this way.\n'
80 'Please re-install gsutil per the installation instructions.' % (
81 libdir
, THIRD_PARTY_DIR
))
82 sys
.path
.insert(0, os
.path
.join(THIRD_PARTY_DIR
, libdir
, subdir
))
84 # The wrapper script adds all third_party libraries to the Python path, since
85 # we don't assume any third party libraries are installed system-wide.
86 THIRD_PARTY_DIR
= os
.path
.join(GSUTIL_DIR
, 'third_party')
88 CRCMOD_PATH
= os
.path
.join(THIRD_PARTY_DIR
, 'crcmod', 'python2')
89 CRCMOD_OSX_PATH
= os
.path
.join(THIRD_PARTY_DIR
, 'crcmod_osx')
92 # pylint: disable=g-import-not-at-top
97 if not UsingCrcmodExtension(crcmod
):
98 local_crcmod_path
= (CRCMOD_OSX_PATH
99 if 'darwin' in str(sys
.platform
).lower()
101 sys
.path
.insert(0, local_crcmod_path
)
105 # pylint: disable=g-import-not-at-top
106 import gslib
.__main
__
107 sys
.exit(gslib
.__main
__.main())
109 if __name__
== '__main__':