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