annotate distribute_setup.py @ 39:8cc5970039f3 0.1.0

distribute is now used with distutils, added urwid requirement
author Goffi <goffi@goffi.org>
date Tue, 11 Jan 2011 15:32:14 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!python
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
2 """Bootstrap distribute installation
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
3
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
4 If you want to use setuptools in your package's setup.py, just include this
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
5 file in the same directory with it, and add this to the top of your setup.py::
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
6
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from distribute_setup import use_setuptools
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
8 use_setuptools()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
9
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
10 If you want to require a specific version of setuptools, set a download
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
11 mirror, or use an alternate download directory, you can do so by supplying
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
12 the appropriate options to ``use_setuptools()``.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
13
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
14 This file can also be run as a script to install or upgrade setuptools.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
15 """
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
16 import os
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
17 import sys
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
18 import time
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import fnmatch
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import tempfile
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import tarfile
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from distutils import log
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
23
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
24 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from site import USER_SITE
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
27 USER_SITE = None
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
28
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
29 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
30 import subprocess
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
31
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def _python_cmd(*args):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
33 args = (sys.executable,) + args
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
34 return subprocess.call(args) == 0
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
35
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
36 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
37 # will be used for python 2.3
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
38 def _python_cmd(*args):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
39 args = (sys.executable,) + args
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
40 # quoting arguments if windows
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
41 if sys.platform == 'win32':
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def quote(arg):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
43 if ' ' in arg:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
44 return '"%s"' % arg
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
45 return arg
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
46 args = [quote(arg) for arg in args]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
47 return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
48
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
49 DEFAULT_VERSION = "0.6.14"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
50 DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
51 SETUPTOOLS_FAKED_VERSION = "0.6c11"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
52
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
53 SETUPTOOLS_PKG_INFO = """\
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
54 Metadata-Version: 1.0
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
55 Name: setuptools
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
56 Version: %s
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
57 Summary: xxxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
58 Home-page: xxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
59 Author: xxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
60 Author-email: xxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
61 License: xxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
62 Description: xxx
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
63 """ % SETUPTOOLS_FAKED_VERSION
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
64
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
65
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def _install(tarball):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
67 # extracting the tarball
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
68 tmpdir = tempfile.mkdtemp()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
69 log.warn('Extracting in %s', tmpdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
70 old_wd = os.getcwd()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
71 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
72 os.chdir(tmpdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
73 tar = tarfile.open(tarball)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
74 _extractall(tar)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
75 tar.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
76
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
77 # going in the directory
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
78 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
79 os.chdir(subdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
80 log.warn('Now working in %s', subdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
81
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
82 # installing
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
83 log.warn('Installing Distribute')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
84 if not _python_cmd('setup.py', 'install'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
85 log.warn('Something went wrong during the installation.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
86 log.warn('See the error message above.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
87 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
88 os.chdir(old_wd)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
89
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
90
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def _build_egg(egg, tarball, to_dir):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
92 # extracting the tarball
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
93 tmpdir = tempfile.mkdtemp()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
94 log.warn('Extracting in %s', tmpdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
95 old_wd = os.getcwd()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
96 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
97 os.chdir(tmpdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
98 tar = tarfile.open(tarball)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
99 _extractall(tar)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
100 tar.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
101
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
102 # going in the directory
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
103 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
104 os.chdir(subdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
105 log.warn('Now working in %s', subdir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
106
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
107 # building an egg
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
108 log.warn('Building a Distribute egg in %s', to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
109 _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
110
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
111 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
112 os.chdir(old_wd)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
113 # returning the result
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
114 log.warn(egg)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
115 if not os.path.exists(egg):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
116 raise IOError('Could not build the egg.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
117
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
118
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def _do_download(version, download_base, to_dir, download_delay):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
120 egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
121 % (version, sys.version_info[0], sys.version_info[1]))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
122 if not os.path.exists(egg):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
123 tarball = download_setuptools(version, download_base,
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
124 to_dir, download_delay)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
125 _build_egg(egg, tarball, to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
126 sys.path.insert(0, egg)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
127 import setuptools
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
128 setuptools.bootstrap_install_from = egg
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
129
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
130
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
132 to_dir=os.curdir, download_delay=15, no_fake=True):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
133 # making sure we use the absolute path
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
134 to_dir = os.path.abspath(to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
135 was_imported = 'pkg_resources' in sys.modules or \
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
136 'setuptools' in sys.modules
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
137 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
138 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
139 import pkg_resources
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
140 if not hasattr(pkg_resources, '_distribute'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
141 if not no_fake:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
142 _fake_setuptools()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
143 raise ImportError
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
144 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
145 return _do_download(version, download_base, to_dir, download_delay)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
146 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
147 pkg_resources.require("distribute>="+version)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
149 except pkg_resources.VersionConflict:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
150 e = sys.exc_info()[1]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
151 if was_imported:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
152 sys.stderr.write(
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "The required version of distribute (>=%s) is not available,\n"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "and can't be installed while this script is running. Please\n"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
155 "install a more recent version first, using\n"
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
156 "'easy_install -U distribute'."
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
157 "\n\n(Currently using %r)\n" % (version, e.args[0]))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
158 sys.exit(2)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
159 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
160 del pkg_resources, sys.modules['pkg_resources'] # reload ok
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
161 return _do_download(version, download_base, to_dir,
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
162 download_delay)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
163 except pkg_resources.DistributionNotFound:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
164 return _do_download(version, download_base, to_dir,
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
165 download_delay)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
166 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
167 if not no_fake:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
168 _create_fake_setuptools_pkg_info(to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
169
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
170 def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
171 to_dir=os.curdir, delay=15):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
172 """Download distribute from a specified location and return its filename
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
173
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
174 `version` should be a valid distribute version number that is available
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
175 as an egg for download under the `download_base` URL (which should end
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
176 with a '/'). `to_dir` is the directory where the egg will be downloaded.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
177 `delay` is the number of seconds to pause before an actual download
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
178 attempt.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
179 """
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
180 # making sure we use the absolute path
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
181 to_dir = os.path.abspath(to_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
182 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
183 from urllib.request import urlopen
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
184 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
185 from urllib2 import urlopen
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
186 tgz_name = "distribute-%s.tar.gz" % version
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
187 url = download_base + tgz_name
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
188 saveto = os.path.join(to_dir, tgz_name)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
189 src = dst = None
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
190 if not os.path.exists(saveto): # Avoid repeated downloads
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
191 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
192 log.warn("Downloading %s", url)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
193 src = urlopen(url)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
194 # Read/write all in one block, so we don't create a corrupt file
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
195 # if the download is interrupted.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
196 data = src.read()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
197 dst = open(saveto, "wb")
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
198 dst.write(data)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
199 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if src:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
201 src.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
202 if dst:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
203 dst.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
204 return os.path.realpath(saveto)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
205
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
206 def _no_sandbox(function):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
207 def __no_sandbox(*args, **kw):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
208 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
209 from setuptools.sandbox import DirectorySandbox
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
210 if not hasattr(DirectorySandbox, '_old'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
211 def violation(*args):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
212 pass
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
213 DirectorySandbox._old = DirectorySandbox._violation
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
214 DirectorySandbox._violation = violation
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
215 patched = True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
216 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
217 patched = False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
218 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
219 patched = False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
220
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
221 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
222 return function(*args, **kw)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
223 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
224 if patched:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
225 DirectorySandbox._violation = DirectorySandbox._old
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
226 del DirectorySandbox._old
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
227
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
228 return __no_sandbox
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
229
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def _patch_file(path, content):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
231 """Will backup the file then patch it"""
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
232 existing_content = open(path).read()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
233 if existing_content == content:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
234 # already patched
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
235 log.warn('Already patched.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
236 return False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
237 log.warn('Patching...')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
238 _rename_path(path)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
239 f = open(path, 'w')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
240 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
241 f.write(content)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
242 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
243 f.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
244 return True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
245
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
246 _patch_file = _no_sandbox(_patch_file)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
247
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
248 def _same_content(path, content):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
249 return open(path).read() == content
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
250
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
251 def _rename_path(path):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
252 new_name = path + '.OLD.%s' % time.time()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
253 log.warn('Renaming %s into %s', path, new_name)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
254 os.rename(path, new_name)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
255 return new_name
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
256
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
257 def _remove_flat_installation(placeholder):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
258 if not os.path.isdir(placeholder):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
259 log.warn('Unkown installation at %s', placeholder)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
260 return False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
261 found = False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
262 for file in os.listdir(placeholder):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
263 if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
264 found = True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
265 break
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
266 if not found:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
267 log.warn('Could not locate setuptools*.egg-info')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
268 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
269
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
270 log.warn('Removing elements out of the way...')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
271 pkg_info = os.path.join(placeholder, file)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
272 if os.path.isdir(pkg_info):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
273 patched = _patch_egg_dir(pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
274 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
275 patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
276
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
277 if not patched:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
278 log.warn('%s already patched.', pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
279 return False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
280 # now let's move the files out of the way
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
281 for element in ('setuptools', 'pkg_resources.py', 'site.py'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
282 element = os.path.join(placeholder, element)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
283 if os.path.exists(element):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
284 _rename_path(element)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
285 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
286 log.warn('Could not find the %s element of the '
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
287 'Setuptools distribution', element)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
288 return True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
289
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
290 _remove_flat_installation = _no_sandbox(_remove_flat_installation)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
291
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
292 def _after_install(dist):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
293 log.warn('After install bootstrap.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
294 placeholder = dist.get_command_obj('install').install_purelib
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
295 _create_fake_setuptools_pkg_info(placeholder)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
296
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
297 def _create_fake_setuptools_pkg_info(placeholder):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
298 if not placeholder or not os.path.exists(placeholder):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
299 log.warn('Could not find the install location')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
300 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
301 pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
302 setuptools_file = 'setuptools-%s-py%s.egg-info' % \
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
303 (SETUPTOOLS_FAKED_VERSION, pyver)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
304 pkg_info = os.path.join(placeholder, setuptools_file)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
305 if os.path.exists(pkg_info):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
306 log.warn('%s already exists', pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
307 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
308
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
309 log.warn('Creating %s', pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
310 f = open(pkg_info, 'w')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
311 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
312 f.write(SETUPTOOLS_PKG_INFO)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
313 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
314 f.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
315
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
316 pth_file = os.path.join(placeholder, 'setuptools.pth')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
317 log.warn('Creating %s', pth_file)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
318 f = open(pth_file, 'w')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
319 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
320 f.write(os.path.join(os.curdir, setuptools_file))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
321 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
322 f.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
323
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
324 _create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
325
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
326 def _patch_egg_dir(path):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
327 # let's check if it's already patched
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
328 pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
329 if os.path.exists(pkg_info):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
330 if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
331 log.warn('%s already patched.', pkg_info)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
332 return False
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
333 _rename_path(path)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
334 os.mkdir(path)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
335 os.mkdir(os.path.join(path, 'EGG-INFO'))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
336 pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
337 f = open(pkg_info, 'w')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
338 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
339 f.write(SETUPTOOLS_PKG_INFO)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
340 finally:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
341 f.close()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
342 return True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
343
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
344 _patch_egg_dir = _no_sandbox(_patch_egg_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
345
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
346 def _before_install():
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
347 log.warn('Before install bootstrap.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
348 _fake_setuptools()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
349
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
350
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
351 def _under_prefix(location):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
352 if 'install' not in sys.argv:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
353 return True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
354 args = sys.argv[sys.argv.index('install')+1:]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
355 for index, arg in enumerate(args):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
356 for option in ('--root', '--prefix'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
357 if arg.startswith('%s=' % option):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
358 top_dir = arg.split('root=')[-1]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
359 return location.startswith(top_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
360 elif arg == option:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
361 if len(args) > index:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
362 top_dir = args[index+1]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
363 return location.startswith(top_dir)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
364 if arg == '--user' and USER_SITE is not None:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
365 return location.startswith(USER_SITE)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
366 return True
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
367
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
368
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
369 def _fake_setuptools():
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
370 log.warn('Scanning installed packages')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
371 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
372 import pkg_resources
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
373 except ImportError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
374 # we're cool
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
375 log.warn('Setuptools or Distribute does not seem to be installed.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
376 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
377 ws = pkg_resources.working_set
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
378 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
379 setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
380 replacement=False))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
381 except TypeError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
382 # old distribute API
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
383 setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
384
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
385 if setuptools_dist is None:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
386 log.warn('No setuptools distribution found')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
387 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
388 # detecting if it was already faked
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
389 setuptools_location = setuptools_dist.location
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
390 log.warn('Setuptools installation detected at %s', setuptools_location)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
391
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
392 # if --root or --preix was provided, and if
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
393 # setuptools is not located in them, we don't patch it
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
394 if not _under_prefix(setuptools_location):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
395 log.warn('Not patching, --root or --prefix is installing Distribute'
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
396 ' in another location')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
397 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
398
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
399 # let's see if its an egg
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
400 if not setuptools_location.endswith('.egg'):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
401 log.warn('Non-egg installation')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
402 res = _remove_flat_installation(setuptools_location)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
403 if not res:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
404 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
405 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
406 log.warn('Egg installation')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
407 pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
408 if (os.path.exists(pkg_info) and
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
409 _same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
410 log.warn('Already patched.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
411 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
412 log.warn('Patching...')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
413 # let's create a fake egg replacing setuptools one
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
414 res = _patch_egg_dir(setuptools_location)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
415 if not res:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
416 return
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
417 log.warn('Patched done.')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
418 _relaunch()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
419
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
420
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
421 def _relaunch():
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
422 log.warn('Relaunching...')
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
423 # we have to relaunch the process
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
424 # pip marker to avoid a relaunch bug
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
425 if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
426 sys.argv[0] = 'setup.py'
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
427 args = [sys.executable] + sys.argv
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
428 sys.exit(subprocess.call(args))
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
429
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
430
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
431 def _extractall(self, path=".", members=None):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
432 """Extract all members from the archive to the current working
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
433 directory and set owner, modification time and permissions on
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
434 directories afterwards. `path' specifies a different directory
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
435 to extract to. `members' is optional and must be a subset of the
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
436 list returned by getmembers().
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
437 """
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
438 import copy
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
439 import operator
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
440 from tarfile import ExtractError
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
441 directories = []
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
442
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
443 if members is None:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
444 members = self
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
445
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
446 for tarinfo in members:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
447 if tarinfo.isdir():
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
448 # Extract directories with a safe mode.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
449 directories.append(tarinfo)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
450 tarinfo = copy.copy(tarinfo)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
451 tarinfo.mode = 448 # decimal for oct 0700
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
452 self.extract(tarinfo, path)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
453
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
454 # Reverse sort directories.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
455 if sys.version_info < (2, 4):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
456 def sorter(dir1, dir2):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
457 return cmp(dir1.name, dir2.name)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
458 directories.sort(sorter)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
459 directories.reverse()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
460 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
461 directories.sort(key=operator.attrgetter('name'), reverse=True)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
462
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
463 # Set correct owner, mtime and filemode on directories.
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
464 for tarinfo in directories:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
465 dirpath = os.path.join(path, tarinfo.name)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
466 try:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
467 self.chown(tarinfo, dirpath)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
468 self.utime(tarinfo, dirpath)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
469 self.chmod(tarinfo, dirpath)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
470 except ExtractError:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
471 e = sys.exc_info()[1]
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
472 if self.errorlevel > 1:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
473 raise
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
474 else:
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
475 self._dbg(1, "tarfile: %s" % e)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
476
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
477
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
478 def main(argv, version=DEFAULT_VERSION):
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
479 """Install or upgrade setuptools and EasyInstall"""
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
480 tarball = download_setuptools()
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
481 _install(tarball)
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
482
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
483
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
484 if __name__ == '__main__':
8cc5970039f3 distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff changeset
485 main(sys.argv[1:])