Mercurial > urwid-satext
annotate ez_setup.py @ 133:acd6d4ec072b
Added tag 0.7.0a1 for changeset 406c310e52b5
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Jul 2018 18:14:13 +0200 |
parents | 20be00928875 |
children |
rev | line source |
---|---|
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
1 #!/usr/bin/env python |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
2 """Bootstrap setuptools installation |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
4 To use setuptools in your package's setup.py, include this |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
5 file in the same directory and add this to the top of your setup.py:: |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
7 from ez_setup import use_setuptools |
39
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 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
10 To require a specific version of setuptools, set a download |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
11 mirror, or use an alternate download directory, simply supply |
39
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 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
17 import shutil |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 import sys |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import tempfile |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
20 import zipfile |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
21 import optparse |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
22 import subprocess |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
23 import platform |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
24 import textwrap |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
25 import contextlib |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
26 |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from distutils import log |
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: |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
30 from urllib.request import urlopen |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
31 except ImportError: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
32 from urllib2 import urlopen |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
33 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
34 try: |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from site import USER_SITE |
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 USER_SITE = None |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
105
20be00928875
Lower default setuptools version
Matteo Cypriani <mcy@lm7.fr>
parents:
83
diff
changeset
|
39 DEFAULT_VERSION = "5.5" |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
40 DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
42 def _python_cmd(*args): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
43 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
44 Return True if the command succeeded. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
45 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
46 args = (sys.executable,) + args |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
47 return subprocess.call(args) == 0 |
39
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 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
50 def _install(archive_filename, install_args=()): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
51 with archive_context(archive_filename): |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 # installing |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
53 log.warn('Installing Setuptools') |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
54 if not _python_cmd('setup.py', 'install', *install_args): |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 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
|
56 log.warn('See the error message above.') |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
57 # exitcode will be 2 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
58 return 2 |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
61 def _build_egg(egg, archive_filename, to_dir): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
62 with archive_context(archive_filename): |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 # building an egg |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
64 log.warn('Building a Setuptools egg in %s', to_dir) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 _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
|
66 # returning the result |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 log.warn(egg) |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 if not os.path.exists(egg): |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 raise IOError('Could not build the egg.') |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
72 class ContextualZipFile(zipfile.ZipFile): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
73 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
74 Supplement ZipFile class to support context manager for Python 2.6 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
75 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
76 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
77 def __enter__(self): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
78 return self |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
79 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
80 def __exit__(self, type, value, traceback): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
81 self.close() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
82 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
83 def __new__(cls, *args, **kwargs): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
84 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
85 Construct a ZipFile or ContextualZipFile as appropriate |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
86 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
87 if hasattr(zipfile.ZipFile, '__exit__'): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
88 return zipfile.ZipFile(*args, **kwargs) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
89 return super(ContextualZipFile, cls).__new__(cls) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
90 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
91 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
92 @contextlib.contextmanager |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
93 def archive_context(filename): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
94 # extracting the archive |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
95 tmpdir = tempfile.mkdtemp() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
96 log.warn('Extracting in %s', tmpdir) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
97 old_wd = os.getcwd() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
98 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
99 os.chdir(tmpdir) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
100 with ContextualZipFile(filename) as archive: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
101 archive.extractall() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
102 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
103 # going in the directory |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
104 subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
105 os.chdir(subdir) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
106 log.warn('Now working in %s', subdir) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
107 yield |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
108 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
109 finally: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
110 os.chdir(old_wd) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
111 shutil.rmtree(tmpdir) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
112 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
113 |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 def _do_download(version, download_base, to_dir, download_delay): |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
115 egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg' |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 % (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
|
117 if not os.path.exists(egg): |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
118 archive = download_setuptools(version, download_base, |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 to_dir, download_delay) |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
120 _build_egg(egg, archive, to_dir) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 sys.path.insert(0, egg) |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
122 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
123 # Remove previously-imported pkg_resources if present (see |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
124 # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details). |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
125 if 'pkg_resources' in sys.modules: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
126 del sys.modules['pkg_resources'] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
127 |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 import setuptools |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 setuptools.bootstrap_install_from = egg |
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 |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
133 to_dir=os.curdir, download_delay=15): |
39
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) |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
135 rep_modules = 'pkg_resources', 'setuptools' |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
136 imported = set(sys.modules).intersection(rep_modules) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
137 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
138 import pkg_resources |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
139 except ImportError: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
140 return _do_download(version, download_base, to_dir, download_delay) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 try: |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
142 pkg_resources.require("setuptools>=" + version) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
143 return |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
144 except pkg_resources.DistributionNotFound: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
145 return _do_download(version, download_base, to_dir, download_delay) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
146 except pkg_resources.VersionConflict as VC_err: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
147 if imported: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
148 msg = textwrap.dedent(""" |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
149 The required version of setuptools (>={version}) is not available, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
150 and can't be installed while this script is running. Please |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
151 install a more recent version first, using |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
152 'easy_install -U setuptools'. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
153 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
154 (Currently using {VC_err.args[0]!r}) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
155 """).format(VC_err=VC_err, version=version) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
156 sys.stderr.write(msg) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
157 sys.exit(2) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
158 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
159 # otherwise, reload ok |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
160 del pkg_resources, sys.modules['pkg_resources'] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
161 return _do_download(version, download_base, to_dir, download_delay) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
162 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
163 def _clean_check(cmd, target): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
164 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
165 Run the command to download target. If the command fails, clean up before |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
166 re-raising the error. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
167 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
168 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
169 subprocess.check_call(cmd) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
170 except subprocess.CalledProcessError: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
171 if os.access(target, os.F_OK): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
172 os.unlink(target) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
173 raise |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
174 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
175 def download_file_powershell(url, target): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
176 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
177 Download the file at url to target using Powershell (which will validate |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
178 trust). Raise an exception if the command cannot complete. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
179 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
180 target = os.path.abspath(target) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
181 ps_cmd = ( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
182 "[System.Net.WebRequest]::DefaultWebProxy.Credentials = " |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
183 "[System.Net.CredentialCache]::DefaultCredentials; " |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
184 "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
185 % vars() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
186 ) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
187 cmd = [ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
188 'powershell', |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
189 '-Command', |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
190 ps_cmd, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
191 ] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
192 _clean_check(cmd, target) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
193 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
194 def has_powershell(): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
195 if platform.system() != 'Windows': |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
196 return False |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
197 cmd = ['powershell', '-Command', 'echo test'] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
198 with open(os.path.devnull, 'wb') as devnull: |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 try: |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
200 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
201 except Exception: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
202 return False |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
203 return True |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
204 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
205 download_file_powershell.viable = has_powershell |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
206 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
207 def download_file_curl(url, target): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
208 cmd = ['curl', url, '--silent', '--output', target] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
209 _clean_check(cmd, target) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
210 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
211 def has_curl(): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
212 cmd = ['curl', '--version'] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
213 with open(os.path.devnull, 'wb') as devnull: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
214 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
215 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
216 except Exception: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
217 return False |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
218 return True |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
219 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
220 download_file_curl.viable = has_curl |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
221 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
222 def download_file_wget(url, target): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
223 cmd = ['wget', url, '--quiet', '--output-document', target] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
224 _clean_check(cmd, target) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
225 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
226 def has_wget(): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
227 cmd = ['wget', '--version'] |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
228 with open(os.path.devnull, 'wb') as devnull: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
229 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
230 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
231 except Exception: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
232 return False |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
233 return True |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
234 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
235 download_file_wget.viable = has_wget |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
236 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
237 def download_file_insecure(url, target): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
238 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
239 Use Python to download the file, even though it cannot authenticate the |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
240 connection. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
241 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
242 src = urlopen(url) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
243 try: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
244 # Read all the data in one block. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
245 data = src.read() |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 finally: |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
247 src.close() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
248 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
249 # Write all the data in one block to avoid creating a partial file. |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
250 with open(target, "wb") as dst: |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
251 dst.write(data) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
252 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
253 download_file_insecure.viable = lambda: True |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
254 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
255 def get_best_downloader(): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
256 downloaders = ( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
257 download_file_powershell, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
258 download_file_curl, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
259 download_file_wget, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
260 download_file_insecure, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
261 ) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
262 viable_downloaders = (dl for dl in downloaders if dl.viable()) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
263 return next(viable_downloaders, None) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
266 to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
267 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
268 Download setuptools from a specified location and return its filename |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
270 `version` should be a valid setuptools version number that is available |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
271 as an sdist for download under the `download_base` URL (which should end |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 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
|
273 `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
|
274 attempt. |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
275 |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
276 ``downloader_factory`` should be a function taking no arguments and |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
277 returning a function for downloading a URL to a target. |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 """ |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 # making sure we use the absolute path |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 to_dir = os.path.abspath(to_dir) |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
281 zip_name = "setuptools-%s.zip" % version |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
282 url = download_base + zip_name |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
283 saveto = os.path.join(to_dir, zip_name) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 if not os.path.exists(saveto): # Avoid repeated downloads |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
285 log.warn("Downloading %s", url) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
286 downloader = downloader_factory() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
287 downloader(url, saveto) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 return os.path.realpath(saveto) |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
290 def _build_install_args(options): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
291 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
292 Build the arguments to 'python setup.py install' on the setuptools package |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
293 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
294 return ['--user'] if options.user_install else [] |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
296 def _parse_args(): |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
297 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
298 Parse the command line for options |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
299 """ |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
300 parser = optparse.OptionParser() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
301 parser.add_option( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
302 '--user', dest='user_install', action='store_true', default=False, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
303 help='install in user site package (requires Python 2.6 or later)') |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
304 parser.add_option( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
305 '--download-base', dest='download_base', metavar="URL", |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
306 default=DEFAULT_URL, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
307 help='alternative URL from where to download the setuptools package') |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
308 parser.add_option( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
309 '--insecure', dest='downloader_factory', action='store_const', |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
310 const=lambda: download_file_insecure, default=get_best_downloader, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
311 help='Use internal, non-validating downloader' |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
312 ) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
313 parser.add_option( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
314 '--version', help="Specify which version to download", |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
315 default=DEFAULT_VERSION, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
316 ) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
317 options, args = parser.parse_args() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
318 # positional arguments are ignored |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
319 return options |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
321 def main(): |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 """Install or upgrade setuptools and EasyInstall""" |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
323 options = _parse_args() |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
324 archive = download_setuptools( |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
325 version=options.version, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
326 download_base=options.download_base, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
327 downloader_factory=options.downloader_factory, |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
328 ) |
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
329 return _install(archive, _build_install_args(options)) |
39
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 |
8cc5970039f3
distribute is now used with distutils, added urwid requirement
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 if __name__ == '__main__': |
83
12b5b1435e17
updated old distribute_setup.py to new setuptools' ez_setup.py
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
332 sys.exit(main()) |