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