[r5025]: projects / tgsetupng / trunk / create-tgsetupng.py Maximize Restore History

Download this file

create-tgsetupng.py    95 lines (79 with data), 3.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""Create a virtualenv bootstrap script for TurboGears.
See http://pypi.python.org/pypi/virtualenv for more information.
"""
__program__ = "create-tgsetupng.py"
__author__ = "Christopher Arndt"
__version__ = "1.0b"
__revision__ = "$Rev:$"
__date__ = "$Date:$"
__copyright__ = "MIT license"
import os
import sys
import textwrap
import virtualenv
defaults = dict(
package_index = 'http://pypi.turbogears.org'
)
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
def extend_parser(parser):
parser.usage = ("Usage: %%prog [OPTIONS] DEST_DIR [VERSION]\\n\\n"
"Installs the TurboGears framework in a virtual environment in DESTDIR."
"\\n\\nSpecify a particular version to install with VERSION.")
parser.remove_option('--no-site-packages')
parser.add_option('--with-site-packages',
dest='no_site_packages',
action='store_false',
help="Give access to the global site-packages dir to the "
"virtual environment")
parser.add_option('-i', '--package-index', dest='package_index',
metavar="URL", default='%(package_index)s',
help="Find & download packages from package index at URL"
" (default: %(package_index)s)")
parser.add_option('-a', '--allow-other-hosts', dest='other_hosts',
action='store_true',
help="Allow package downloads from third-party servers"
" (default: only allow download from package index)")
def adjust_options(options, args):
if len(args) > 1:
options.tg_version = args.pop()
def after_install(options, home_dir):
try:
install_spec = 'TurboGears==%%s' %% options.tg_version
except AttributeError:
install_spec = 'TurboGears'
if sys.platform.startswith('win'):
scriptdir = 'Scripts'
else:
scriptdir = 'bin'
# Install TurboGears
if options.other_hosts:
rc = subprocess.call([join(home_dir, scriptdir, 'easy_install'),
'-i', options.package_index, install_spec])
else:
import urlparse
host = urlparse.urlparse(options.package_index)[1]
rc = subprocess.call([join(home_dir, scriptdir, 'easy_install'),
'-i', options.package_index, '-H', host, install_spec])
# run 'tg-admin info'
if rc == 0:
rc = subprocess.call([join(home_dir, scriptdir, 'tg-admin'), 'info'])
print "-" * 75
print "TurboGears installation successful."
print "Please see the output above for version information."
if rc != 0:
print "!" * 75
print ("Installation failed. Please check output above for "
"error messages.")
print "If you're stuck, visit http://docs.turbogears.org/GettingHelp"
""" % defaults))
try:
scriptname = sys.argv[1]
except IndexError:
scriptname = 'tgsetupng.py'
print ("Writing TurboGears 1.x installation script to '%s'." %
scriptname)
f = open(scriptname, 'w').write(output)
try:
os.chmod(scriptname, 0755)
except: pass