OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # coding=utf8 |
| 3 # Copyright 2011 Google Inc. |
| 4 # |
| 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 |
| 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # |
| 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. |
| 16 |
| 17 '''Distutils setup.py script for Google Cloud Storage command line tool.''' |
| 18 |
| 19 import glob |
| 20 import sys |
| 21 import os |
| 22 import platform |
| 23 from distutils.core import setup |
| 24 from pkg_util import parse_manifest |
| 25 |
| 26 print ''' |
| 27 NOTE: Enterprise mode (installing gsutil via setup.py) is no longer officially |
| 28 supported - unpacking the zip file into a directory is the preferred method |
| 29 for installing gsutil for both shared and private configurations. See README |
| 30 and README.pkg for further details. |
| 31 ''' |
| 32 |
| 33 # Command name and target directory. |
| 34 NAME = 'gsutil' |
| 35 TARGET = '/usr/share/gsutil' |
| 36 BINDIR = '/usr/bin' |
| 37 |
| 38 # Enterprise mode (shared/central) installation is not supported |
| 39 # on Windows. |
| 40 system = platform.system() |
| 41 if system.lower().startswith('windows'): |
| 42 error = 'ERROR: enterprise (shared/central) installation is not ' \ |
| 43 'supported on Windows.' |
| 44 exit(error) |
| 45 |
| 46 def walk(dir, paths): |
| 47 '''Do a recursive file tree walk, adding files found to passed dict.''' |
| 48 for file in os.listdir(dir): |
| 49 # Skip "dot files". |
| 50 if file[0] == '.': |
| 51 continue |
| 52 path = dir + '/' + file |
| 53 if os.path.isdir(path): |
| 54 walk(path, paths) |
| 55 else: |
| 56 if dir not in paths: |
| 57 paths[dir] = [] |
| 58 paths[dir].append(path) |
| 59 |
| 60 def first_token(filename): |
| 61 '''Open file, read first line, parse & return first token to caller.''' |
| 62 token = None |
| 63 f = open(filename, 'r') |
| 64 line = f.readline().strip() |
| 65 tokens = line.split() |
| 66 token = tokens[0] |
| 67 f.close() |
| 68 return token |
| 69 |
| 70 # Validate python version. |
| 71 if sys.version_info <= (2, 6): |
| 72 error = 'ERROR: gsutil requires Python Version 2.6 or above...exiting.' |
| 73 exit(error) |
| 74 |
| 75 # Rather than hard-coding package contents here, we read the manifest |
| 76 # file to obtain the list of files and directories to include. |
| 77 files = [] |
| 78 dirs = [] |
| 79 parse_manifest(files, dirs) |
| 80 |
| 81 # Build list of data files dynamically. |
| 82 data_files = [(TARGET, files)] |
| 83 paths = {} |
| 84 for dir in dirs: |
| 85 walk(dir, paths) |
| 86 for path in paths: |
| 87 data_files += (os.path.join(TARGET, path), paths[path]), |
| 88 |
| 89 long_desc = ''' |
| 90 GSUtil is a Python application that lets you access Google Cloud Storage |
| 91 from the command line. You can use GSUtil to do a wide range of bucket and |
| 92 object management tasks, including: |
| 93 - Creating and deleting buckets. |
| 94 - Uploading, downloading, and deleting objects. |
| 95 - Listing buckets and objects. |
| 96 - Moving, copying, and renaming objects. |
| 97 - Setting object and bucket ACLs. |
| 98 ''' |
| 99 |
| 100 VERSION = first_token('VERSION') |
| 101 if not VERSION: |
| 102 error = 'ERROR: can\'t find gsutil version...exiting.' |
| 103 exit(error) |
| 104 |
| 105 # This is the main function call that installs the gsutil package. See |
| 106 # distutil documentation for details on this function and its arguments. |
| 107 setup(name = NAME, |
| 108 version = VERSION, |
| 109 license = 'Apache 2.0', |
| 110 author = 'Google', |
| 111 author_email = 'gs-team@google.com', |
| 112 url = 'http://code.google.com/apis/storage/docs/gsutil.html', |
| 113 description = 'gsutil - command line utility for Google Cloud Storage', |
| 114 long_description = long_desc, |
| 115 data_files = data_files, |
| 116 # Dependency on boto commented out for now because initially we plan to |
| 117 # bundle boto with this package, however, when we're ready to depend on |
| 118 # a separate boto rpm package, this line should be uncommented. |
| 119 #requires = ['boto (>=2.0)'], |
| 120 ) |
| 121 |
| 122 # Create symlink from /usr/bin/gsutil to /usr/share/gsutil/gsutil but |
| 123 # only run directly in enterprise mode (see README.pkg). When run by |
| 124 # rpmbuild we don't want to create this link because it's done by the |
| 125 # rpm spec file slightly differently (using a relative link). Same story |
| 126 # for permission setting, which is only needed if not run by rpmbuild. |
| 127 if not os.environ.get('RPM_BUILD_ROOT'): |
| 128 link = os.path.join(BINDIR, NAME) |
| 129 dest = os.path.join(TARGET, NAME) |
| 130 if not os.path.exists(link): |
| 131 os.symlink(dest, link) |
| 132 # Make all files and dirs in install area readable by other |
| 133 # and make all directories executable by other. These steps |
| 134 # are performed in support of the enterprise (shared/central) |
| 135 # installation mode, in which users with different user/group |
| 136 # than the installation user/group must be able to run gsutil. |
| 137 os.system('chmod -R o+r ' + TARGET) |
| 138 os.system('find ' + TARGET + ' -type d | xargs chmod o+x') |
| 139 # Make main gsutil script readable and executable by other. |
| 140 os.system('chmod o+rx ' + os.path.join(TARGET, NAME)) |
| 141 |
OLD | NEW |