annotate ez_setup.py @ 1316:8adcdf2cdfe1 frontends_multi_profiles

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