| OLD | NEW |
| 1 # -*- coding: utf-8 -*- |
| 1 # Copyright 2010 Google Inc. All Rights Reserved. | 2 # Copyright 2010 Google Inc. All Rights Reserved. |
| 2 # | 3 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 10 # lowing conditions: |
| 10 # | 11 # |
| 11 # The above copyright notice and this permission notice shall be included | 12 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. | 13 # in all copies or substantial portions of the Software. |
| 13 # | 14 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. | 21 # IN THE SOFTWARE. |
| 22 """Package marker file.""" |
| 21 | 23 |
| 22 """Package marker file.""" | 24 from __future__ import absolute_import |
| 23 | 25 |
| 24 import os | 26 import os |
| 25 import pkgutil | 27 import pkgutil |
| 26 import sys | 28 import sys |
| 29 import tempfile |
| 27 | 30 |
| 28 import gslib.exception | 31 import gslib.exception |
| 29 | 32 |
| 33 coverage_outfile = os.getenv('GSUTIL_COVERAGE_OUTPUT_FILE', None) |
| 34 if coverage_outfile: |
| 35 try: |
| 36 import coverage # pylint: disable=g-import-not-at-top |
| 37 coverage_controller = coverage.coverage( |
| 38 data_file=coverage_outfile, data_suffix=True, auto_data=True, |
| 39 source=['gslib'], omit=['gslib/third_party/*', 'gslib/tests/*', |
| 40 tempfile.gettempdir() + '*']) |
| 41 coverage_controller.start() |
| 42 except ImportError: |
| 43 pass |
| 44 |
| 45 |
| 30 # Directory containing the gslib module. | 46 # Directory containing the gslib module. |
| 31 GSLIB_DIR = os.path.dirname(os.path.realpath(__file__)) | 47 GSLIB_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 32 # Path to gsutil executable. This assumes gsutil is the running script. | 48 # Path to gsutil executable. This assumes gsutil is the running script. |
| 33 GSUTIL_PATH = os.path.realpath(sys.argv[0]) | 49 GSUTIL_PATH = os.path.realpath(sys.argv[0]) |
| 34 # The directory that contains the gsutil executable. | 50 # The directory that contains the gsutil executable. |
| 35 GSUTIL_DIR = os.path.dirname(GSUTIL_PATH) | 51 GSUTIL_DIR = os.path.dirname(GSUTIL_PATH) |
| 36 | 52 |
| 37 # Whether or not this was installed via a package manager like pip, deb, rpm, | 53 # Whether or not this was installed via a package manager like pip, deb, rpm, |
| 38 # etc. If installed by just extracting a tarball or zip file, this will be | 54 # etc. If installed by just extracting a tarball or zip file, this will be |
| 39 # False. | 55 # False. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 IS_EDITABLE_INSTALL = True | 78 IS_EDITABLE_INSTALL = True |
| 63 | 79 |
| 64 # If installed via editable mode, we have to add the mock_storage_service | 80 # If installed via editable mode, we have to add the mock_storage_service |
| 65 # module to the Python path, since the gsutil script path munging is not | 81 # module to the Python path, since the gsutil script path munging is not |
| 66 # executed in this mode. | 82 # executed in this mode. |
| 67 if IS_EDITABLE_INSTALL: | 83 if IS_EDITABLE_INSTALL: |
| 68 mock_storage_location = os.path.join( | 84 mock_storage_location = os.path.join( |
| 69 PROGRAM_FILES_DIR, 'third_party', 'boto', 'tests', 'integration', 's3') | 85 PROGRAM_FILES_DIR, 'third_party', 'boto', 'tests', 'integration', 's3') |
| 70 sys.path.append(mock_storage_location) | 86 sys.path.append(mock_storage_location) |
| 71 | 87 |
| 88 |
| 72 def _GetFileContents(filename): | 89 def _GetFileContents(filename): |
| 73 """Tries to find the given filename on disk or via pkgutil.get_data. | 90 """Tries to find the given filename on disk or via pkgutil.get_data. |
| 74 | 91 |
| 92 Args: |
| 93 filename: String name of the file. |
| 94 |
| 75 Returns: | 95 Returns: |
| 76 A tuple containing the absolute path to the requested file and the file's | 96 A tuple containing the absolute path to the requested file and the file's |
| 77 contents. If the file is not actually on disk, the file path will be None. | 97 contents. If the file is not actually on disk, the file path will be None. |
| 78 """ | 98 """ |
| 79 fpath = os.path.join(PROGRAM_FILES_DIR, filename) | 99 fpath = os.path.join(PROGRAM_FILES_DIR, filename) |
| 80 if os.path.isfile(fpath): | 100 if os.path.isfile(fpath): |
| 81 with open(fpath, 'r') as f: | 101 with open(fpath, 'r') as f: |
| 82 content = f.read() | 102 content = f.read() |
| 83 else: | 103 else: |
| 84 content = pkgutil.get_data('gslib', filename) | 104 content = pkgutil.get_data('gslib', filename) |
| 85 fpath = None | 105 fpath = None |
| 86 return (fpath, content.strip()) | 106 return (fpath, content.strip()) |
| 87 | 107 |
| 88 # Get the version file and store it. | 108 # Get the version file and store it. |
| 89 VERSION_FILE, VERSION = _GetFileContents('VERSION') | 109 VERSION_FILE, VERSION = _GetFileContents('VERSION') |
| 90 if not VERSION: | 110 if not VERSION: |
| 91 raise gslib.exception.CommandException( | 111 raise gslib.exception.CommandException( |
| 92 'VERSION file not found. Please reinstall gsutil from scratch') | 112 'VERSION file not found. Please reinstall gsutil from scratch') |
| 93 __version__ = VERSION | 113 __version__ = VERSION |
| 94 | 114 |
| 95 # Get the checksum file and store it. | 115 # Get the checksum file and store it. |
| 96 CHECKSUM_FILE, CHECKSUM = _GetFileContents('CHECKSUM') | 116 CHECKSUM_FILE, CHECKSUM = _GetFileContents('CHECKSUM') |
| 97 if not CHECKSUM: | 117 if not CHECKSUM: |
| 98 raise gslib.exception.CommandException( | 118 raise gslib.exception.CommandException( |
| 99 'CHECKSUM file not found. Please reinstall gsutil from scratch') | 119 'CHECKSUM file not found. Please reinstall gsutil from scratch') |
| OLD | NEW |