python/virtualenv/virtualenv.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #!/usr/bin/env python
michael@0 2 """Create a "virtual" Python installation
michael@0 3 """
michael@0 4
michael@0 5 __version__ = "1.11.4"
michael@0 6 virtualenv_version = __version__ # legacy
michael@0 7
michael@0 8 import base64
michael@0 9 import sys
michael@0 10 import os
michael@0 11 import codecs
michael@0 12 import optparse
michael@0 13 import re
michael@0 14 import shutil
michael@0 15 import logging
michael@0 16 import tempfile
michael@0 17 import zlib
michael@0 18 import errno
michael@0 19 import glob
michael@0 20 import distutils.sysconfig
michael@0 21 from distutils.util import strtobool
michael@0 22 import struct
michael@0 23 import subprocess
michael@0 24 import tarfile
michael@0 25
michael@0 26 if sys.version_info < (2, 6):
michael@0 27 print('ERROR: %s' % sys.exc_info()[1])
michael@0 28 print('ERROR: this script requires Python 2.6 or greater.')
michael@0 29 sys.exit(101)
michael@0 30
michael@0 31 try:
michael@0 32 set
michael@0 33 except NameError:
michael@0 34 from sets import Set as set
michael@0 35 try:
michael@0 36 basestring
michael@0 37 except NameError:
michael@0 38 basestring = str
michael@0 39
michael@0 40 try:
michael@0 41 import ConfigParser
michael@0 42 except ImportError:
michael@0 43 import configparser as ConfigParser
michael@0 44
michael@0 45 join = os.path.join
michael@0 46 py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
michael@0 47
michael@0 48 is_jython = sys.platform.startswith('java')
michael@0 49 is_pypy = hasattr(sys, 'pypy_version_info')
michael@0 50 is_win = (sys.platform == 'win32')
michael@0 51 is_cygwin = (sys.platform == 'cygwin')
michael@0 52 is_darwin = (sys.platform == 'darwin')
michael@0 53 abiflags = getattr(sys, 'abiflags', '')
michael@0 54
michael@0 55 user_dir = os.path.expanduser('~')
michael@0 56 if is_win:
michael@0 57 default_storage_dir = os.path.join(user_dir, 'virtualenv')
michael@0 58 else:
michael@0 59 default_storage_dir = os.path.join(user_dir, '.virtualenv')
michael@0 60 default_config_file = os.path.join(default_storage_dir, 'virtualenv.ini')
michael@0 61
michael@0 62 if is_pypy:
michael@0 63 expected_exe = 'pypy'
michael@0 64 elif is_jython:
michael@0 65 expected_exe = 'jython'
michael@0 66 else:
michael@0 67 expected_exe = 'python'
michael@0 68
michael@0 69 # Return a mapping of version -> Python executable
michael@0 70 # Only provided for Windows, where the information in the registry is used
michael@0 71 if not is_win:
michael@0 72 def get_installed_pythons():
michael@0 73 return {}
michael@0 74 else:
michael@0 75 try:
michael@0 76 import winreg
michael@0 77 except ImportError:
michael@0 78 import _winreg as winreg
michael@0 79
michael@0 80 def get_installed_pythons():
michael@0 81 python_core = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE,
michael@0 82 "Software\\Python\\PythonCore")
michael@0 83 i = 0
michael@0 84 versions = []
michael@0 85 while True:
michael@0 86 try:
michael@0 87 versions.append(winreg.EnumKey(python_core, i))
michael@0 88 i = i + 1
michael@0 89 except WindowsError:
michael@0 90 break
michael@0 91 exes = dict()
michael@0 92 for ver in versions:
michael@0 93 path = winreg.QueryValue(python_core, "%s\\InstallPath" % ver)
michael@0 94 exes[ver] = join(path, "python.exe")
michael@0 95
michael@0 96 winreg.CloseKey(python_core)
michael@0 97
michael@0 98 # Add the major versions
michael@0 99 # Sort the keys, then repeatedly update the major version entry
michael@0 100 # Last executable (i.e., highest version) wins with this approach
michael@0 101 for ver in sorted(exes):
michael@0 102 exes[ver[0]] = exes[ver]
michael@0 103
michael@0 104 return exes
michael@0 105
michael@0 106 REQUIRED_MODULES = ['os', 'posix', 'posixpath', 'nt', 'ntpath', 'genericpath',
michael@0 107 'fnmatch', 'locale', 'encodings', 'codecs',
michael@0 108 'stat', 'UserDict', 'readline', 'copy_reg', 'types',
michael@0 109 're', 'sre', 'sre_parse', 'sre_constants', 'sre_compile',
michael@0 110 'zlib']
michael@0 111
michael@0 112 REQUIRED_FILES = ['lib-dynload', 'config']
michael@0 113
michael@0 114 majver, minver = sys.version_info[:2]
michael@0 115 if majver == 2:
michael@0 116 if minver >= 6:
michael@0 117 REQUIRED_MODULES.extend(['warnings', 'linecache', '_abcoll', 'abc'])
michael@0 118 if minver >= 7:
michael@0 119 REQUIRED_MODULES.extend(['_weakrefset'])
michael@0 120 if minver <= 3:
michael@0 121 REQUIRED_MODULES.extend(['sets', '__future__'])
michael@0 122 elif majver == 3:
michael@0 123 # Some extra modules are needed for Python 3, but different ones
michael@0 124 # for different versions.
michael@0 125 REQUIRED_MODULES.extend(['_abcoll', 'warnings', 'linecache', 'abc', 'io',
michael@0 126 '_weakrefset', 'copyreg', 'tempfile', 'random',
michael@0 127 '__future__', 'collections', 'keyword', 'tarfile',
michael@0 128 'shutil', 'struct', 'copy', 'tokenize', 'token',
michael@0 129 'functools', 'heapq', 'bisect', 'weakref',
michael@0 130 'reprlib'])
michael@0 131 if minver >= 2:
michael@0 132 REQUIRED_FILES[-1] = 'config-%s' % majver
michael@0 133 if minver >= 3:
michael@0 134 import sysconfig
michael@0 135 platdir = sysconfig.get_config_var('PLATDIR')
michael@0 136 REQUIRED_FILES.append(platdir)
michael@0 137 # The whole list of 3.3 modules is reproduced below - the current
michael@0 138 # uncommented ones are required for 3.3 as of now, but more may be
michael@0 139 # added as 3.3 development continues.
michael@0 140 REQUIRED_MODULES.extend([
michael@0 141 #"aifc",
michael@0 142 #"antigravity",
michael@0 143 #"argparse",
michael@0 144 #"ast",
michael@0 145 #"asynchat",
michael@0 146 #"asyncore",
michael@0 147 "base64",
michael@0 148 #"bdb",
michael@0 149 #"binhex",
michael@0 150 #"bisect",
michael@0 151 #"calendar",
michael@0 152 #"cgi",
michael@0 153 #"cgitb",
michael@0 154 #"chunk",
michael@0 155 #"cmd",
michael@0 156 #"codeop",
michael@0 157 #"code",
michael@0 158 #"colorsys",
michael@0 159 #"_compat_pickle",
michael@0 160 #"compileall",
michael@0 161 #"concurrent",
michael@0 162 #"configparser",
michael@0 163 #"contextlib",
michael@0 164 #"cProfile",
michael@0 165 #"crypt",
michael@0 166 #"csv",
michael@0 167 #"ctypes",
michael@0 168 #"curses",
michael@0 169 #"datetime",
michael@0 170 #"dbm",
michael@0 171 #"decimal",
michael@0 172 #"difflib",
michael@0 173 #"dis",
michael@0 174 #"doctest",
michael@0 175 #"dummy_threading",
michael@0 176 "_dummy_thread",
michael@0 177 #"email",
michael@0 178 #"filecmp",
michael@0 179 #"fileinput",
michael@0 180 #"formatter",
michael@0 181 #"fractions",
michael@0 182 #"ftplib",
michael@0 183 #"functools",
michael@0 184 #"getopt",
michael@0 185 #"getpass",
michael@0 186 #"gettext",
michael@0 187 #"glob",
michael@0 188 #"gzip",
michael@0 189 "hashlib",
michael@0 190 #"heapq",
michael@0 191 "hmac",
michael@0 192 #"html",
michael@0 193 #"http",
michael@0 194 #"idlelib",
michael@0 195 #"imaplib",
michael@0 196 #"imghdr",
michael@0 197 "imp",
michael@0 198 "importlib",
michael@0 199 #"inspect",
michael@0 200 #"json",
michael@0 201 #"lib2to3",
michael@0 202 #"logging",
michael@0 203 #"macpath",
michael@0 204 #"macurl2path",
michael@0 205 #"mailbox",
michael@0 206 #"mailcap",
michael@0 207 #"_markupbase",
michael@0 208 #"mimetypes",
michael@0 209 #"modulefinder",
michael@0 210 #"multiprocessing",
michael@0 211 #"netrc",
michael@0 212 #"nntplib",
michael@0 213 #"nturl2path",
michael@0 214 #"numbers",
michael@0 215 #"opcode",
michael@0 216 #"optparse",
michael@0 217 #"os2emxpath",
michael@0 218 #"pdb",
michael@0 219 #"pickle",
michael@0 220 #"pickletools",
michael@0 221 #"pipes",
michael@0 222 #"pkgutil",
michael@0 223 #"platform",
michael@0 224 #"plat-linux2",
michael@0 225 #"plistlib",
michael@0 226 #"poplib",
michael@0 227 #"pprint",
michael@0 228 #"profile",
michael@0 229 #"pstats",
michael@0 230 #"pty",
michael@0 231 #"pyclbr",
michael@0 232 #"py_compile",
michael@0 233 #"pydoc_data",
michael@0 234 #"pydoc",
michael@0 235 #"_pyio",
michael@0 236 #"queue",
michael@0 237 #"quopri",
michael@0 238 #"reprlib",
michael@0 239 "rlcompleter",
michael@0 240 #"runpy",
michael@0 241 #"sched",
michael@0 242 #"shelve",
michael@0 243 #"shlex",
michael@0 244 #"smtpd",
michael@0 245 #"smtplib",
michael@0 246 #"sndhdr",
michael@0 247 #"socket",
michael@0 248 #"socketserver",
michael@0 249 #"sqlite3",
michael@0 250 #"ssl",
michael@0 251 #"stringprep",
michael@0 252 #"string",
michael@0 253 #"_strptime",
michael@0 254 #"subprocess",
michael@0 255 #"sunau",
michael@0 256 #"symbol",
michael@0 257 #"symtable",
michael@0 258 #"sysconfig",
michael@0 259 #"tabnanny",
michael@0 260 #"telnetlib",
michael@0 261 #"test",
michael@0 262 #"textwrap",
michael@0 263 #"this",
michael@0 264 #"_threading_local",
michael@0 265 #"threading",
michael@0 266 #"timeit",
michael@0 267 #"tkinter",
michael@0 268 #"tokenize",
michael@0 269 #"token",
michael@0 270 #"traceback",
michael@0 271 #"trace",
michael@0 272 #"tty",
michael@0 273 #"turtledemo",
michael@0 274 #"turtle",
michael@0 275 #"unittest",
michael@0 276 #"urllib",
michael@0 277 #"uuid",
michael@0 278 #"uu",
michael@0 279 #"wave",
michael@0 280 #"weakref",
michael@0 281 #"webbrowser",
michael@0 282 #"wsgiref",
michael@0 283 #"xdrlib",
michael@0 284 #"xml",
michael@0 285 #"xmlrpc",
michael@0 286 #"zipfile",
michael@0 287 ])
michael@0 288 if minver >= 4:
michael@0 289 REQUIRED_MODULES.extend([
michael@0 290 'operator',
michael@0 291 '_collections_abc',
michael@0 292 '_bootlocale',
michael@0 293 ])
michael@0 294
michael@0 295 if is_pypy:
michael@0 296 # these are needed to correctly display the exceptions that may happen
michael@0 297 # during the bootstrap
michael@0 298 REQUIRED_MODULES.extend(['traceback', 'linecache'])
michael@0 299
michael@0 300 class Logger(object):
michael@0 301
michael@0 302 """
michael@0 303 Logging object for use in command-line script. Allows ranges of
michael@0 304 levels, to avoid some redundancy of displayed information.
michael@0 305 """
michael@0 306
michael@0 307 DEBUG = logging.DEBUG
michael@0 308 INFO = logging.INFO
michael@0 309 NOTIFY = (logging.INFO+logging.WARN)/2
michael@0 310 WARN = WARNING = logging.WARN
michael@0 311 ERROR = logging.ERROR
michael@0 312 FATAL = logging.FATAL
michael@0 313
michael@0 314 LEVELS = [DEBUG, INFO, NOTIFY, WARN, ERROR, FATAL]
michael@0 315
michael@0 316 def __init__(self, consumers):
michael@0 317 self.consumers = consumers
michael@0 318 self.indent = 0
michael@0 319 self.in_progress = None
michael@0 320 self.in_progress_hanging = False
michael@0 321
michael@0 322 def debug(self, msg, *args, **kw):
michael@0 323 self.log(self.DEBUG, msg, *args, **kw)
michael@0 324 def info(self, msg, *args, **kw):
michael@0 325 self.log(self.INFO, msg, *args, **kw)
michael@0 326 def notify(self, msg, *args, **kw):
michael@0 327 self.log(self.NOTIFY, msg, *args, **kw)
michael@0 328 def warn(self, msg, *args, **kw):
michael@0 329 self.log(self.WARN, msg, *args, **kw)
michael@0 330 def error(self, msg, *args, **kw):
michael@0 331 self.log(self.ERROR, msg, *args, **kw)
michael@0 332 def fatal(self, msg, *args, **kw):
michael@0 333 self.log(self.FATAL, msg, *args, **kw)
michael@0 334 def log(self, level, msg, *args, **kw):
michael@0 335 if args:
michael@0 336 if kw:
michael@0 337 raise TypeError(
michael@0 338 "You may give positional or keyword arguments, not both")
michael@0 339 args = args or kw
michael@0 340 rendered = None
michael@0 341 for consumer_level, consumer in self.consumers:
michael@0 342 if self.level_matches(level, consumer_level):
michael@0 343 if (self.in_progress_hanging
michael@0 344 and consumer in (sys.stdout, sys.stderr)):
michael@0 345 self.in_progress_hanging = False
michael@0 346 sys.stdout.write('\n')
michael@0 347 sys.stdout.flush()
michael@0 348 if rendered is None:
michael@0 349 if args:
michael@0 350 rendered = msg % args
michael@0 351 else:
michael@0 352 rendered = msg
michael@0 353 rendered = ' '*self.indent + rendered
michael@0 354 if hasattr(consumer, 'write'):
michael@0 355 consumer.write(rendered+'\n')
michael@0 356 else:
michael@0 357 consumer(rendered)
michael@0 358
michael@0 359 def start_progress(self, msg):
michael@0 360 assert not self.in_progress, (
michael@0 361 "Tried to start_progress(%r) while in_progress %r"
michael@0 362 % (msg, self.in_progress))
michael@0 363 if self.level_matches(self.NOTIFY, self._stdout_level()):
michael@0 364 sys.stdout.write(msg)
michael@0 365 sys.stdout.flush()
michael@0 366 self.in_progress_hanging = True
michael@0 367 else:
michael@0 368 self.in_progress_hanging = False
michael@0 369 self.in_progress = msg
michael@0 370
michael@0 371 def end_progress(self, msg='done.'):
michael@0 372 assert self.in_progress, (
michael@0 373 "Tried to end_progress without start_progress")
michael@0 374 if self.stdout_level_matches(self.NOTIFY):
michael@0 375 if not self.in_progress_hanging:
michael@0 376 # Some message has been printed out since start_progress
michael@0 377 sys.stdout.write('...' + self.in_progress + msg + '\n')
michael@0 378 sys.stdout.flush()
michael@0 379 else:
michael@0 380 sys.stdout.write(msg + '\n')
michael@0 381 sys.stdout.flush()
michael@0 382 self.in_progress = None
michael@0 383 self.in_progress_hanging = False
michael@0 384
michael@0 385 def show_progress(self):
michael@0 386 """If we are in a progress scope, and no log messages have been
michael@0 387 shown, write out another '.'"""
michael@0 388 if self.in_progress_hanging:
michael@0 389 sys.stdout.write('.')
michael@0 390 sys.stdout.flush()
michael@0 391
michael@0 392 def stdout_level_matches(self, level):
michael@0 393 """Returns true if a message at this level will go to stdout"""
michael@0 394 return self.level_matches(level, self._stdout_level())
michael@0 395
michael@0 396 def _stdout_level(self):
michael@0 397 """Returns the level that stdout runs at"""
michael@0 398 for level, consumer in self.consumers:
michael@0 399 if consumer is sys.stdout:
michael@0 400 return level
michael@0 401 return self.FATAL
michael@0 402
michael@0 403 def level_matches(self, level, consumer_level):
michael@0 404 """
michael@0 405 >>> l = Logger([])
michael@0 406 >>> l.level_matches(3, 4)
michael@0 407 False
michael@0 408 >>> l.level_matches(3, 2)
michael@0 409 True
michael@0 410 >>> l.level_matches(slice(None, 3), 3)
michael@0 411 False
michael@0 412 >>> l.level_matches(slice(None, 3), 2)
michael@0 413 True
michael@0 414 >>> l.level_matches(slice(1, 3), 1)
michael@0 415 True
michael@0 416 >>> l.level_matches(slice(2, 3), 1)
michael@0 417 False
michael@0 418 """
michael@0 419 if isinstance(level, slice):
michael@0 420 start, stop = level.start, level.stop
michael@0 421 if start is not None and start > consumer_level:
michael@0 422 return False
michael@0 423 if stop is not None and stop <= consumer_level:
michael@0 424 return False
michael@0 425 return True
michael@0 426 else:
michael@0 427 return level >= consumer_level
michael@0 428
michael@0 429 #@classmethod
michael@0 430 def level_for_integer(cls, level):
michael@0 431 levels = cls.LEVELS
michael@0 432 if level < 0:
michael@0 433 return levels[0]
michael@0 434 if level >= len(levels):
michael@0 435 return levels[-1]
michael@0 436 return levels[level]
michael@0 437
michael@0 438 level_for_integer = classmethod(level_for_integer)
michael@0 439
michael@0 440 # create a silent logger just to prevent this from being undefined
michael@0 441 # will be overridden with requested verbosity main() is called.
michael@0 442 logger = Logger([(Logger.LEVELS[-1], sys.stdout)])
michael@0 443
michael@0 444 def mkdir(path):
michael@0 445 if not os.path.exists(path):
michael@0 446 logger.info('Creating %s', path)
michael@0 447 os.makedirs(path)
michael@0 448 else:
michael@0 449 logger.info('Directory %s already exists', path)
michael@0 450
michael@0 451 def copyfileordir(src, dest, symlink=True):
michael@0 452 if os.path.isdir(src):
michael@0 453 shutil.copytree(src, dest, symlink)
michael@0 454 else:
michael@0 455 shutil.copy2(src, dest)
michael@0 456
michael@0 457 def copyfile(src, dest, symlink=True):
michael@0 458 if not os.path.exists(src):
michael@0 459 # Some bad symlink in the src
michael@0 460 logger.warn('Cannot find file %s (bad symlink)', src)
michael@0 461 return
michael@0 462 if os.path.exists(dest):
michael@0 463 logger.debug('File %s already exists', dest)
michael@0 464 return
michael@0 465 if not os.path.exists(os.path.dirname(dest)):
michael@0 466 logger.info('Creating parent directories for %s', os.path.dirname(dest))
michael@0 467 os.makedirs(os.path.dirname(dest))
michael@0 468 if not os.path.islink(src):
michael@0 469 srcpath = os.path.abspath(src)
michael@0 470 else:
michael@0 471 srcpath = os.readlink(src)
michael@0 472 if symlink and hasattr(os, 'symlink') and not is_win:
michael@0 473 logger.info('Symlinking %s', dest)
michael@0 474 try:
michael@0 475 os.symlink(srcpath, dest)
michael@0 476 except (OSError, NotImplementedError):
michael@0 477 logger.info('Symlinking failed, copying to %s', dest)
michael@0 478 copyfileordir(src, dest, symlink)
michael@0 479 else:
michael@0 480 logger.info('Copying to %s', dest)
michael@0 481 copyfileordir(src, dest, symlink)
michael@0 482
michael@0 483 def writefile(dest, content, overwrite=True):
michael@0 484 if not os.path.exists(dest):
michael@0 485 logger.info('Writing %s', dest)
michael@0 486 f = open(dest, 'wb')
michael@0 487 f.write(content.encode('utf-8'))
michael@0 488 f.close()
michael@0 489 return
michael@0 490 else:
michael@0 491 f = open(dest, 'rb')
michael@0 492 c = f.read()
michael@0 493 f.close()
michael@0 494 if c != content.encode("utf-8"):
michael@0 495 if not overwrite:
michael@0 496 logger.notify('File %s exists with different content; not overwriting', dest)
michael@0 497 return
michael@0 498 logger.notify('Overwriting %s with new content', dest)
michael@0 499 f = open(dest, 'wb')
michael@0 500 f.write(content.encode('utf-8'))
michael@0 501 f.close()
michael@0 502 else:
michael@0 503 logger.info('Content %s already in place', dest)
michael@0 504
michael@0 505 def rmtree(dir):
michael@0 506 if os.path.exists(dir):
michael@0 507 logger.notify('Deleting tree %s', dir)
michael@0 508 shutil.rmtree(dir)
michael@0 509 else:
michael@0 510 logger.info('Do not need to delete %s; already gone', dir)
michael@0 511
michael@0 512 def make_exe(fn):
michael@0 513 if hasattr(os, 'chmod'):
michael@0 514 oldmode = os.stat(fn).st_mode & 0xFFF # 0o7777
michael@0 515 newmode = (oldmode | 0x16D) & 0xFFF # 0o555, 0o7777
michael@0 516 os.chmod(fn, newmode)
michael@0 517 logger.info('Changed mode of %s to %s', fn, oct(newmode))
michael@0 518
michael@0 519 def _find_file(filename, dirs):
michael@0 520 for dir in reversed(dirs):
michael@0 521 files = glob.glob(os.path.join(dir, filename))
michael@0 522 if files and os.path.isfile(files[0]):
michael@0 523 return True, files[0]
michael@0 524 return False, filename
michael@0 525
michael@0 526 def file_search_dirs():
michael@0 527 here = os.path.dirname(os.path.abspath(__file__))
michael@0 528 dirs = ['.', here,
michael@0 529 join(here, 'virtualenv_support')]
michael@0 530 if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
michael@0 531 # Probably some boot script; just in case virtualenv is installed...
michael@0 532 try:
michael@0 533 import virtualenv
michael@0 534 except ImportError:
michael@0 535 pass
michael@0 536 else:
michael@0 537 dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support'))
michael@0 538 return [d for d in dirs if os.path.isdir(d)]
michael@0 539
michael@0 540
michael@0 541 class UpdatingDefaultsHelpFormatter(optparse.IndentedHelpFormatter):
michael@0 542 """
michael@0 543 Custom help formatter for use in ConfigOptionParser that updates
michael@0 544 the defaults before expanding them, allowing them to show up correctly
michael@0 545 in the help listing
michael@0 546 """
michael@0 547 def expand_default(self, option):
michael@0 548 if self.parser is not None:
michael@0 549 self.parser.update_defaults(self.parser.defaults)
michael@0 550 return optparse.IndentedHelpFormatter.expand_default(self, option)
michael@0 551
michael@0 552
michael@0 553 class ConfigOptionParser(optparse.OptionParser):
michael@0 554 """
michael@0 555 Custom option parser which updates its defaults by checking the
michael@0 556 configuration files and environmental variables
michael@0 557 """
michael@0 558 def __init__(self, *args, **kwargs):
michael@0 559 self.config = ConfigParser.RawConfigParser()
michael@0 560 self.files = self.get_config_files()
michael@0 561 self.config.read(self.files)
michael@0 562 optparse.OptionParser.__init__(self, *args, **kwargs)
michael@0 563
michael@0 564 def get_config_files(self):
michael@0 565 config_file = os.environ.get('VIRTUALENV_CONFIG_FILE', False)
michael@0 566 if config_file and os.path.exists(config_file):
michael@0 567 return [config_file]
michael@0 568 return [default_config_file]
michael@0 569
michael@0 570 def update_defaults(self, defaults):
michael@0 571 """
michael@0 572 Updates the given defaults with values from the config files and
michael@0 573 the environ. Does a little special handling for certain types of
michael@0 574 options (lists).
michael@0 575 """
michael@0 576 # Then go and look for the other sources of configuration:
michael@0 577 config = {}
michael@0 578 # 1. config files
michael@0 579 config.update(dict(self.get_config_section('virtualenv')))
michael@0 580 # 2. environmental variables
michael@0 581 config.update(dict(self.get_environ_vars()))
michael@0 582 # Then set the options with those values
michael@0 583 for key, val in config.items():
michael@0 584 key = key.replace('_', '-')
michael@0 585 if not key.startswith('--'):
michael@0 586 key = '--%s' % key # only prefer long opts
michael@0 587 option = self.get_option(key)
michael@0 588 if option is not None:
michael@0 589 # ignore empty values
michael@0 590 if not val:
michael@0 591 continue
michael@0 592 # handle multiline configs
michael@0 593 if option.action == 'append':
michael@0 594 val = val.split()
michael@0 595 else:
michael@0 596 option.nargs = 1
michael@0 597 if option.action == 'store_false':
michael@0 598 val = not strtobool(val)
michael@0 599 elif option.action in ('store_true', 'count'):
michael@0 600 val = strtobool(val)
michael@0 601 try:
michael@0 602 val = option.convert_value(key, val)
michael@0 603 except optparse.OptionValueError:
michael@0 604 e = sys.exc_info()[1]
michael@0 605 print("An error occured during configuration: %s" % e)
michael@0 606 sys.exit(3)
michael@0 607 defaults[option.dest] = val
michael@0 608 return defaults
michael@0 609
michael@0 610 def get_config_section(self, name):
michael@0 611 """
michael@0 612 Get a section of a configuration
michael@0 613 """
michael@0 614 if self.config.has_section(name):
michael@0 615 return self.config.items(name)
michael@0 616 return []
michael@0 617
michael@0 618 def get_environ_vars(self, prefix='VIRTUALENV_'):
michael@0 619 """
michael@0 620 Returns a generator with all environmental vars with prefix VIRTUALENV
michael@0 621 """
michael@0 622 for key, val in os.environ.items():
michael@0 623 if key.startswith(prefix):
michael@0 624 yield (key.replace(prefix, '').lower(), val)
michael@0 625
michael@0 626 def get_default_values(self):
michael@0 627 """
michael@0 628 Overridding to make updating the defaults after instantiation of
michael@0 629 the option parser possible, update_defaults() does the dirty work.
michael@0 630 """
michael@0 631 if not self.process_default_values:
michael@0 632 # Old, pre-Optik 1.5 behaviour.
michael@0 633 return optparse.Values(self.defaults)
michael@0 634
michael@0 635 defaults = self.update_defaults(self.defaults.copy()) # ours
michael@0 636 for option in self._get_all_options():
michael@0 637 default = defaults.get(option.dest)
michael@0 638 if isinstance(default, basestring):
michael@0 639 opt_str = option.get_opt_string()
michael@0 640 defaults[option.dest] = option.check_value(opt_str, default)
michael@0 641 return optparse.Values(defaults)
michael@0 642
michael@0 643
michael@0 644 def main():
michael@0 645 parser = ConfigOptionParser(
michael@0 646 version=virtualenv_version,
michael@0 647 usage="%prog [OPTIONS] DEST_DIR",
michael@0 648 formatter=UpdatingDefaultsHelpFormatter())
michael@0 649
michael@0 650 parser.add_option(
michael@0 651 '-v', '--verbose',
michael@0 652 action='count',
michael@0 653 dest='verbose',
michael@0 654 default=0,
michael@0 655 help="Increase verbosity.")
michael@0 656
michael@0 657 parser.add_option(
michael@0 658 '-q', '--quiet',
michael@0 659 action='count',
michael@0 660 dest='quiet',
michael@0 661 default=0,
michael@0 662 help='Decrease verbosity.')
michael@0 663
michael@0 664 parser.add_option(
michael@0 665 '-p', '--python',
michael@0 666 dest='python',
michael@0 667 metavar='PYTHON_EXE',
michael@0 668 help='The Python interpreter to use, e.g., --python=python2.5 will use the python2.5 '
michael@0 669 'interpreter to create the new environment. The default is the interpreter that '
michael@0 670 'virtualenv was installed with (%s)' % sys.executable)
michael@0 671
michael@0 672 parser.add_option(
michael@0 673 '--clear',
michael@0 674 dest='clear',
michael@0 675 action='store_true',
michael@0 676 help="Clear out the non-root install and start from scratch.")
michael@0 677
michael@0 678 parser.set_defaults(system_site_packages=False)
michael@0 679 parser.add_option(
michael@0 680 '--no-site-packages',
michael@0 681 dest='system_site_packages',
michael@0 682 action='store_false',
michael@0 683 help="DEPRECATED. Retained only for backward compatibility. "
michael@0 684 "Not having access to global site-packages is now the default behavior.")
michael@0 685
michael@0 686 parser.add_option(
michael@0 687 '--system-site-packages',
michael@0 688 dest='system_site_packages',
michael@0 689 action='store_true',
michael@0 690 help="Give the virtual environment access to the global site-packages.")
michael@0 691
michael@0 692 parser.add_option(
michael@0 693 '--always-copy',
michael@0 694 dest='symlink',
michael@0 695 action='store_false',
michael@0 696 default=True,
michael@0 697 help="Always copy files rather than symlinking.")
michael@0 698
michael@0 699 parser.add_option(
michael@0 700 '--unzip-setuptools',
michael@0 701 dest='unzip_setuptools',
michael@0 702 action='store_true',
michael@0 703 help="Unzip Setuptools when installing it.")
michael@0 704
michael@0 705 parser.add_option(
michael@0 706 '--relocatable',
michael@0 707 dest='relocatable',
michael@0 708 action='store_true',
michael@0 709 help='Make an EXISTING virtualenv environment relocatable. '
michael@0 710 'This fixes up scripts and makes all .pth files relative.')
michael@0 711
michael@0 712 parser.add_option(
michael@0 713 '--no-setuptools',
michael@0 714 dest='no_setuptools',
michael@0 715 action='store_true',
michael@0 716 help='Do not install setuptools (or pip) in the new virtualenv.')
michael@0 717
michael@0 718 parser.add_option(
michael@0 719 '--no-pip',
michael@0 720 dest='no_pip',
michael@0 721 action='store_true',
michael@0 722 help='Do not install pip in the new virtualenv.')
michael@0 723
michael@0 724 default_search_dirs = file_search_dirs()
michael@0 725 parser.add_option(
michael@0 726 '--extra-search-dir',
michael@0 727 dest="search_dirs",
michael@0 728 action="append",
michael@0 729 metavar='DIR',
michael@0 730 default=default_search_dirs,
michael@0 731 help="Directory to look for setuptools/pip distributions in. "
michael@0 732 "This option can be used multiple times.")
michael@0 733
michael@0 734 parser.add_option(
michael@0 735 '--never-download',
michael@0 736 dest="never_download",
michael@0 737 action="store_true",
michael@0 738 default=True,
michael@0 739 help="DEPRECATED. Retained only for backward compatibility. This option has no effect. "
michael@0 740 "Virtualenv never downloads pip or setuptools.")
michael@0 741
michael@0 742 parser.add_option(
michael@0 743 '--prompt',
michael@0 744 dest='prompt',
michael@0 745 help='Provides an alternative prompt prefix for this environment.')
michael@0 746
michael@0 747 parser.add_option(
michael@0 748 '--setuptools',
michael@0 749 dest='setuptools',
michael@0 750 action='store_true',
michael@0 751 help="DEPRECATED. Retained only for backward compatibility. This option has no effect.")
michael@0 752
michael@0 753 parser.add_option(
michael@0 754 '--distribute',
michael@0 755 dest='distribute',
michael@0 756 action='store_true',
michael@0 757 help="DEPRECATED. Retained only for backward compatibility. This option has no effect.")
michael@0 758
michael@0 759 if 'extend_parser' in globals():
michael@0 760 extend_parser(parser)
michael@0 761
michael@0 762 options, args = parser.parse_args()
michael@0 763
michael@0 764 global logger
michael@0 765
michael@0 766 if 'adjust_options' in globals():
michael@0 767 adjust_options(options, args)
michael@0 768
michael@0 769 verbosity = options.verbose - options.quiet
michael@0 770 logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
michael@0 771
michael@0 772 if options.python and not os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
michael@0 773 env = os.environ.copy()
michael@0 774 interpreter = resolve_interpreter(options.python)
michael@0 775 if interpreter == sys.executable:
michael@0 776 logger.warn('Already using interpreter %s' % interpreter)
michael@0 777 else:
michael@0 778 logger.notify('Running virtualenv with interpreter %s' % interpreter)
michael@0 779 env['VIRTUALENV_INTERPRETER_RUNNING'] = 'true'
michael@0 780 file = __file__
michael@0 781 if file.endswith('.pyc'):
michael@0 782 file = file[:-1]
michael@0 783 popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
michael@0 784 raise SystemExit(popen.wait())
michael@0 785
michael@0 786 if not args:
michael@0 787 print('You must provide a DEST_DIR')
michael@0 788 parser.print_help()
michael@0 789 sys.exit(2)
michael@0 790 if len(args) > 1:
michael@0 791 print('There must be only one argument: DEST_DIR (you gave %s)' % (
michael@0 792 ' '.join(args)))
michael@0 793 parser.print_help()
michael@0 794 sys.exit(2)
michael@0 795
michael@0 796 home_dir = args[0]
michael@0 797
michael@0 798 if os.environ.get('WORKING_ENV'):
michael@0 799 logger.fatal('ERROR: you cannot run virtualenv while in a workingenv')
michael@0 800 logger.fatal('Please deactivate your workingenv, then re-run this script')
michael@0 801 sys.exit(3)
michael@0 802
michael@0 803 if 'PYTHONHOME' in os.environ:
michael@0 804 logger.warn('PYTHONHOME is set. You *must* activate the virtualenv before using it')
michael@0 805 del os.environ['PYTHONHOME']
michael@0 806
michael@0 807 if options.relocatable:
michael@0 808 make_environment_relocatable(home_dir)
michael@0 809 return
michael@0 810
michael@0 811 if not options.never_download:
michael@0 812 logger.warn('The --never-download option is for backward compatibility only.')
michael@0 813 logger.warn('Setting it to false is no longer supported, and will be ignored.')
michael@0 814
michael@0 815 create_environment(home_dir,
michael@0 816 site_packages=options.system_site_packages,
michael@0 817 clear=options.clear,
michael@0 818 unzip_setuptools=options.unzip_setuptools,
michael@0 819 prompt=options.prompt,
michael@0 820 search_dirs=options.search_dirs,
michael@0 821 never_download=True,
michael@0 822 no_setuptools=options.no_setuptools,
michael@0 823 no_pip=options.no_pip,
michael@0 824 symlink=options.symlink)
michael@0 825 if 'after_install' in globals():
michael@0 826 after_install(options, home_dir)
michael@0 827
michael@0 828 def call_subprocess(cmd, show_stdout=True,
michael@0 829 filter_stdout=None, cwd=None,
michael@0 830 raise_on_returncode=True, extra_env=None,
michael@0 831 remove_from_env=None):
michael@0 832 cmd_parts = []
michael@0 833 for part in cmd:
michael@0 834 if len(part) > 45:
michael@0 835 part = part[:20]+"..."+part[-20:]
michael@0 836 if ' ' in part or '\n' in part or '"' in part or "'" in part:
michael@0 837 part = '"%s"' % part.replace('"', '\\"')
michael@0 838 if hasattr(part, 'decode'):
michael@0 839 try:
michael@0 840 part = part.decode(sys.getdefaultencoding())
michael@0 841 except UnicodeDecodeError:
michael@0 842 part = part.decode(sys.getfilesystemencoding())
michael@0 843 cmd_parts.append(part)
michael@0 844 cmd_desc = ' '.join(cmd_parts)
michael@0 845 if show_stdout:
michael@0 846 stdout = None
michael@0 847 else:
michael@0 848 stdout = subprocess.PIPE
michael@0 849 logger.debug("Running command %s" % cmd_desc)
michael@0 850 if extra_env or remove_from_env:
michael@0 851 env = os.environ.copy()
michael@0 852 if extra_env:
michael@0 853 env.update(extra_env)
michael@0 854 if remove_from_env:
michael@0 855 for varname in remove_from_env:
michael@0 856 env.pop(varname, None)
michael@0 857 else:
michael@0 858 env = None
michael@0 859 try:
michael@0 860 proc = subprocess.Popen(
michael@0 861 cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
michael@0 862 cwd=cwd, env=env)
michael@0 863 except Exception:
michael@0 864 e = sys.exc_info()[1]
michael@0 865 logger.fatal(
michael@0 866 "Error %s while executing command %s" % (e, cmd_desc))
michael@0 867 raise
michael@0 868 all_output = []
michael@0 869 if stdout is not None:
michael@0 870 stdout = proc.stdout
michael@0 871 encoding = sys.getdefaultencoding()
michael@0 872 fs_encoding = sys.getfilesystemencoding()
michael@0 873 while 1:
michael@0 874 line = stdout.readline()
michael@0 875 try:
michael@0 876 line = line.decode(encoding)
michael@0 877 except UnicodeDecodeError:
michael@0 878 line = line.decode(fs_encoding)
michael@0 879 if not line:
michael@0 880 break
michael@0 881 line = line.rstrip()
michael@0 882 all_output.append(line)
michael@0 883 if filter_stdout:
michael@0 884 level = filter_stdout(line)
michael@0 885 if isinstance(level, tuple):
michael@0 886 level, line = level
michael@0 887 logger.log(level, line)
michael@0 888 if not logger.stdout_level_matches(level):
michael@0 889 logger.show_progress()
michael@0 890 else:
michael@0 891 logger.info(line)
michael@0 892 else:
michael@0 893 proc.communicate()
michael@0 894 proc.wait()
michael@0 895 if proc.returncode:
michael@0 896 if raise_on_returncode:
michael@0 897 if all_output:
michael@0 898 logger.notify('Complete output from command %s:' % cmd_desc)
michael@0 899 logger.notify('\n'.join(all_output) + '\n----------------------------------------')
michael@0 900 raise OSError(
michael@0 901 "Command %s failed with error code %s"
michael@0 902 % (cmd_desc, proc.returncode))
michael@0 903 else:
michael@0 904 logger.warn(
michael@0 905 "Command %s had error code %s"
michael@0 906 % (cmd_desc, proc.returncode))
michael@0 907
michael@0 908 def filter_install_output(line):
michael@0 909 if line.strip().startswith('running'):
michael@0 910 return Logger.INFO
michael@0 911 return Logger.DEBUG
michael@0 912
michael@0 913 def find_wheels(projects, search_dirs):
michael@0 914 """Find wheels from which we can import PROJECTS.
michael@0 915
michael@0 916 Scan through SEARCH_DIRS for a wheel for each PROJECT in turn. Return
michael@0 917 a list of the first wheel found for each PROJECT
michael@0 918 """
michael@0 919
michael@0 920 wheels = []
michael@0 921
michael@0 922 # Look through SEARCH_DIRS for the first suitable wheel. Don't bother
michael@0 923 # about version checking here, as this is simply to get something we can
michael@0 924 # then use to install the correct version.
michael@0 925 for project in projects:
michael@0 926 for dirname in search_dirs:
michael@0 927 # This relies on only having "universal" wheels available.
michael@0 928 # The pattern could be tightened to require -py2.py3-none-any.whl.
michael@0 929 files = glob.glob(os.path.join(dirname, project + '-*.whl'))
michael@0 930 if files:
michael@0 931 wheels.append(os.path.abspath(files[0]))
michael@0 932 break
michael@0 933 else:
michael@0 934 # We're out of luck, so quit with a suitable error
michael@0 935 logger.fatal('Cannot find a wheel for %s' % (project,))
michael@0 936
michael@0 937 return wheels
michael@0 938
michael@0 939 def install_wheel(project_names, py_executable, search_dirs=None):
michael@0 940 if search_dirs is None:
michael@0 941 search_dirs = file_search_dirs()
michael@0 942
michael@0 943 wheels = find_wheels(['setuptools', 'pip'], search_dirs)
michael@0 944 pythonpath = os.pathsep.join(wheels)
michael@0 945 findlinks = ' '.join(search_dirs)
michael@0 946
michael@0 947 cmd = [
michael@0 948 py_executable, '-c',
michael@0 949 'import sys, pip; sys.exit(pip.main(["install", "--ignore-installed"] + sys.argv[1:]))',
michael@0 950 ] + project_names
michael@0 951 logger.start_progress('Installing %s...' % (', '.join(project_names)))
michael@0 952 logger.indent += 2
michael@0 953 try:
michael@0 954 call_subprocess(cmd, show_stdout=False,
michael@0 955 extra_env = {
michael@0 956 'PYTHONPATH': pythonpath,
michael@0 957 'PIP_FIND_LINKS': findlinks,
michael@0 958 'PIP_USE_WHEEL': '1',
michael@0 959 'PIP_PRE': '1',
michael@0 960 'PIP_NO_INDEX': '1'
michael@0 961 }
michael@0 962 )
michael@0 963 finally:
michael@0 964 logger.indent -= 2
michael@0 965 logger.end_progress()
michael@0 966
michael@0 967 def create_environment(home_dir, site_packages=False, clear=False,
michael@0 968 unzip_setuptools=False,
michael@0 969 prompt=None, search_dirs=None, never_download=False,
michael@0 970 no_setuptools=False, no_pip=False, symlink=True):
michael@0 971 """
michael@0 972 Creates a new environment in ``home_dir``.
michael@0 973
michael@0 974 If ``site_packages`` is true, then the global ``site-packages/``
michael@0 975 directory will be on the path.
michael@0 976
michael@0 977 If ``clear`` is true (default False) then the environment will
michael@0 978 first be cleared.
michael@0 979 """
michael@0 980 home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
michael@0 981
michael@0 982 py_executable = os.path.abspath(install_python(
michael@0 983 home_dir, lib_dir, inc_dir, bin_dir,
michael@0 984 site_packages=site_packages, clear=clear, symlink=symlink))
michael@0 985
michael@0 986 install_distutils(home_dir)
michael@0 987
michael@0 988 if not no_setuptools:
michael@0 989 to_install = ['setuptools']
michael@0 990 if not no_pip:
michael@0 991 to_install.append('pip')
michael@0 992 install_wheel(to_install, py_executable, search_dirs)
michael@0 993
michael@0 994 install_activate(home_dir, bin_dir, prompt)
michael@0 995
michael@0 996 def is_executable_file(fpath):
michael@0 997 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
michael@0 998
michael@0 999 def path_locations(home_dir):
michael@0 1000 """Return the path locations for the environment (where libraries are,
michael@0 1001 where scripts go, etc)"""
michael@0 1002 # XXX: We'd use distutils.sysconfig.get_python_inc/lib but its
michael@0 1003 # prefix arg is broken: http://bugs.python.org/issue3386
michael@0 1004 if is_win:
michael@0 1005 # Windows has lots of problems with executables with spaces in
michael@0 1006 # the name; this function will remove them (using the ~1
michael@0 1007 # format):
michael@0 1008 mkdir(home_dir)
michael@0 1009 if ' ' in home_dir:
michael@0 1010 import ctypes
michael@0 1011 GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
michael@0 1012 size = max(len(home_dir)+1, 256)
michael@0 1013 buf = ctypes.create_unicode_buffer(size)
michael@0 1014 try:
michael@0 1015 u = unicode
michael@0 1016 except NameError:
michael@0 1017 u = str
michael@0 1018 ret = GetShortPathName(u(home_dir), buf, size)
michael@0 1019 if not ret:
michael@0 1020 print('Error: the path "%s" has a space in it' % home_dir)
michael@0 1021 print('We could not determine the short pathname for it.')
michael@0 1022 print('Exiting.')
michael@0 1023 sys.exit(3)
michael@0 1024 home_dir = str(buf.value)
michael@0 1025 lib_dir = join(home_dir, 'Lib')
michael@0 1026 inc_dir = join(home_dir, 'Include')
michael@0 1027 bin_dir = join(home_dir, 'Scripts')
michael@0 1028 if is_jython:
michael@0 1029 lib_dir = join(home_dir, 'Lib')
michael@0 1030 inc_dir = join(home_dir, 'Include')
michael@0 1031 bin_dir = join(home_dir, 'bin')
michael@0 1032 elif is_pypy:
michael@0 1033 lib_dir = home_dir
michael@0 1034 inc_dir = join(home_dir, 'include')
michael@0 1035 bin_dir = join(home_dir, 'bin')
michael@0 1036 elif not is_win:
michael@0 1037 lib_dir = join(home_dir, 'lib', py_version)
michael@0 1038 multiarch_exec = '/usr/bin/multiarch-platform'
michael@0 1039 if is_executable_file(multiarch_exec):
michael@0 1040 # In Mageia (2) and Mandriva distros the include dir must be like:
michael@0 1041 # virtualenv/include/multiarch-x86_64-linux/python2.7
michael@0 1042 # instead of being virtualenv/include/python2.7
michael@0 1043 p = subprocess.Popen(multiarch_exec, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
michael@0 1044 stdout, stderr = p.communicate()
michael@0 1045 # stdout.strip is needed to remove newline character
michael@0 1046 inc_dir = join(home_dir, 'include', stdout.strip(), py_version + abiflags)
michael@0 1047 else:
michael@0 1048 inc_dir = join(home_dir, 'include', py_version + abiflags)
michael@0 1049 bin_dir = join(home_dir, 'bin')
michael@0 1050 return home_dir, lib_dir, inc_dir, bin_dir
michael@0 1051
michael@0 1052
michael@0 1053 def change_prefix(filename, dst_prefix):
michael@0 1054 prefixes = [sys.prefix]
michael@0 1055
michael@0 1056 if is_darwin:
michael@0 1057 prefixes.extend((
michael@0 1058 os.path.join("/Library/Python", sys.version[:3], "site-packages"),
michael@0 1059 os.path.join(sys.prefix, "Extras", "lib", "python"),
michael@0 1060 os.path.join("~", "Library", "Python", sys.version[:3], "site-packages"),
michael@0 1061 # Python 2.6 no-frameworks
michael@0 1062 os.path.join("~", ".local", "lib","python", sys.version[:3], "site-packages"),
michael@0 1063 # System Python 2.7 on OSX Mountain Lion
michael@0 1064 os.path.join("~", "Library", "Python", sys.version[:3], "lib", "python", "site-packages")))
michael@0 1065
michael@0 1066 if hasattr(sys, 'real_prefix'):
michael@0 1067 prefixes.append(sys.real_prefix)
michael@0 1068 if hasattr(sys, 'base_prefix'):
michael@0 1069 prefixes.append(sys.base_prefix)
michael@0 1070 prefixes = list(map(os.path.expanduser, prefixes))
michael@0 1071 prefixes = list(map(os.path.abspath, prefixes))
michael@0 1072 # Check longer prefixes first so we don't split in the middle of a filename
michael@0 1073 prefixes = sorted(prefixes, key=len, reverse=True)
michael@0 1074 filename = os.path.abspath(filename)
michael@0 1075 for src_prefix in prefixes:
michael@0 1076 if filename.startswith(src_prefix):
michael@0 1077 _, relpath = filename.split(src_prefix, 1)
michael@0 1078 if src_prefix != os.sep: # sys.prefix == "/"
michael@0 1079 assert relpath[0] == os.sep
michael@0 1080 relpath = relpath[1:]
michael@0 1081 return join(dst_prefix, relpath)
michael@0 1082 assert False, "Filename %s does not start with any of these prefixes: %s" % \
michael@0 1083 (filename, prefixes)
michael@0 1084
michael@0 1085 def copy_required_modules(dst_prefix, symlink):
michael@0 1086 import imp
michael@0 1087 # If we are running under -p, we need to remove the current
michael@0 1088 # directory from sys.path temporarily here, so that we
michael@0 1089 # definitely get the modules from the site directory of
michael@0 1090 # the interpreter we are running under, not the one
michael@0 1091 # virtualenv.py is installed under (which might lead to py2/py3
michael@0 1092 # incompatibility issues)
michael@0 1093 _prev_sys_path = sys.path
michael@0 1094 if os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
michael@0 1095 sys.path = sys.path[1:]
michael@0 1096 try:
michael@0 1097 for modname in REQUIRED_MODULES:
michael@0 1098 if modname in sys.builtin_module_names:
michael@0 1099 logger.info("Ignoring built-in bootstrap module: %s" % modname)
michael@0 1100 continue
michael@0 1101 try:
michael@0 1102 f, filename, _ = imp.find_module(modname)
michael@0 1103 except ImportError:
michael@0 1104 logger.info("Cannot import bootstrap module: %s" % modname)
michael@0 1105 else:
michael@0 1106 if f is not None:
michael@0 1107 f.close()
michael@0 1108 # special-case custom readline.so on OS X, but not for pypy:
michael@0 1109 if modname == 'readline' and sys.platform == 'darwin' and not (
michael@0 1110 is_pypy or filename.endswith(join('lib-dynload', 'readline.so'))):
michael@0 1111 dst_filename = join(dst_prefix, 'lib', 'python%s' % sys.version[:3], 'readline.so')
michael@0 1112 elif modname == 'readline' and sys.platform == 'win32':
michael@0 1113 # special-case for Windows, where readline is not a
michael@0 1114 # standard module, though it may have been installed in
michael@0 1115 # site-packages by a third-party package
michael@0 1116 pass
michael@0 1117 else:
michael@0 1118 dst_filename = change_prefix(filename, dst_prefix)
michael@0 1119 copyfile(filename, dst_filename, symlink)
michael@0 1120 if filename.endswith('.pyc'):
michael@0 1121 pyfile = filename[:-1]
michael@0 1122 if os.path.exists(pyfile):
michael@0 1123 copyfile(pyfile, dst_filename[:-1], symlink)
michael@0 1124 finally:
michael@0 1125 sys.path = _prev_sys_path
michael@0 1126
michael@0 1127
michael@0 1128 def subst_path(prefix_path, prefix, home_dir):
michael@0 1129 prefix_path = os.path.normpath(prefix_path)
michael@0 1130 prefix = os.path.normpath(prefix)
michael@0 1131 home_dir = os.path.normpath(home_dir)
michael@0 1132 if not prefix_path.startswith(prefix):
michael@0 1133 logger.warn('Path not in prefix %r %r', prefix_path, prefix)
michael@0 1134 return
michael@0 1135 return prefix_path.replace(prefix, home_dir, 1)
michael@0 1136
michael@0 1137
michael@0 1138 def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, symlink=True):
michael@0 1139 """Install just the base environment, no distutils patches etc"""
michael@0 1140 if sys.executable.startswith(bin_dir):
michael@0 1141 print('Please use the *system* python to run this script')
michael@0 1142 return
michael@0 1143
michael@0 1144 if clear:
michael@0 1145 rmtree(lib_dir)
michael@0 1146 ## FIXME: why not delete it?
michael@0 1147 ## Maybe it should delete everything with #!/path/to/venv/python in it
michael@0 1148 logger.notify('Not deleting %s', bin_dir)
michael@0 1149
michael@0 1150 if hasattr(sys, 'real_prefix'):
michael@0 1151 logger.notify('Using real prefix %r' % sys.real_prefix)
michael@0 1152 prefix = sys.real_prefix
michael@0 1153 elif hasattr(sys, 'base_prefix'):
michael@0 1154 logger.notify('Using base prefix %r' % sys.base_prefix)
michael@0 1155 prefix = sys.base_prefix
michael@0 1156 else:
michael@0 1157 prefix = sys.prefix
michael@0 1158 mkdir(lib_dir)
michael@0 1159 fix_lib64(lib_dir, symlink)
michael@0 1160 stdlib_dirs = [os.path.dirname(os.__file__)]
michael@0 1161 if is_win:
michael@0 1162 stdlib_dirs.append(join(os.path.dirname(stdlib_dirs[0]), 'DLLs'))
michael@0 1163 elif is_darwin:
michael@0 1164 stdlib_dirs.append(join(stdlib_dirs[0], 'site-packages'))
michael@0 1165 if hasattr(os, 'symlink'):
michael@0 1166 logger.info('Symlinking Python bootstrap modules')
michael@0 1167 else:
michael@0 1168 logger.info('Copying Python bootstrap modules')
michael@0 1169 logger.indent += 2
michael@0 1170 try:
michael@0 1171 # copy required files...
michael@0 1172 for stdlib_dir in stdlib_dirs:
michael@0 1173 if not os.path.isdir(stdlib_dir):
michael@0 1174 continue
michael@0 1175 for fn in os.listdir(stdlib_dir):
michael@0 1176 bn = os.path.splitext(fn)[0]
michael@0 1177 if fn != 'site-packages' and bn in REQUIRED_FILES:
michael@0 1178 copyfile(join(stdlib_dir, fn), join(lib_dir, fn), symlink)
michael@0 1179 # ...and modules
michael@0 1180 copy_required_modules(home_dir, symlink)
michael@0 1181 finally:
michael@0 1182 logger.indent -= 2
michael@0 1183 mkdir(join(lib_dir, 'site-packages'))
michael@0 1184 import site
michael@0 1185 site_filename = site.__file__
michael@0 1186 if site_filename.endswith('.pyc'):
michael@0 1187 site_filename = site_filename[:-1]
michael@0 1188 elif site_filename.endswith('$py.class'):
michael@0 1189 site_filename = site_filename.replace('$py.class', '.py')
michael@0 1190 site_filename_dst = change_prefix(site_filename, home_dir)
michael@0 1191 site_dir = os.path.dirname(site_filename_dst)
michael@0 1192 writefile(site_filename_dst, SITE_PY)
michael@0 1193 writefile(join(site_dir, 'orig-prefix.txt'), prefix)
michael@0 1194 site_packages_filename = join(site_dir, 'no-global-site-packages.txt')
michael@0 1195 if not site_packages:
michael@0 1196 writefile(site_packages_filename, '')
michael@0 1197
michael@0 1198 if is_pypy or is_win:
michael@0 1199 stdinc_dir = join(prefix, 'include')
michael@0 1200 else:
michael@0 1201 stdinc_dir = join(prefix, 'include', py_version + abiflags)
michael@0 1202 if os.path.exists(stdinc_dir):
michael@0 1203 copyfile(stdinc_dir, inc_dir, symlink)
michael@0 1204 else:
michael@0 1205 logger.debug('No include dir %s' % stdinc_dir)
michael@0 1206
michael@0 1207 platinc_dir = distutils.sysconfig.get_python_inc(plat_specific=1)
michael@0 1208 if platinc_dir != stdinc_dir:
michael@0 1209 platinc_dest = distutils.sysconfig.get_python_inc(
michael@0 1210 plat_specific=1, prefix=home_dir)
michael@0 1211 if platinc_dir == platinc_dest:
michael@0 1212 # Do platinc_dest manually due to a CPython bug;
michael@0 1213 # not http://bugs.python.org/issue3386 but a close cousin
michael@0 1214 platinc_dest = subst_path(platinc_dir, prefix, home_dir)
michael@0 1215 if platinc_dest:
michael@0 1216 # PyPy's stdinc_dir and prefix are relative to the original binary
michael@0 1217 # (traversing virtualenvs), whereas the platinc_dir is relative to
michael@0 1218 # the inner virtualenv and ignores the prefix argument.
michael@0 1219 # This seems more evolved than designed.
michael@0 1220 copyfile(platinc_dir, platinc_dest, symlink)
michael@0 1221
michael@0 1222 # pypy never uses exec_prefix, just ignore it
michael@0 1223 if sys.exec_prefix != prefix and not is_pypy:
michael@0 1224 if is_win:
michael@0 1225 exec_dir = join(sys.exec_prefix, 'lib')
michael@0 1226 elif is_jython:
michael@0 1227 exec_dir = join(sys.exec_prefix, 'Lib')
michael@0 1228 else:
michael@0 1229 exec_dir = join(sys.exec_prefix, 'lib', py_version)
michael@0 1230 for fn in os.listdir(exec_dir):
michael@0 1231 copyfile(join(exec_dir, fn), join(lib_dir, fn), symlink)
michael@0 1232
michael@0 1233 if is_jython:
michael@0 1234 # Jython has either jython-dev.jar and javalib/ dir, or just
michael@0 1235 # jython.jar
michael@0 1236 for name in 'jython-dev.jar', 'javalib', 'jython.jar':
michael@0 1237 src = join(prefix, name)
michael@0 1238 if os.path.exists(src):
michael@0 1239 copyfile(src, join(home_dir, name), symlink)
michael@0 1240 # XXX: registry should always exist after Jython 2.5rc1
michael@0 1241 src = join(prefix, 'registry')
michael@0 1242 if os.path.exists(src):
michael@0 1243 copyfile(src, join(home_dir, 'registry'), symlink=False)
michael@0 1244 copyfile(join(prefix, 'cachedir'), join(home_dir, 'cachedir'),
michael@0 1245 symlink=False)
michael@0 1246
michael@0 1247 mkdir(bin_dir)
michael@0 1248 py_executable = join(bin_dir, os.path.basename(sys.executable))
michael@0 1249 if 'Python.framework' in prefix:
michael@0 1250 # OS X framework builds cause validation to break
michael@0 1251 # https://github.com/pypa/virtualenv/issues/322
michael@0 1252 if os.environ.get('__PYVENV_LAUNCHER__'):
michael@0 1253 del os.environ["__PYVENV_LAUNCHER__"]
michael@0 1254 if re.search(r'/Python(?:-32|-64)*$', py_executable):
michael@0 1255 # The name of the python executable is not quite what
michael@0 1256 # we want, rename it.
michael@0 1257 py_executable = os.path.join(
michael@0 1258 os.path.dirname(py_executable), 'python')
michael@0 1259
michael@0 1260 logger.notify('New %s executable in %s', expected_exe, py_executable)
michael@0 1261 pcbuild_dir = os.path.dirname(sys.executable)
michael@0 1262 pyd_pth = os.path.join(lib_dir, 'site-packages', 'virtualenv_builddir_pyd.pth')
michael@0 1263 if is_win and os.path.exists(os.path.join(pcbuild_dir, 'build.bat')):
michael@0 1264 logger.notify('Detected python running from build directory %s', pcbuild_dir)
michael@0 1265 logger.notify('Writing .pth file linking to build directory for *.pyd files')
michael@0 1266 writefile(pyd_pth, pcbuild_dir)
michael@0 1267 else:
michael@0 1268 pcbuild_dir = None
michael@0 1269 if os.path.exists(pyd_pth):
michael@0 1270 logger.info('Deleting %s (not Windows env or not build directory python)' % pyd_pth)
michael@0 1271 os.unlink(pyd_pth)
michael@0 1272
michael@0 1273 if sys.executable != py_executable:
michael@0 1274 ## FIXME: could I just hard link?
michael@0 1275 executable = sys.executable
michael@0 1276 shutil.copyfile(executable, py_executable)
michael@0 1277 make_exe(py_executable)
michael@0 1278 if is_win or is_cygwin:
michael@0 1279 pythonw = os.path.join(os.path.dirname(sys.executable), 'pythonw.exe')
michael@0 1280 if os.path.exists(pythonw):
michael@0 1281 logger.info('Also created pythonw.exe')
michael@0 1282 shutil.copyfile(pythonw, os.path.join(os.path.dirname(py_executable), 'pythonw.exe'))
michael@0 1283 python_d = os.path.join(os.path.dirname(sys.executable), 'python_d.exe')
michael@0 1284 python_d_dest = os.path.join(os.path.dirname(py_executable), 'python_d.exe')
michael@0 1285 if os.path.exists(python_d):
michael@0 1286 logger.info('Also created python_d.exe')
michael@0 1287 shutil.copyfile(python_d, python_d_dest)
michael@0 1288 elif os.path.exists(python_d_dest):
michael@0 1289 logger.info('Removed python_d.exe as it is no longer at the source')
michael@0 1290 os.unlink(python_d_dest)
michael@0 1291 # we need to copy the DLL to enforce that windows will load the correct one.
michael@0 1292 # may not exist if we are cygwin.
michael@0 1293 py_executable_dll = 'python%s%s.dll' % (
michael@0 1294 sys.version_info[0], sys.version_info[1])
michael@0 1295 py_executable_dll_d = 'python%s%s_d.dll' % (
michael@0 1296 sys.version_info[0], sys.version_info[1])
michael@0 1297 pythondll = os.path.join(os.path.dirname(sys.executable), py_executable_dll)
michael@0 1298 pythondll_d = os.path.join(os.path.dirname(sys.executable), py_executable_dll_d)
michael@0 1299 pythondll_d_dest = os.path.join(os.path.dirname(py_executable), py_executable_dll_d)
michael@0 1300 if os.path.exists(pythondll):
michael@0 1301 logger.info('Also created %s' % py_executable_dll)
michael@0 1302 shutil.copyfile(pythondll, os.path.join(os.path.dirname(py_executable), py_executable_dll))
michael@0 1303 if os.path.exists(pythondll_d):
michael@0 1304 logger.info('Also created %s' % py_executable_dll_d)
michael@0 1305 shutil.copyfile(pythondll_d, pythondll_d_dest)
michael@0 1306 elif os.path.exists(pythondll_d_dest):
michael@0 1307 logger.info('Removed %s as the source does not exist' % pythondll_d_dest)
michael@0 1308 os.unlink(pythondll_d_dest)
michael@0 1309 if is_pypy:
michael@0 1310 # make a symlink python --> pypy-c
michael@0 1311 python_executable = os.path.join(os.path.dirname(py_executable), 'python')
michael@0 1312 if sys.platform in ('win32', 'cygwin'):
michael@0 1313 python_executable += '.exe'
michael@0 1314 logger.info('Also created executable %s' % python_executable)
michael@0 1315 copyfile(py_executable, python_executable, symlink)
michael@0 1316
michael@0 1317 if is_win:
michael@0 1318 for name in 'libexpat.dll', 'libpypy.dll', 'libpypy-c.dll', 'libeay32.dll', 'ssleay32.dll', 'sqlite.dll':
michael@0 1319 src = join(prefix, name)
michael@0 1320 if os.path.exists(src):
michael@0 1321 copyfile(src, join(bin_dir, name), symlink)
michael@0 1322
michael@0 1323 if os.path.splitext(os.path.basename(py_executable))[0] != expected_exe:
michael@0 1324 secondary_exe = os.path.join(os.path.dirname(py_executable),
michael@0 1325 expected_exe)
michael@0 1326 py_executable_ext = os.path.splitext(py_executable)[1]
michael@0 1327 if py_executable_ext.lower() == '.exe':
michael@0 1328 # python2.4 gives an extension of '.4' :P
michael@0 1329 secondary_exe += py_executable_ext
michael@0 1330 if os.path.exists(secondary_exe):
michael@0 1331 logger.warn('Not overwriting existing %s script %s (you must use %s)'
michael@0 1332 % (expected_exe, secondary_exe, py_executable))
michael@0 1333 else:
michael@0 1334 logger.notify('Also creating executable in %s' % secondary_exe)
michael@0 1335 shutil.copyfile(sys.executable, secondary_exe)
michael@0 1336 make_exe(secondary_exe)
michael@0 1337
michael@0 1338 if '.framework' in prefix:
michael@0 1339 if 'Python.framework' in prefix:
michael@0 1340 logger.debug('MacOSX Python framework detected')
michael@0 1341 # Make sure we use the the embedded interpreter inside
michael@0 1342 # the framework, even if sys.executable points to
michael@0 1343 # the stub executable in ${sys.prefix}/bin
michael@0 1344 # See http://groups.google.com/group/python-virtualenv/
michael@0 1345 # browse_thread/thread/17cab2f85da75951
michael@0 1346 original_python = os.path.join(
michael@0 1347 prefix, 'Resources/Python.app/Contents/MacOS/Python')
michael@0 1348 if 'EPD' in prefix:
michael@0 1349 logger.debug('EPD framework detected')
michael@0 1350 original_python = os.path.join(prefix, 'bin/python')
michael@0 1351 shutil.copy(original_python, py_executable)
michael@0 1352
michael@0 1353 # Copy the framework's dylib into the virtual
michael@0 1354 # environment
michael@0 1355 virtual_lib = os.path.join(home_dir, '.Python')
michael@0 1356
michael@0 1357 if os.path.exists(virtual_lib):
michael@0 1358 os.unlink(virtual_lib)
michael@0 1359 copyfile(
michael@0 1360 os.path.join(prefix, 'Python'),
michael@0 1361 virtual_lib,
michael@0 1362 symlink)
michael@0 1363
michael@0 1364 # And then change the install_name of the copied python executable
michael@0 1365 try:
michael@0 1366 mach_o_change(py_executable,
michael@0 1367 os.path.join(prefix, 'Python'),
michael@0 1368 '@executable_path/../.Python')
michael@0 1369 except:
michael@0 1370 e = sys.exc_info()[1]
michael@0 1371 logger.warn("Could not call mach_o_change: %s. "
michael@0 1372 "Trying to call install_name_tool instead." % e)
michael@0 1373 try:
michael@0 1374 call_subprocess(
michael@0 1375 ["install_name_tool", "-change",
michael@0 1376 os.path.join(prefix, 'Python'),
michael@0 1377 '@executable_path/../.Python',
michael@0 1378 py_executable])
michael@0 1379 except:
michael@0 1380 logger.fatal("Could not call install_name_tool -- you must "
michael@0 1381 "have Apple's development tools installed")
michael@0 1382 raise
michael@0 1383
michael@0 1384 if not is_win:
michael@0 1385 # Ensure that 'python', 'pythonX' and 'pythonX.Y' all exist
michael@0 1386 py_exe_version_major = 'python%s' % sys.version_info[0]
michael@0 1387 py_exe_version_major_minor = 'python%s.%s' % (
michael@0 1388 sys.version_info[0], sys.version_info[1])
michael@0 1389 py_exe_no_version = 'python'
michael@0 1390 required_symlinks = [ py_exe_no_version, py_exe_version_major,
michael@0 1391 py_exe_version_major_minor ]
michael@0 1392
michael@0 1393 py_executable_base = os.path.basename(py_executable)
michael@0 1394
michael@0 1395 if py_executable_base in required_symlinks:
michael@0 1396 # Don't try to symlink to yourself.
michael@0 1397 required_symlinks.remove(py_executable_base)
michael@0 1398
michael@0 1399 for pth in required_symlinks:
michael@0 1400 full_pth = join(bin_dir, pth)
michael@0 1401 if os.path.exists(full_pth):
michael@0 1402 os.unlink(full_pth)
michael@0 1403 if symlink:
michael@0 1404 os.symlink(py_executable_base, full_pth)
michael@0 1405 else:
michael@0 1406 copyfile(py_executable, full_pth, symlink)
michael@0 1407
michael@0 1408 if is_win and ' ' in py_executable:
michael@0 1409 # There's a bug with subprocess on Windows when using a first
michael@0 1410 # argument that has a space in it. Instead we have to quote
michael@0 1411 # the value:
michael@0 1412 py_executable = '"%s"' % py_executable
michael@0 1413 # NOTE: keep this check as one line, cmd.exe doesn't cope with line breaks
michael@0 1414 cmd = [py_executable, '-c', 'import sys;out=sys.stdout;'
michael@0 1415 'getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))']
michael@0 1416 logger.info('Testing executable with %s %s "%s"' % tuple(cmd))
michael@0 1417 try:
michael@0 1418 proc = subprocess.Popen(cmd,
michael@0 1419 stdout=subprocess.PIPE)
michael@0 1420 proc_stdout, proc_stderr = proc.communicate()
michael@0 1421 except OSError:
michael@0 1422 e = sys.exc_info()[1]
michael@0 1423 if e.errno == errno.EACCES:
michael@0 1424 logger.fatal('ERROR: The executable %s could not be run: %s' % (py_executable, e))
michael@0 1425 sys.exit(100)
michael@0 1426 else:
michael@0 1427 raise e
michael@0 1428
michael@0 1429 proc_stdout = proc_stdout.strip().decode("utf-8")
michael@0 1430 proc_stdout = os.path.normcase(os.path.abspath(proc_stdout))
michael@0 1431 norm_home_dir = os.path.normcase(os.path.abspath(home_dir))
michael@0 1432 if hasattr(norm_home_dir, 'decode'):
michael@0 1433 norm_home_dir = norm_home_dir.decode(sys.getfilesystemencoding())
michael@0 1434 if proc_stdout != norm_home_dir:
michael@0 1435 logger.fatal(
michael@0 1436 'ERROR: The executable %s is not functioning' % py_executable)
michael@0 1437 logger.fatal(
michael@0 1438 'ERROR: It thinks sys.prefix is %r (should be %r)'
michael@0 1439 % (proc_stdout, norm_home_dir))
michael@0 1440 logger.fatal(
michael@0 1441 'ERROR: virtualenv is not compatible with this system or executable')
michael@0 1442 if is_win:
michael@0 1443 logger.fatal(
michael@0 1444 'Note: some Windows users have reported this error when they '
michael@0 1445 'installed Python for "Only this user" or have multiple '
michael@0 1446 'versions of Python installed. Copying the appropriate '
michael@0 1447 'PythonXX.dll to the virtualenv Scripts/ directory may fix '
michael@0 1448 'this problem.')
michael@0 1449 sys.exit(100)
michael@0 1450 else:
michael@0 1451 logger.info('Got sys.prefix result: %r' % proc_stdout)
michael@0 1452
michael@0 1453 pydistutils = os.path.expanduser('~/.pydistutils.cfg')
michael@0 1454 if os.path.exists(pydistutils):
michael@0 1455 logger.notify('Please make sure you remove any previous custom paths from '
michael@0 1456 'your %s file.' % pydistutils)
michael@0 1457 ## FIXME: really this should be calculated earlier
michael@0 1458
michael@0 1459 fix_local_scheme(home_dir, symlink)
michael@0 1460
michael@0 1461 if site_packages:
michael@0 1462 if os.path.exists(site_packages_filename):
michael@0 1463 logger.info('Deleting %s' % site_packages_filename)
michael@0 1464 os.unlink(site_packages_filename)
michael@0 1465
michael@0 1466 return py_executable
michael@0 1467
michael@0 1468
michael@0 1469 def install_activate(home_dir, bin_dir, prompt=None):
michael@0 1470 home_dir = os.path.abspath(home_dir)
michael@0 1471 if is_win or is_jython and os._name == 'nt':
michael@0 1472 files = {
michael@0 1473 'activate.bat': ACTIVATE_BAT,
michael@0 1474 'deactivate.bat': DEACTIVATE_BAT,
michael@0 1475 'activate.ps1': ACTIVATE_PS,
michael@0 1476 }
michael@0 1477
michael@0 1478 # MSYS needs paths of the form /c/path/to/file
michael@0 1479 drive, tail = os.path.splitdrive(home_dir.replace(os.sep, '/'))
michael@0 1480 home_dir_msys = (drive and "/%s%s" or "%s%s") % (drive[:1], tail)
michael@0 1481
michael@0 1482 # Run-time conditional enables (basic) Cygwin compatibility
michael@0 1483 home_dir_sh = ("""$(if [ "$OSTYPE" "==" "cygwin" ]; then cygpath -u '%s'; else echo '%s'; fi;)""" %
michael@0 1484 (home_dir, home_dir_msys))
michael@0 1485 files['activate'] = ACTIVATE_SH.replace('__VIRTUAL_ENV__', home_dir_sh)
michael@0 1486
michael@0 1487 else:
michael@0 1488 files = {'activate': ACTIVATE_SH}
michael@0 1489
michael@0 1490 # suppling activate.fish in addition to, not instead of, the
michael@0 1491 # bash script support.
michael@0 1492 files['activate.fish'] = ACTIVATE_FISH
michael@0 1493
michael@0 1494 # same for csh/tcsh support...
michael@0 1495 files['activate.csh'] = ACTIVATE_CSH
michael@0 1496
michael@0 1497 files['activate_this.py'] = ACTIVATE_THIS
michael@0 1498 if hasattr(home_dir, 'decode'):
michael@0 1499 home_dir = home_dir.decode(sys.getfilesystemencoding())
michael@0 1500 vname = os.path.basename(home_dir)
michael@0 1501 for name, content in files.items():
michael@0 1502 content = content.replace('__VIRTUAL_PROMPT__', prompt or '')
michael@0 1503 content = content.replace('__VIRTUAL_WINPROMPT__', prompt or '(%s)' % vname)
michael@0 1504 content = content.replace('__VIRTUAL_ENV__', home_dir)
michael@0 1505 content = content.replace('__VIRTUAL_NAME__', vname)
michael@0 1506 content = content.replace('__BIN_NAME__', os.path.basename(bin_dir))
michael@0 1507 writefile(os.path.join(bin_dir, name), content)
michael@0 1508
michael@0 1509 def install_distutils(home_dir):
michael@0 1510 distutils_path = change_prefix(distutils.__path__[0], home_dir)
michael@0 1511 mkdir(distutils_path)
michael@0 1512 ## FIXME: maybe this prefix setting should only be put in place if
michael@0 1513 ## there's a local distutils.cfg with a prefix setting?
michael@0 1514 home_dir = os.path.abspath(home_dir)
michael@0 1515 ## FIXME: this is breaking things, removing for now:
michael@0 1516 #distutils_cfg = DISTUTILS_CFG + "\n[install]\nprefix=%s\n" % home_dir
michael@0 1517 writefile(os.path.join(distutils_path, '__init__.py'), DISTUTILS_INIT)
michael@0 1518 writefile(os.path.join(distutils_path, 'distutils.cfg'), DISTUTILS_CFG, overwrite=False)
michael@0 1519
michael@0 1520 def fix_local_scheme(home_dir, symlink=True):
michael@0 1521 """
michael@0 1522 Platforms that use the "posix_local" install scheme (like Ubuntu with
michael@0 1523 Python 2.7) need to be given an additional "local" location, sigh.
michael@0 1524 """
michael@0 1525 try:
michael@0 1526 import sysconfig
michael@0 1527 except ImportError:
michael@0 1528 pass
michael@0 1529 else:
michael@0 1530 if sysconfig._get_default_scheme() == 'posix_local':
michael@0 1531 local_path = os.path.join(home_dir, 'local')
michael@0 1532 if not os.path.exists(local_path):
michael@0 1533 os.mkdir(local_path)
michael@0 1534 for subdir_name in os.listdir(home_dir):
michael@0 1535 if subdir_name == 'local':
michael@0 1536 continue
michael@0 1537 copyfile(os.path.abspath(os.path.join(home_dir, subdir_name)), \
michael@0 1538 os.path.join(local_path, subdir_name), symlink)
michael@0 1539
michael@0 1540 def fix_lib64(lib_dir, symlink=True):
michael@0 1541 """
michael@0 1542 Some platforms (particularly Gentoo on x64) put things in lib64/pythonX.Y
michael@0 1543 instead of lib/pythonX.Y. If this is such a platform we'll just create a
michael@0 1544 symlink so lib64 points to lib
michael@0 1545 """
michael@0 1546 if [p for p in distutils.sysconfig.get_config_vars().values()
michael@0 1547 if isinstance(p, basestring) and 'lib64' in p]:
michael@0 1548 # PyPy's library path scheme is not affected by this.
michael@0 1549 # Return early or we will die on the following assert.
michael@0 1550 if is_pypy:
michael@0 1551 logger.debug('PyPy detected, skipping lib64 symlinking')
michael@0 1552 return
michael@0 1553
michael@0 1554 logger.debug('This system uses lib64; symlinking lib64 to lib')
michael@0 1555
michael@0 1556 assert os.path.basename(lib_dir) == 'python%s' % sys.version[:3], (
michael@0 1557 "Unexpected python lib dir: %r" % lib_dir)
michael@0 1558 lib_parent = os.path.dirname(lib_dir)
michael@0 1559 top_level = os.path.dirname(lib_parent)
michael@0 1560 lib_dir = os.path.join(top_level, 'lib')
michael@0 1561 lib64_link = os.path.join(top_level, 'lib64')
michael@0 1562 assert os.path.basename(lib_parent) == 'lib', (
michael@0 1563 "Unexpected parent dir: %r" % lib_parent)
michael@0 1564 if os.path.lexists(lib64_link):
michael@0 1565 return
michael@0 1566 cp_or_ln = (os.symlink if symlink else copyfile)
michael@0 1567 cp_or_ln('lib', lib64_link)
michael@0 1568
michael@0 1569 def resolve_interpreter(exe):
michael@0 1570 """
michael@0 1571 If the executable given isn't an absolute path, search $PATH for the interpreter
michael@0 1572 """
michael@0 1573 # If the "executable" is a version number, get the installed executable for
michael@0 1574 # that version
michael@0 1575 python_versions = get_installed_pythons()
michael@0 1576 if exe in python_versions:
michael@0 1577 exe = python_versions[exe]
michael@0 1578
michael@0 1579 if os.path.abspath(exe) != exe:
michael@0 1580 paths = os.environ.get('PATH', '').split(os.pathsep)
michael@0 1581 for path in paths:
michael@0 1582 if os.path.exists(os.path.join(path, exe)):
michael@0 1583 exe = os.path.join(path, exe)
michael@0 1584 break
michael@0 1585 if not os.path.exists(exe):
michael@0 1586 logger.fatal('The executable %s (from --python=%s) does not exist' % (exe, exe))
michael@0 1587 raise SystemExit(3)
michael@0 1588 if not is_executable(exe):
michael@0 1589 logger.fatal('The executable %s (from --python=%s) is not executable' % (exe, exe))
michael@0 1590 raise SystemExit(3)
michael@0 1591 return exe
michael@0 1592
michael@0 1593 def is_executable(exe):
michael@0 1594 """Checks a file is executable"""
michael@0 1595 return os.access(exe, os.X_OK)
michael@0 1596
michael@0 1597 ############################################################
michael@0 1598 ## Relocating the environment:
michael@0 1599
michael@0 1600 def make_environment_relocatable(home_dir):
michael@0 1601 """
michael@0 1602 Makes the already-existing environment use relative paths, and takes out
michael@0 1603 the #!-based environment selection in scripts.
michael@0 1604 """
michael@0 1605 home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
michael@0 1606 activate_this = os.path.join(bin_dir, 'activate_this.py')
michael@0 1607 if not os.path.exists(activate_this):
michael@0 1608 logger.fatal(
michael@0 1609 'The environment doesn\'t have a file %s -- please re-run virtualenv '
michael@0 1610 'on this environment to update it' % activate_this)
michael@0 1611 fixup_scripts(home_dir, bin_dir)
michael@0 1612 fixup_pth_and_egg_link(home_dir)
michael@0 1613 ## FIXME: need to fix up distutils.cfg
michael@0 1614
michael@0 1615 OK_ABS_SCRIPTS = ['python', 'python%s' % sys.version[:3],
michael@0 1616 'activate', 'activate.bat', 'activate_this.py',
michael@0 1617 'activate.fish', 'activate.csh']
michael@0 1618
michael@0 1619 def fixup_scripts(home_dir, bin_dir):
michael@0 1620 if is_win:
michael@0 1621 new_shebang_args = (
michael@0 1622 '%s /c' % os.path.normcase(os.environ.get('COMSPEC', 'cmd.exe')),
michael@0 1623 '', '.exe')
michael@0 1624 else:
michael@0 1625 new_shebang_args = ('/usr/bin/env', sys.version[:3], '')
michael@0 1626
michael@0 1627 # This is what we expect at the top of scripts:
michael@0 1628 shebang = '#!%s' % os.path.normcase(os.path.join(
michael@0 1629 os.path.abspath(bin_dir), 'python%s' % new_shebang_args[2]))
michael@0 1630 # This is what we'll put:
michael@0 1631 new_shebang = '#!%s python%s%s' % new_shebang_args
michael@0 1632
michael@0 1633 for filename in os.listdir(bin_dir):
michael@0 1634 filename = os.path.join(bin_dir, filename)
michael@0 1635 if not os.path.isfile(filename):
michael@0 1636 # ignore subdirs, e.g. .svn ones.
michael@0 1637 continue
michael@0 1638 f = open(filename, 'rb')
michael@0 1639 try:
michael@0 1640 try:
michael@0 1641 lines = f.read().decode('utf-8').splitlines()
michael@0 1642 except UnicodeDecodeError:
michael@0 1643 # This is probably a binary program instead
michael@0 1644 # of a script, so just ignore it.
michael@0 1645 continue
michael@0 1646 finally:
michael@0 1647 f.close()
michael@0 1648 if not lines:
michael@0 1649 logger.warn('Script %s is an empty file' % filename)
michael@0 1650 continue
michael@0 1651
michael@0 1652 old_shebang = lines[0].strip()
michael@0 1653 old_shebang = old_shebang[0:2] + os.path.normcase(old_shebang[2:])
michael@0 1654
michael@0 1655 if not old_shebang.startswith(shebang):
michael@0 1656 if os.path.basename(filename) in OK_ABS_SCRIPTS:
michael@0 1657 logger.debug('Cannot make script %s relative' % filename)
michael@0 1658 elif lines[0].strip() == new_shebang:
michael@0 1659 logger.info('Script %s has already been made relative' % filename)
michael@0 1660 else:
michael@0 1661 logger.warn('Script %s cannot be made relative (it\'s not a normal script that starts with %s)'
michael@0 1662 % (filename, shebang))
michael@0 1663 continue
michael@0 1664 logger.notify('Making script %s relative' % filename)
michael@0 1665 script = relative_script([new_shebang] + lines[1:])
michael@0 1666 f = open(filename, 'wb')
michael@0 1667 f.write('\n'.join(script).encode('utf-8'))
michael@0 1668 f.close()
michael@0 1669
michael@0 1670 def relative_script(lines):
michael@0 1671 "Return a script that'll work in a relocatable environment."
michael@0 1672 activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activate_this"
michael@0 1673 # Find the last future statement in the script. If we insert the activation
michael@0 1674 # line before a future statement, Python will raise a SyntaxError.
michael@0 1675 activate_at = None
michael@0 1676 for idx, line in reversed(list(enumerate(lines))):
michael@0 1677 if line.split()[:3] == ['from', '__future__', 'import']:
michael@0 1678 activate_at = idx + 1
michael@0 1679 break
michael@0 1680 if activate_at is None:
michael@0 1681 # Activate after the shebang.
michael@0 1682 activate_at = 1
michael@0 1683 return lines[:activate_at] + ['', activate, ''] + lines[activate_at:]
michael@0 1684
michael@0 1685 def fixup_pth_and_egg_link(home_dir, sys_path=None):
michael@0 1686 """Makes .pth and .egg-link files use relative paths"""
michael@0 1687 home_dir = os.path.normcase(os.path.abspath(home_dir))
michael@0 1688 if sys_path is None:
michael@0 1689 sys_path = sys.path
michael@0 1690 for path in sys_path:
michael@0 1691 if not path:
michael@0 1692 path = '.'
michael@0 1693 if not os.path.isdir(path):
michael@0 1694 continue
michael@0 1695 path = os.path.normcase(os.path.abspath(path))
michael@0 1696 if not path.startswith(home_dir):
michael@0 1697 logger.debug('Skipping system (non-environment) directory %s' % path)
michael@0 1698 continue
michael@0 1699 for filename in os.listdir(path):
michael@0 1700 filename = os.path.join(path, filename)
michael@0 1701 if filename.endswith('.pth'):
michael@0 1702 if not os.access(filename, os.W_OK):
michael@0 1703 logger.warn('Cannot write .pth file %s, skipping' % filename)
michael@0 1704 else:
michael@0 1705 fixup_pth_file(filename)
michael@0 1706 if filename.endswith('.egg-link'):
michael@0 1707 if not os.access(filename, os.W_OK):
michael@0 1708 logger.warn('Cannot write .egg-link file %s, skipping' % filename)
michael@0 1709 else:
michael@0 1710 fixup_egg_link(filename)
michael@0 1711
michael@0 1712 def fixup_pth_file(filename):
michael@0 1713 lines = []
michael@0 1714 prev_lines = []
michael@0 1715 f = open(filename)
michael@0 1716 prev_lines = f.readlines()
michael@0 1717 f.close()
michael@0 1718 for line in prev_lines:
michael@0 1719 line = line.strip()
michael@0 1720 if (not line or line.startswith('#') or line.startswith('import ')
michael@0 1721 or os.path.abspath(line) != line):
michael@0 1722 lines.append(line)
michael@0 1723 else:
michael@0 1724 new_value = make_relative_path(filename, line)
michael@0 1725 if line != new_value:
michael@0 1726 logger.debug('Rewriting path %s as %s (in %s)' % (line, new_value, filename))
michael@0 1727 lines.append(new_value)
michael@0 1728 if lines == prev_lines:
michael@0 1729 logger.info('No changes to .pth file %s' % filename)
michael@0 1730 return
michael@0 1731 logger.notify('Making paths in .pth file %s relative' % filename)
michael@0 1732 f = open(filename, 'w')
michael@0 1733 f.write('\n'.join(lines) + '\n')
michael@0 1734 f.close()
michael@0 1735
michael@0 1736 def fixup_egg_link(filename):
michael@0 1737 f = open(filename)
michael@0 1738 link = f.readline().strip()
michael@0 1739 f.close()
michael@0 1740 if os.path.abspath(link) != link:
michael@0 1741 logger.debug('Link in %s already relative' % filename)
michael@0 1742 return
michael@0 1743 new_link = make_relative_path(filename, link)
michael@0 1744 logger.notify('Rewriting link %s in %s as %s' % (link, filename, new_link))
michael@0 1745 f = open(filename, 'w')
michael@0 1746 f.write(new_link)
michael@0 1747 f.close()
michael@0 1748
michael@0 1749 def make_relative_path(source, dest, dest_is_directory=True):
michael@0 1750 """
michael@0 1751 Make a filename relative, where the filename is dest, and it is
michael@0 1752 being referred to from the filename source.
michael@0 1753
michael@0 1754 >>> make_relative_path('/usr/share/something/a-file.pth',
michael@0 1755 ... '/usr/share/another-place/src/Directory')
michael@0 1756 '../another-place/src/Directory'
michael@0 1757 >>> make_relative_path('/usr/share/something/a-file.pth',
michael@0 1758 ... '/home/user/src/Directory')
michael@0 1759 '../../../home/user/src/Directory'
michael@0 1760 >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
michael@0 1761 './'
michael@0 1762 """
michael@0 1763 source = os.path.dirname(source)
michael@0 1764 if not dest_is_directory:
michael@0 1765 dest_filename = os.path.basename(dest)
michael@0 1766 dest = os.path.dirname(dest)
michael@0 1767 dest = os.path.normpath(os.path.abspath(dest))
michael@0 1768 source = os.path.normpath(os.path.abspath(source))
michael@0 1769 dest_parts = dest.strip(os.path.sep).split(os.path.sep)
michael@0 1770 source_parts = source.strip(os.path.sep).split(os.path.sep)
michael@0 1771 while dest_parts and source_parts and dest_parts[0] == source_parts[0]:
michael@0 1772 dest_parts.pop(0)
michael@0 1773 source_parts.pop(0)
michael@0 1774 full_parts = ['..']*len(source_parts) + dest_parts
michael@0 1775 if not dest_is_directory:
michael@0 1776 full_parts.append(dest_filename)
michael@0 1777 if not full_parts:
michael@0 1778 # Special case for the current directory (otherwise it'd be '')
michael@0 1779 return './'
michael@0 1780 return os.path.sep.join(full_parts)
michael@0 1781
michael@0 1782
michael@0 1783
michael@0 1784 ############################################################
michael@0 1785 ## Bootstrap script creation:
michael@0 1786
michael@0 1787 def create_bootstrap_script(extra_text, python_version=''):
michael@0 1788 """
michael@0 1789 Creates a bootstrap script, which is like this script but with
michael@0 1790 extend_parser, adjust_options, and after_install hooks.
michael@0 1791
michael@0 1792 This returns a string that (written to disk of course) can be used
michael@0 1793 as a bootstrap script with your own customizations. The script
michael@0 1794 will be the standard virtualenv.py script, with your extra text
michael@0 1795 added (your extra text should be Python code).
michael@0 1796
michael@0 1797 If you include these functions, they will be called:
michael@0 1798
michael@0 1799 ``extend_parser(optparse_parser)``:
michael@0 1800 You can add or remove options from the parser here.
michael@0 1801
michael@0 1802 ``adjust_options(options, args)``:
michael@0 1803 You can change options here, or change the args (if you accept
michael@0 1804 different kinds of arguments, be sure you modify ``args`` so it is
michael@0 1805 only ``[DEST_DIR]``).
michael@0 1806
michael@0 1807 ``after_install(options, home_dir)``:
michael@0 1808
michael@0 1809 After everything is installed, this function is called. This
michael@0 1810 is probably the function you are most likely to use. An
michael@0 1811 example would be::
michael@0 1812
michael@0 1813 def after_install(options, home_dir):
michael@0 1814 subprocess.call([join(home_dir, 'bin', 'easy_install'),
michael@0 1815 'MyPackage'])
michael@0 1816 subprocess.call([join(home_dir, 'bin', 'my-package-script'),
michael@0 1817 'setup', home_dir])
michael@0 1818
michael@0 1819 This example immediately installs a package, and runs a setup
michael@0 1820 script from that package.
michael@0 1821
michael@0 1822 If you provide something like ``python_version='2.5'`` then the
michael@0 1823 script will start with ``#!/usr/bin/env python2.5`` instead of
michael@0 1824 ``#!/usr/bin/env python``. You can use this when the script must
michael@0 1825 be run with a particular Python version.
michael@0 1826 """
michael@0 1827 filename = __file__
michael@0 1828 if filename.endswith('.pyc'):
michael@0 1829 filename = filename[:-1]
michael@0 1830 f = codecs.open(filename, 'r', encoding='utf-8')
michael@0 1831 content = f.read()
michael@0 1832 f.close()
michael@0 1833 py_exe = 'python%s' % python_version
michael@0 1834 content = (('#!/usr/bin/env %s\n' % py_exe)
michael@0 1835 + '## WARNING: This file is generated\n'
michael@0 1836 + content)
michael@0 1837 return content.replace('##EXT' 'END##', extra_text)
michael@0 1838
michael@0 1839 ##EXTEND##
michael@0 1840
michael@0 1841 def convert(s):
michael@0 1842 b = base64.b64decode(s.encode('ascii'))
michael@0 1843 return zlib.decompress(b).decode('utf-8')
michael@0 1844
michael@0 1845 ##file site.py
michael@0 1846 SITE_PY = convert("""
michael@0 1847 eJzFPf1z2zaWv/OvwMqToZTIdOJ0e3tOnRsncVrvuYm3SWdz63q0lARZrCmSJUjL2pu7v/3eBwAC
michael@0 1848 JCXbm+6cphNLJPDw8PC+8PAeOhgMTopCZnOxyud1KoWScTlbiiKulkos8lJUy6Sc7xdxWW3g6ewm
michael@0 1849 vpZKVLlQGxVhqygInn7lJ3gqPi8TZVCAb3Fd5au4SmZxmm5EsiryspJzMa/LJLsWSZZUSZwm/4AW
michael@0 1850 eRaJp1+PQXCWCZh5mshS3MpSAVwl8oW42FTLPBPDusA5v4j+GL8cjYWalUlRQYNS4wwUWcZVkEk5
michael@0 1851 BzShZa2AlEkl91UhZ8kimdmG67xO56JI45kUf/87T42ahmGg8pVcL2UpRQbIAEwJsArEA74mpZjl
michael@0 1852 cxkJ8UbOYhyAnzfEChjaGNdMIRmzXKR5dg1zyuRMKhWXGzGc1hUBIpTFPAecEsCgStI0WOfljRrB
michael@0 1853 ktJ6rOGRiJk9/Mkwe8A8cfwu5wCOH7Pg5yy5GzNs4B4EVy2ZbUq5SO5EjGDhp7yTs4l+NkwWYp4s
michael@0 1854 FkCDrBphk4ARUCJNpgcFLcd3eoVeHxBWlitjGEMiytyYX1KPKDirRJwqYNu6QBopwvydnCZxBtTI
michael@0 1855 bmE4gAgkDfrGmSeqsuPQ7EQOAEpcxwqkZKXEcBUnGTDrj/GM0P5rks3ztRoRBWC1lPi1VpU7/2EP
michael@0 1856 AaC1Q4BxgItlVrPO0uRGppsRIPAZsC+lqtMKBWKelHJW5WUiFQEA1DZC3gHSYxGXUpOQOdPI7Zjo
michael@0 1857 TzRJMlxYFDAUeHyJJFkk13VJEiYWCXAucMX7jz+Jd6dvzk4+aB4zwFhmr1eAM0ChhXZwggHEQa3K
michael@0 1858 gzQHgY6Cc/wj4vkchewaxwe8mgYH9650MIS5F1G7j7PgQHa9uHoYmGMFyoTGCqjff0OXsVoCff7n
michael@0 1859 nvUOgpNtVKGJ87f1MgeZzOKVFMuY+Qs5I/hOw3kdFdXyFXCDQjgVkErh4iCCCcIDkrg0G+aZFAWw
michael@0 1860 WJpkchQAhabU1l9FYIUPebZPa93iBIBQBhm8dJ6NaMRMwkS7sF6hvjCNNzQz3SSw67zKS1IcwP/Z
michael@0 1861 jHRRGmc3hKMihuJvU3mdZBkihLwQhHshDaxuEuDEeSTOqRXpBdNIhKy9uCWKRA28hEwHPCnv4lWR
michael@0 1862 yjGLL+rW3WqEBpOVMGudMsdBy4rUK61aM9Ve3juMvrS4jtCslqUE4PXUE7pFno/FFHQ2YVPEKxav
michael@0 1863 ap0T5wQ98kSdkCeoJfTF70DRE6XqlbQvkVdAsxBDBYs8TfM1kOwoCITYw0bGKPvMCW/hHfwLcPHf
michael@0 1864 VFazZRA4I1nAGhQivw0UAgGTIDPN1RoJj9s0K7eVTJKxpsjLuSxpqIcR+4ARf2BjnGvwIa+0UePp
michael@0 1865 4irnq6RClTTVJjNhi5eFFevHVzxvmAZYbkU0M00bOq1wemmxjKfSuCRTuUBJ0Iv0yi47jBn0jEm2
michael@0 1866 uBIrtjLwDsgiE7Yg/YoFlc6ikuQEAAwWvjhLijqlRgoZTMQw0Kog+KsYTXqunSVgbzbLASokNt8z
michael@0 1867 sD+A2z9AjNbLBOgzAwigYVBLwfJNk6pEB6HRR4Fv9E1/Hh849WyhbRMPuYiTVFv5OAvO6OFpWZL4
michael@0 1868 zmSBvcaaGApmmFXo2l1nQEcU88FgEATGHdoo8zVXQVVujoAVhBlnMpnWCRq+yQRNvf6hAh5FOAN7
michael@0 1869 3Ww7Cw80hOn0AajkdFmU+Qpf27l9AmUCY2GPYE9ckJaR7CB7nPgKyeeq9MI0RdvtsLNAPRRc/HT6
michael@0 1870 /uzL6SdxLC4blTZu67MrGPM0i4GtySIAU7WGbXQZtETFl6DuE+/BvBNTgD2j3iS+Mq5q4F1A/XNZ
michael@0 1871 02uYxsx7GZx+OHlzfjr5+dPpT5NPZ59PAUGwMzLYoymjeazBYVQRCAdw5VxF2r4GnR704M3JJ/sg
michael@0 1872 mCRq8u03wG7wZHgtK2DicggzHotwFd8pYNBwTE1HiGOnAVjwcDQSr8Xh06cvDwlasSk2AAzMrtMU
michael@0 1873 H060RZ8k2SIPR9T4V3bpj1lJaf/t8uibK3F8LMJf49s4DMCHapoyS/xI4vR5U0joWsGfYa5GQTCX
michael@0 1874 CxC9G4kCOnxKfvGIO8CSQMtc2+lf8yQz75kr3SFIfwypB+AwmczSWClsPJmEQATq0POBDhE71yh1
michael@0 1875 Q+hYbNyuI40KfkoJC5thlzH+04NiPKV+iAaj6HYxjUBcV7NYSW5F04d+kwnqrMlkqAcEYSaJAYeL
michael@0 1876 1VAoTBPUWWUCfi1xHuqwqcpT/InwUQuQAOLWCrUkLpLeOkW3cVpLNXQmBUQcDltkREWbKOJHcFGG
michael@0 1877 YImbpRuN2tQ0PAPNgHxpDlq0bFEOP3vg74C6Mps43Ojx3otphpj+mXcahAO4nCGqe6VaUFg7iovT
michael@0 1878 C/Hy+eE+ujOw55xb6njN0UInWS3twwWslpEHRph7GXlx6bJAPYtPj3bDXEV2ZbqssNBLXMpVfivn
michael@0 1879 gC0ysLPK4id6AztzmMcshlUEvU7+AKtQ4zfGuA/l2YO0oO8A1FsRFLP+Zun3OBggMwWKiDfWRGq9
michael@0 1880 62dTWJT5bYLOxnSjX4KtBGWJFtM4NoGzcB6ToUkEDQFecIaUWssQ1GFZs8NKeCNItBfzRrFGBO4c
michael@0 1881 NfUVfb3J8nU24Z3wMSrd4ciyLgqWZl5s0CzBnngPVgiQzGFj1xCNoYDLL1C29gF5mD5MFyhLewsA
michael@0 1882 BIZe0XbNgWW2ejRF3jXisAhj9EqQ8JYS/YVbMwRttQwxHEj0NrIPjJZASDA5q+CsatBMhrJmmsHA
michael@0 1883 Dkl8rjuPeAvqA2hRMQKzOdTQuJGh3+URKGdx7iolpx9a5C9fvjDbqCXFVxCxKU4aXYgFGcuo2IBh
michael@0 1884 TUAnGI+MozXEBmtwbgFMrTRriv1PIi/YG4P1vNCyDX4A7O6qqjg6OFiv15GOLuTl9YFaHPzxT99+
michael@0 1885 +6fnrBPnc+IfmI4jLTrUFh3QO/Roo++MBXptVq7Fj0nmcyPBGkryysgVRfy+r5N5Lo72R1Z/Ihc3
michael@0 1886 Zhr/Na4MKJCJGZSpDLQdNBg9UftPopdqIJ6QdbZthyP2S7RJtVbMt7rQo8rBEwC/ZZbXaKobTlDi
michael@0 1887 GVg32KHP5bS+Du3gno00P2CqKKdDywP7L64QA58zDF8ZUzxBLUFsgRbfIf1PzDYxeUdaQyB50UR1
michael@0 1888 ds+bfi1miDt/uLxbX9MRGjPDRCF3oET4TR4sgLZxV3Lwo11btHuOa2s+niEwlj4wzKsdyyEKDuGC
michael@0 1889 azF2pc7havR4QZrWrJpBwbiqERQ0OIlTprYGRzYyRJDo3ZjNPi+sbgF0akUOTXzArAK0cMfpWLs2
michael@0 1890 KzieEPLAsXhBTyS4yEedd895aes0pYBOi0c9qjBgb6HRTufAl0MDYCwG5c8Dbmm2KR9bi8Jr0AMs
michael@0 1891 5xgQMtiiw0z4xvUBB3uDHnbqWP1tvZnGfSBwkYYci3oQdEL5mEcoFUhTMfR7bmNxS9zuYDstDjGV
michael@0 1892 WSYSabVFuNrKo1eodhqmRZKh7nUWKZqlOXjFVisSIzXvfWeB9kH4uM+YaQnUZGjI4TQ6Jm/PE8BQ
michael@0 1893 t8Pw2XWNgQY3DoMYrRJF1g3JtIR/wK2g+AYFo4CWBM2CeaiU+RP7HWTOzld/2cIeltDIEG7TbW5I
michael@0 1894 x2JoOOb9nkAy6mgMSEEGJOwKI7mOrA5S4DBngTzhhtdyq3QTjEiBnDkWhNQM4E4vvQ0OPonwBIQk
michael@0 1895 FCHfVUoW4pkYwPK1RfVhuvt35VIThBg6DchV0NGLYzey4UQ1jltRDp+h/fgGnZUUOXDwFFweN9Dv
michael@0 1896 srlhWht0AWfdV9wWKdDIFIcZjFxUrwxh3GDyH46dFg2xzCCGobyBvCMdM9IosMutQcOCGzDemrfH
michael@0 1897 0o/diAX2HYa5OpSrO9j/hWWiZrkKKWbSjl24H80VXdpYbM+T6QD+eAswGF15kGSq4xcYZfknBgk9
michael@0 1898 6GEfdG+yGBaZx+U6yUJSYJp+x/7SdPCwpPSM3MEn2k4dwEQx4nnwvgQBoaPPAxAn1ASwK5eh0m5/
michael@0 1899 F+zOKQ4sXO4+8Nzmy6OXV13ijrdFeOynf6lO76oyVrhaKS8aCwWuVteAo9KFycXZRh9e6sNt3CaU
michael@0 1900 uYJdpPj46YtAQnBcdx1vHjf1huERm3vn5H0M6qDX7iVXa3bELoAIakVklIPw8Rz5cGQfO7kdE3sE
michael@0 1901 kEcxzI5FMZA0n/wzcHYtFIyxP99kGEdrqwz8wOtvv5n0REZdJL/9ZnDPKC1i9In9sOUJ2pE5qWDX
michael@0 1902 bEsZp+RqOH0oqJg1rGPbFCPW57T90zx21eNzarRs7Lu/BX4MFAypS/ARno8bsnWnih/fndoKT9up
michael@0 1903 HcA6u1Xz2aNFgL19Pv0VdshKB9Vu4ySlcwWY/P4+Klezued4Rb/28CDtVDAOCfr2X+ryOXBDyNGE
michael@0 1904 UXc62hk7MQHnnl2w+RSx6qKyp3MImiMwLy/APf7sQtUWzDDucz5eOOxRTd6M+5yJr1Gr+PldNJAF
michael@0 1905 5tFg0Ef2rez4/zHL5/+aST5wKubk+ne0ho8E9HvNhI0HQ9PGw4fVv+yu3TXAHmCetridO9zC7tB8
michael@0 1906 Vrkwzh2rJCWeou56KtaUrkCxVTwpAihz9vt64OAy6kPvt3VZ8tE1qcBClvt4HDsWmKllPL9eE7Mn
michael@0 1907 Dj7ICjGxzWYUq3byevI+NRLq6LOdSdjsG/rlbJmbmJXMbpMS+oLCHYY/fPzxNOw3IRjHhU4PtyIP
michael@0 1908 9xsQ7iOYNtTECR/Thyn0mC7/vFS1ty4+QU1GgIkIa7L12gc/EGziCP1rcE9EyDuw5WN23KHPlnJ2
michael@0 1909 M5GUOoBsil2doPhbfI2Y2IwCP/9LxQtKYoOZzNIaacWON2YfLupsRucjlQT/SqcKY+oQJQRw+G+R
michael@0 1910 xtdiSJ3nGHrS3EjRqdu41N5nUeaYnCrqZH5wncyF/K2OU9zWy8UCcMHDK/0q4uEpAiXecU4DJy0q
michael@0 1911 OavLpNoACWKV67M/Sn9wGk43PNGhhyQf8zABMSHiSHzCaeN7JtzckMsEB/wTD5wk7ruxg5OsENFz
michael@0 1912 eJ/lExx1Qjm+Y0aqey5Pj4P2CDkAGABQmP9gpCN3/htJr9wDRlpzl6ioJT1SupGGnJwxhDIcYaSD
michael@0 1913 f9NPnxFd3tqC5fV2LK93Y3ndxvK6F8trH8vr3Vi6IoELa4NWRhL6AlftY43efBs35sTDnMazJbfD
michael@0 1914 3E/M8QSIojAbbCNTnALtRbb4fI+AkNp2DpzpYZM/k3BSaZlzCFyDRO7HQyy9mTfJ605nysbRnXkq
michael@0 1915 xp3dlkPk9z2IIkoVm1J3lrd5XMWRJxfXaT4FsbXojhsAY9FOJ+JYaXY7mXJ0t2WpBhf/9fmHjx+w
michael@0 1916 OYIamPQG6oaLiIYFpzJ8GpfXqitNzeavAHakln4iDnXTAPceGFnjUfb4n3eU4YGMI9aUoZCLAjwA
michael@0 1917 yuqyzdzcpzBsPddJUvo5MzkfNh2LQVYNmkltIdLJxcW7k88nAwr5Df534AqMoa0vHS4+poVt0PXf
michael@0 1918 3OaW4tgHhFrHthrj587Jo3XDEffbWAO248O3Hhw+xGD3hgn8Wf5LKQVLAoSKdPD3MYR68B7oq7YJ
michael@0 1919 HfoYRuwk/7kna+ys2HeO7DkuiiP6fccO7QH8w07cY0yAANqFGpqdQbOZail9a153UNQB+kBf76u3
michael@0 1920 YO2tV3sn41PUTqLHAXQoa5ttd/+8cxo2ekpWb06/P/twfvbm4uTzD44LiK7cx08Hh+L0xy+C8kPQ
michael@0 1921 gLFPFGNqRIWZSGBY3EInMc/hvxojP/O64iAx9Hp3fq5PalZY6oK5z2hzInjOaUwWGgfNOAptH+r8
michael@0 1922 I8Qo1Rskp6aI0nWo5gj3SyuuZ1G5zo+mUqUpOqu13nrpWjFTU0bn2hFIHzR2ScEgOMUMXlEWe2V2
michael@0 1923 hSWfAOo6qx6ktI22iSEpBQU76QLO+Zc5XfECpdQZnjSdtaK/DF1cw6tIFWkCO7lXoZUl3Q3TYxrG
michael@0 1924 0Q/tATfj1acBne4wsm7Is96KBVqtVyHPTfcfNYz2Ww0YNgz2DuadSUoPoQxsTG4TITbik5xQ3sFX
michael@0 1925 u/R6DRQsGB70VbiIhukSmH0Mm2uxTGADATy5BOuL+wSA0FoJ/0DgyIkOyByzM8K3q/n+X0JNEL/1
michael@0 1926 L7/0NK/KdP9vooBdkOBUorCHmG7jd7DxiWQkTj++H4WMHKXmir/UWB4ADgkFQB1pp/wlPkGfDJVM
michael@0 1927 Fzq/xNcH+EL7CfS61b2URam797vGIUrAEzUkr+GJMvQLMd3Lwh7jVEYt0Fj5YDHDCkI3DcF89sSn
michael@0 1928 pUxTne9+9u78FHxHLMZACeJzt1MYjuMleISuk++4wrEFCg/Y4XWJbFyiC0tJFvPIa9YbtEaRo95e
michael@0 1929 XoZdJwoMd3t1osBlnCgX7SFOm2GZcoIIWRnWwiwrs3arDVLYbUMUR5lhlphclJTA6vME8DI9jXlL
michael@0 1930 BHslLPUwEXg+RU6yymQspskM9CioXFCoYxASJC7WMxLn5RnHwPNSmTIoeFhsyuR6WeHpBnSOqAQD
michael@0 1931 m/948uX87AOVJRy+bLzuHuYc005gzEkkx5giiNEO+OKm/SFXTSZ9PKtfIQzUPvCn/YqzU455gE4/
michael@0 1932 Dizin/YrrkM7dnaCPANQUHXRFg/cADjd+uSmkQXG1e6D8eOmADaY+WAoFollLzrRw51flxNty5Yp
michael@0 1933 obiPefmIA5xFYVPSdGc3Ja390XNcFHjONR/2N4K3fbJlPlPoetN5sy35zf10pBBLYgGjbmt/DJMd
michael@0 1934 1mmqp+Mw2zZuoW2ttrG/ZE6s1Gk3y1CUgYhDt/PIZbJ+JaybMwd6adQdYOI7ja6RxF5VPvglG2gP
michael@0 1935 w8PEEruzTzEdqYyFjABGMqSu/anBh0KLAAqEsn+HjuSOR08PvTk61uD+OWrdBbbxB1CEOheXajzy
michael@0 1936 EjgRvvzGjiO/IrRQjx6J0PFUMpnlNk8MP+slepUv/Dn2ygAFMVHsyji7lkOGNTYwn/nE3hKCJW3r
michael@0 1937 kfoyueozLOIMnNO7LRzelYv+gxODWosROu1u5KatjnzyYIPeUpCdBPPBl/EadH9RV0NeyS3n0L21
michael@0 1938 dNuh3g8Rsw+hqT59H4YYjvkt3LI+DeBeamhY6OH9tuUUltfGOLLWPraqmkL7QnuwsxK2ZpWiYxmn
michael@0 1939 ONH4otYLaAzucWPyB/apThSyv3vqxJyYkAXKg7sgvbkNdINWOGHA5UpcOZpQOnxTTaPfzeWtTMFo
michael@0 1940 gJEdYrXDr7baYRTZcEpvHthXY3exudj040ZvGsyOTDkGIkCFGL2Bnl0INTjgCv+idyJxdkPO8du/
michael@0 1941 no3F2w8/wb9v5EewoFjzOBZ/g9HF27yEbSUX7dJtCljAUfF+Ma8VFkYSNDqh4Isn0Fu78MiLpyG6
michael@0 1942 ssQvKbEKUmAybbni204ARZ4gFbI37oGpl4DfpqCr5YQaB7FvLQb6JdJge40L1oUc6JbRslqlaCac
michael@0 1943 4EiziJeD87O3px8+nUbVHTK2+Tlwgid+HhZORx8Nl3gMNhb2yazGJ1eOv/yDTIsed1nvNU29DO41
michael@0 1944 RQjbkcLuL/kmjdjuKeISAwai2MzzWYQtgdO5RK9ag/88craV99p3z7girOFIH541Tjw+BmqIX9r6
michael@0 1945 ZwANqY+eE/UkhOIp1orx42jQb4HHgiLa8OfpzXruBsR10Q9NsI1pM+uh392qwCXTWcOznER4Hdtl
michael@0 1946 MHWgaRKr1XTm1gd+zIS+CAWUGx1vyEVcp5WQGWylaG9PN1KAgndL+lhCmFXYilGdG0Vn0nW8UU7u
michael@0 1947 UazEAEcdUFE9nsNQoBC23j/GN2wGsNZQ1FwCDdAJUdo25U5XVc+WLMG8EyLq9eQbrJPspZvGoynM
michael@0 1948 g/LGeNb4rzBP9BYZo2tZ6fnzg+Ho8kWT4EDB6JlX0DsrwNi5bLIHGrN4+vTpQPzH/U4PoxKleX4D
michael@0 1949 3hjA7nVWzun1FoOtJ2dXq+vQmzcR8ONsKS/hwRUFze3zOqOI5I6utCDS/jUwQlyb0DKjad8yxxyr
michael@0 1950 K/l8mVvwOZU2GD9nCV13hBElicpW3xqF0SYjTcSSoBjCWM2SJOToBKzHJq+xFg+ji5pf5B1wfIJg
michael@0 1951 xvgWD8Z4h71Ex5LyZi33WHSOxYAADyiljEejYmaqRgM8JxcbjebkLEuqpozkuXtmqq8AqOwtRpqv
michael@0 1952 RLxGyTDzaBHDKev0WLVxrPOdLOptVPLZpRtnbM2SX9+HO7A2SFq+WBhM4aFZpFkuy5kxp7hiySyp
michael@0 1953 HDCmHcLhznR5E1mfKOhBaQDqnazC3Eq0ffsHuy4uph/p+HjfjKSzhip7IRbHhOKslVcYRc34FH2y
michael@0 1954 hLR8a76MYJQPFM3WnoA3lviDjqViDYF3b4dbzlhn+j4OTttoLukAOHQHlFWQlh09HeFcPGbhM9Nu
michael@0 1955 uUUDP7QzJ9xuk7Kq43Sir32YoJ82sefpGk9bBrezwNN6K+Db5+D47uuMfXAcTHIN0hMzbk1FxrFY
michael@0 1956 6MhE5FaW+UVYRY5e3iH7SuBTIGXmE1MPbWJHl5ZdbaGpTtV0VDyCemaKl7Y45KZqplNw4mI+pvQm
michael@0 1957 U+6wxXn2M0fp6grxWgxfjsVha+czKzZ4kxMg+2Qe+q4YdYOpOMEAM8f2vRji9bEYvhiLP+6AHm0Z
michael@0 1958 4OjQHaG9j21B2Ark5dWjyZgmUyJb2JfCfn9fncMImp5xHF21yd8l03dEpX9vUYkrBHWi8ot2onJr
michael@0 1959 7K371s7HRzJcgeJYJHK+/0QhCTXSjW7ezuCEHxbQ79kcLV073lTUUOHcFDYj60YPOhrRuM12EFOU
michael@0 1960 rtUX1++irmHDae8cMGkyrVRFe8scpjFq9FpEBQCTvqM0/IZ3u8B7TQrXP9t6xKqLACzYngiCrvTk
michael@0 1961 A7OmYSOo9zqCj9IA9zCKCPEwtVEUrmQ9QkRCugeHmOhZ6xDb4fjfnXm4xGDbUWgHy2+/2YWnK5i9
michael@0 1962 RR09C7q70sITWVte0Sy3+fQH5jxG6ev6VQLjQGlEB5xVc1UluZlHmL3Md9DkNot5hZdB0sk0msRU
michael@0 1963 um4Tb6X51i/0Yyh2QMlksBbgSdULPEi+pbstTxQlveEVNd8cvhibymAGpCfwMnr5TF8BSd3M5Qe+
michael@0 1964 jz3Wezd4qfsdRv/mAEsqv7d91dnN0LSOW3dB+YOFFD0bRRNLh8Yw3V8H0qxZLPDOxIaY7FvbC0De
michael@0 1965 g7czBT/HXH6ag8MGG9KoD11XYzTSu021bRHg+03GNsl5UNdGkSLSu4Rtm/LcpTgfLQq6V78FwRAC
michael@0 1966 cv4y5jfoCtbFkQ2xGZuCJ59DN5sTP9VNb90Z2xM0ttVNuGv63H/X3HWLwM7cJDN05u7Xl7o00H23
michael@0 1967 W9E+GnB4QxPiQSUSjcbvNyauHRjrHJr+CL3+IPndTjjTLWblPjAmYwfj/cSeGntj9lfxzP2OCWH7
michael@0 1968 fCGzW07c62y0pt2xGW2Of4inwMkv+NzeMEAZTXPNgbxfohv2JpwjO5HX12oS4+2OE9pkUz5XZ/dk
michael@0 1969 tm3v6XI+GauN2W3hpUUAwnCTzrx1k+uBMUBX8i3TnA7l3E4jaGhKGnaykFUyZ5Ogt3YALuKIKfU3
michael@0 1970 gXhOIx6kEgPdqi6LEnbDA30XMefp9KU2N0BNAG8VqxuDuukx1lfTkmKl5DBTgsxx2laSDxCBjXjH
michael@0 1971 NEwm9h3wyvPmmoVkbJlBZvVKlnHVXDHkZwQksOlqRqCic1xcJzzXSGWLS1zEEssbDlIYILPfn8HG
michael@0 1972 0ttU77hXYWS13cPZiXrokO9jrmxwjJHh4uTOXi/oXms1p6utXe/QNmu4zl6pBMtg7sojHaljZfxW
michael@0 1973 39/Fd8xyJB/9S4d/QN7dyks/C92qM/ZuLRrOM1chdC9swhsDyDj33cPY4YDujYutDbAd39cXllE6
michael@0 1974 HuaWxpaK2ifvVTjNaKMmgoQJo/dEkPyigEdGkDz4D4wg6VszwdBofLQe6C0TuCfUxOrBvYKyYQTo
michael@0 1975 MwEi4QF26wJDYyqHbtJ9kavkbmAvlGZd6VTyGfOAHNm9m4xA8FWTys1Q9q6C2xVB8qWLHn9//vHN
michael@0 1976 yTnRYnJx8vY/T76npCw8LmnZqgeH2LJ8n6m976V/u+E2nUjTN3iDbc8NsVzDpCF03ndyEHog9Ner
michael@0 1977 9S1oW5G5r7d16NT9dDsB4run3YK6TWX3Qu74ZbrGxE2faeVpB/opJ9WaX05mgnlkTupYHJqTOPO+
michael@0 1978 OTzRMtqJLW9bOCe9tatOtL+qbwHdEvce2SRrWgE8M0H+skcmpmLGBubZQWn/bz4oMxyrDc0NOiCF
michael@0 1979 M+nc5EiXODKoyv//iZSg7GLc27GjOLZ3c1M7Ph5S9tJ5PPudycgQxCv3G3Tn5wr7XKZbqBAErPD0
michael@0 1980 PYWMiNF/+kDVph88UeJynwqL91HZXNlfuGbauf1rgkkGlb3vS3GCEh+zQuNFnbqJA7ZPpwM5fXQa
michael@0 1981 lS+cShbQfAdA50Y8FbA3+kusEKcbEcLGUbtkmBxLdNSX9TnIo910sDe0ei72t5WdumWXQrzY3nDe
michael@0 1982 quzUPQ65h7qnh6pNcZ9jgTFLc1s9qXhNkPk4U9AFX57zgWfoetsPX28vXxzZwwXkd3ztKBLKJhs4
michael@0 1983 hv3Sycbceamk052YpRxTuh7u1ZyQsG5x5UBln2Db3qZTkrJl/2PyHBjSwHvfHzIzPbyr9wdtTC3r
michael@0 1984 HcGUxPCJGtG0nCIejbt9MupOt1FbXSBckPQAIB0VCLAQTEc3OgmiG87yHj7Xu8FpTdfxuidMoSMV
michael@0 1985 lCzmcwT3ML5fg1+7OxUSP6g7o2j6c4M2B+olB+Fm34FbjbxQyHaT0J56wwdbXACuye7v/+IB/btp
michael@0 1986 jLb74S6/2rZ62VsHyL4sZr5iZlCLROZxBEYG9OaQtDWWSxhBx2toGjq6DNXMDfkCHT/KpsXLtmmD
michael@0 1987 Qc7sRHsA1igE/wfVIOdx
michael@0 1988 """)
michael@0 1989
michael@0 1990 ##file activate.sh
michael@0 1991 ACTIVATE_SH = convert("""
michael@0 1992 eJytVVFvokAQfudXTLEPtTlLeo9tvMSmJpq02hSvl7u2wRUG2QR2DSxSe7n/frOACEVNLlceRHa+
michael@0 1993 nfl25pvZDswCnoDPQ4QoTRQsENIEPci4CsBMZBq7CAsuLOYqvmYKTTj3YxnBgiXBudGBjUzBZUJI
michael@0 1994 BXEqgCvweIyuCjeG4eF2F5x14bcB9KQiQQWrjSddI1/oQIx6SYYeoFjzWIoIhYI1izlbhJjkKO7D
michael@0 1995 M/QEmKfO9O7WeRo/zr4P7pyHwWxkwitcgwpQ5Ej96OX+PmiFwLeVjFUOrNYKaq1Nud3nR2n8nI2m
michael@0 1996 k9H0friPTGVsUdptaxGrTEfpNVFEskxpXtUkkCkl1UNF9cgLBkx48J4EXyALuBtAwNYIjF5kcmUU
michael@0 1997 abMKmMq1ULoiRbgsDEkTSsKSGFCJ6Z8vY/2xYiSacmtyAfCDdCNTVZoVF8vSTQOoEwSnOrngBkws
michael@0 1998 MYGMBMg8/bMBLSYKS7pYEXP0PqT+ZmBT0Xuy+Pplj5yn4aM9nk72JD8/Wi+Gr98sD9eWSMOwkapD
michael@0 1999 BbUv91XSvmyVkICt2tmXR4tWmrcUCsjWOpw87YidEC8i0gdTSOFhouJUNxR+4NYBG0MftoCTD9F7
michael@0 2000 2rTtxG3oPwY1b2HncYwhrlmj6Wq924xtGDWqfdNxap+OYxplEurnMVo9RWks+rH8qKEtx7kZT5zJ
michael@0 2001 4H7oOFclrN6uFe+d+nW2aIUsSgs/42EIPuOhXq+jEo3S6tX6w2ilNkDnIpHCWdEQhFgwj9pkk7FN
michael@0 2002 l/y5eQvRSIQ5+TrL05lewxWpt/Lbhes5cJF3mLET1MGhcKCF+40tNWnUulxrpojwDo2sObdje3Bz
michael@0 2003 N3QeHqf3D7OjEXMVV8LN3ZlvuzoWHqiUcNKHtwNd0IbvPGKYYM31nPKCgkUILw3KL+Y8l7aO1ArS
michael@0 2004 Ad37nIU0fCj5NE5gQCuC5sOSu+UdI2NeXg/lFkQIlFpdWVaWZRfvqGiirC9o6liJ9FXGYrSY9mI1
michael@0 2005 D/Ncozgn13vJvsznr7DnkJWXsyMH7e42ljdJ+aqNDF1bFnKWFLdj31xtaJYK6EXFgqmV/ymD/ROG
michael@0 2006 +n8O9H8f5vsGOWXsL1+1k3g=
michael@0 2007 """)
michael@0 2008
michael@0 2009 ##file activate.fish
michael@0 2010 ACTIVATE_FISH = convert("""
michael@0 2011 eJydVW2P2jgQ/s6vmAZQoVpA9/WkqqJaTou0u6x2uZVOVWWZZEKsS+yc7UDpr+84bziQbauLxEvs
michael@0 2012 eXnsZ56ZIWwTYSAWKUJWGAs7hMJgBEdhEwiMKnSIsBNywUMrDtziPBYmCeBDrFUG7v8HmCTW5n8u
michael@0 2013 Fu7NJJim81Bl08EQTqqAkEupLOhCgrAQCY2hTU+DQVxIiqgkRNiEBphFEKy+kd1BaFvwFOUBuIxA
michael@0 2014 oy20BKtAKp3xFMo0QNtCK5mhtMEA6BmSpUELKo38TThwLfguRVNaiRgs0llnEoIR29zfstf18/bv
michael@0 2015 5T17Wm7vAiiN3ONCzfbfwC3DtWXXDqHfAGX0q6z/bO82j3ebh1VwnbrduwTQbvwcRtesAfMGor/W
michael@0 2016 L3fs6Xnz8LRlm9fV8/P61sM0LDNwCZjl9gSpCokJRzpryGQ5t8kNGFUt51QjOZGu0Mj35FlYlXEr
michael@0 2017 yC09EVOp4lEXfF84Lz1qbhBsgl59vDedXI3rTV03xipduSgt9kLytI3XmBp3aV6MPoMQGNUU62T6
michael@0 2018 uQdeefTy1Hfj10zVHg2pq8fXDoHBiOv94csfXwN49xECqWREy7pwukKfvxdMY2j23vXDPuuxxeE+
michael@0 2019 JOdCOhxCE3N44B1ZeSLuZh8Mmkr2wEPAmPfKWHA2uxIRjEopdbQYjDz3BWOf14/scfmwoki1eQvX
michael@0 2020 ExBdF60Mqh+Y/QcX4uiH4Amwzx79KOVFtbL63sXJbtcvy8/3q5rupmO5CnE91wBviQAhjUUegYpL
michael@0 2021 vVEbpLt2/W+PklRgq5Ku6mp+rpMhhCo/lXthQTxJ2ysO4Ka0ad97S7VT/n6YXus6fzk3fLnBZW5C
michael@0 2022 KDC6gSO62QDqgFqLCCtPmjegjnLeAdArtSE8VYGbAJ/aLb+vnQutFhk768E9uRbSxhCMzdgEveYw
michael@0 2023 IZ5ZqFKl6+kz7UR4U+buqQZXu9SIujrAfD7f0FXpozB4Q0gwp31H9mVTZGGC4b871/wm7lvyDLu1
michael@0 2024 FUyvTj/yvD66k3UPTs08x1AQQaGziOl0S1qRkPG9COtBTSTWM9NzQ4R64B+Px/l3tDzCgxv5C6Ni
michael@0 2025 e+QaF9xFWrxx0V/G5uvYQOdiZzvYpQUVQSIsTr1TTghI33GnPbTA7/GCqcE3oE3GZurq4HeQXQD6
michael@0 2026 32XS1ITj/qLjN72ob0hc5C9bzw8MhfmL
michael@0 2027 """)
michael@0 2028
michael@0 2029 ##file activate.csh
michael@0 2030 ACTIVATE_CSH = convert("""
michael@0 2031 eJx9VG1P2zAQ/u5fcYQKNgTNPtN1WxlIQ4KCUEGaxuQ6yYVYSuzKdhqVX7+zk3bpy5YPUXL3PPfc
michael@0 2032 ne98DLNCWshliVDV1kGCUFvMoJGugMjq2qQIiVSxSJ1cCofD1BYRnOVGV0CfZ0N2DD91DalQSjsw
michael@0 2033 tQLpIJMGU1euvPe7QeJlkKzgWixlhnAt4aoUVsLnLBiy5NtbJWQ5THX1ZciYKKWwkOFaE04dUm6D
michael@0 2034 r/zh7pq/3D7Nnid3/HEy+wFHY/gEJydg0aFaQrBFgz1c5DG1IhTs+UZgsBC2GMFBlaeH+8dZXwcW
michael@0 2035 VPvCjXdlAvCfQsE7al0+07XjZvrSCUevR5dnkVeKlFYZmUztG4BdzL2u9KyLVabTU0bdfg7a0hgs
michael@0 2036 cSmUg6UwUiQl2iHrcbcVGNvPCiLOe7+cRwG13z9qRGgx2z6DHjfm/Op2yqeT+xvOLzs0PTKHDz2V
michael@0 2037 tkckFHoQfQRXoGJAj9el0FyJCmEMhzgMS4sB7KPOE2ExoLcSieYwDvR+cP8cg11gKkVJc2wRcm1g
michael@0 2038 QhYFlXiTaTfO2ki0fQoiFM4tLuO4aZrhOzqR4dIPcWx17hphMBY+Srwh7RTyN83XOWkcSPh1Pg/k
michael@0 2039 TXX/jbJTbMtUmcxZ+/bbqOsy82suFQg/BhdSOTRhMNBHlUarCpU7JzBhmkKmRejKOQzayQe6MWoa
michael@0 2040 n1wqWmuh6LZAaHxcdeqIlVLhIBJdO9/kbl0It2oEXQj+eGjJOuvOIR/YGRqvFhttUB2XTvLXYN2H
michael@0 2041 37CBdbW2W7j2r2+VsCn0doVWcFG1/4y1VwBjfwAyoZhD
michael@0 2042 """)
michael@0 2043
michael@0 2044 ##file activate.bat
michael@0 2045 ACTIVATE_BAT = convert("""
michael@0 2046 eJx9UdEKgjAUfW6wfxjiIH+hEDKUFHSKLCMI7kNOEkIf9P9pTJ3OLJ/03HPPPed4Es9XS9qqwqgT
michael@0 2047 PbGKKOdXL4aAFS7A4gvAwgijuiKlqOpGlATS2NeMLE+TjJM9RkQ+SmqAXLrBo1LLIeLdiWlD6jZt
michael@0 2048 r7VNubWkndkXaxg5GO3UaOOKS6drO3luDDiO5my3iA0YAKGzPRV1ack8cOdhysI0CYzIPzjSiH5X
michael@0 2049 0QcvC8Lfaj0emsVKYF2rhL5L3fCkVjV76kShi59NHwDniAHzkgDgqBcwOgTMx+gDQQqXCw==
michael@0 2050 """)
michael@0 2051
michael@0 2052 ##file deactivate.bat
michael@0 2053 DEACTIVATE_BAT = convert("""
michael@0 2054 eJxzSE3OyFfIT0vj4ipOLVEI8wwKCXX0iXf1C7Pl4spMU0hJTcvMS01RiPf3cYmHyQYE+fsGhCho
michael@0 2055 cCkAAUibEkTEVhWLMlUlLk6QGixStlyaeCyJDPHw9/Pw93VFsQguim4ZXAJoIUw5DhX47XUM8UCx
michael@0 2056 EchHtwsohN1bILUgw61c/Vy4AJYPYm4=
michael@0 2057 """)
michael@0 2058
michael@0 2059 ##file activate.ps1
michael@0 2060 ACTIVATE_PS = convert("""
michael@0 2061 eJylWdmS40Z2fVeE/oHT6rCloNUEAXDThB6wAyQAEjsB29GBjdgXYiWgmC/zgz/Jv+AEWNVd3S2N
michael@0 2062 xuOKYEUxM+/Jmzfvcm7W//zXf/+wUMOoXtyi1F9kbd0sHH/hFc2iLtrK9b3FrSqyxaVQwr8uhqJd
michael@0 2063 uHaeg9mqzRdR8/13Pyy8qPLdJh0+LMhi0QCoXxYfFh9WtttEnd34H8p6/f1300KauwrULws39e18
michael@0 2064 0ZaLNm9rgN/ZVf3h++/e124Vlc0vKsspHy+Yyi5+XbzPhijvCtduoiL/kA1ukWV27n0o7Sb8LIFj
michael@0 2065 CvWR5GQgUJdp1Pw8TS9+rPy6SDv/+e3d+0+4qw8f3v20+PliV37efEYBAB9FTKC+RHn/Cfxn3rdv
michael@0 2066 00Fube5O+iyCtHDs9BfPfz3q4sfFv9d91Ljhfy7ei0VO+nVTtdOkv/jpt0l2AX6iG1jXgKnnDuD4
michael@0 2067 ke2k/i8fzzz5UedkVcP4pwF+Wvz2FJl+3vt598urXf5Y6LNA5WcFOP7r0sW7b9a+W/xcu0Xpv5zk
michael@0 2068 Kfq3P9Dz9di/fCxS72MXVU1rpx9L4Bxl85Wmn5a+zP76Zuh3pL9ROWr87PN+//GHIl+oOtvn9XSU
michael@0 2069 qH+p0gQBFnx1uV+JLH5O5zv+PXW+WepXVVHZT0+oQezkIATcIm+ivPV/z5J/+cYj3ir4w0Lx09vC
michael@0 2070 e5n/y5/Y5LPPfdrqb88ga/PabxZRVfmp39l588m/6u+/e+OpP+dF7n1WZpJ9//Z4v372fDDz9eHB
michael@0 2071 7Juvs/BLMHzrxL9+9twXpJfhd1/DrpQ5Euu/vlss3wp9HXC/54C/Ld69m6zwdx3tC0d8daSv0V8B
michael@0 2072 n4b9YYF53sJelJV/ix6LZspw/sJtqyl5LJ5r/23htA1Imfm/gt9R7dqVB1LjhydAX4Gb+zksQF59
michael@0 2073 9+P7H//U+376afFuvh2/T6P85Xr/5c8C6OXyFY4BGuN+EE0+GeR201b+wkkLN5mmBY5TfMw8ngqL
michael@0 2074 CztXxCSXKMCYrRIElWkEJlEPYsSOeKBVZCAQTKBhApMwRFQzmCThE0YQu2CdEhgjbgmk9GluHpfR
michael@0 2075 /hhwJCZhGI5jt5FsAkOrObVyE6g2y1snyhMGFlDY1x+BoHpCMulTj5JYWNAYJmnKpvLxXgmQ8az1
michael@0 2076 4fUGxxcitMbbhDFcsiAItg04E+OSBIHTUYD1HI4FHH4kMREPknuYRMyhh3AARWMkfhCketqD1CWJ
michael@0 2077 mTCo/nhUScoQcInB1hpFhIKoIXLo5jLpwFCgsnLCx1QlEMlz/iFEGqzH3vWYcpRcThgWnEKm0QcS
michael@0 2078 rA8ek2a2IYYeowUanOZOlrbWSJUC4c7y2EMI3uJPMnMF/SSXdk6E495VLhzkWHps0rOhKwqk+xBI
michael@0 2079 DhJirhdUCTamMfXz2Hy303hM4DFJ8QL21BcPBULR+gcdYxoeiDqOFSqpi5B5PUISfGg46gFZBPo4
michael@0 2080 jdh8lueaWuVSMTURfbAUnLINr/QYuuYoMQV6l1aWxuZVTjlaLC14UzqZ+ziTGDzJzhiYoPLrt3uI
michael@0 2081 tXkVR47kAo09lo5BD76CH51cTt1snVpMOttLhY93yxChCQPI4OBecS7++h4p4Bdn4H97bJongtPk
michael@0 2082 s9gQnXku1vzsjjmX4/o4YUDkXkjHwDg5FXozU0fW4y5kyeYW0uJWlh536BKr0kMGjtzTkng6Ep62
michael@0 2083 uTWnQtiIqKnEsx7e1hLtzlXs7Upw9TwEnp0t9yzCGgUJIZConx9OHJArLkRYW0dW42G9OeR5Nzwk
michael@0 2084 yk1mX7du5RGHT7dka7N3AznmSif7y6tuKe2N1Al/1TUPRqH6E2GLVc27h9IptMLkCKQYRqPQJgzV
michael@0 2085 2m6WLsSipS3v3b1/WmXEYY1meLEVIU/arOGVkyie7ZsH05ZKpjFW4cpY0YkjySpSExNG2TS8nnJx
michael@0 2086 nrQmWh2WY3cP1eISP9wbaVK35ZXc60yC3VN/j9n7UFoK6zvjSTE2+Pvz6Mx322rnftfP8Y0XKIdv
michael@0 2087 Qd7AfK0nexBTMqRiErvCMa3Hegpfjdh58glW2oNMsKeAX8x6YJLZs9K8/ozjJkWL+JmECMvhQ54x
michael@0 2088 9rsTHwcoGrDi6Y4I+H7yY4/rJVPAbYymUH7C2D3uiUS3KQ1nrCAUkE1dJMneDQIJMQQx5SONxoEO
michael@0 2089 OEn1/Ig1eBBUeEDRuOT2WGGGE4bNypBLFh2PeIg3bEbg44PHiqNDbGIQm50LW6MJU62JHCGBrmc9
michael@0 2090 2F7WBJrrj1ssnTAK4sxwRgh5LLblhwNAclv3Gd+jC/etCfyfR8TMhcWQz8TBIbG8IIyAQ81w2n/C
michael@0 2091 mHWAwRzxd3WoBY7BZnsqGOWrOCKwGkMMNfO0Kci/joZgEocLjNnzgcmdehPHJY0FudXgsr+v44TB
michael@0 2092 I3jnMGnsK5veAhgi9iXGifkHMOC09Rh9cAw9sQ0asl6wKMk8mpzFYaaDSgG4F0wisQDDBRpjCINg
michael@0 2093 FIxhlhQ31xdSkkk6odXZFpTYOQpOOgw9ugM2cDQ+2MYa7JsEirGBrOuxsQy5nPMRdYjsTJ/j1iNw
michael@0 2094 FeSt1jY2+dd5yx1/pzZMOQXUIDcXeAzR7QlDRM8AMkUldXOmGmvYXPABjxqkYKO7VAY6JRU7kpXr
michael@0 2095 +Epu2BU3qFFXClFi27784LrDZsJwbNlDw0JzhZ6M0SMXE4iBHehCpHVkrQhpTFn2dsvsZYkiPEEB
michael@0 2096 GSEAwdiur9LS1U6P2U9JhGp4hnFpJo4FfkdJHcwV6Q5dV1Q9uNeeu7rV8PAjwdFg9RLtroifOr0k
michael@0 2097 uOiRTo/obNPhQIf42Fr4mtThWoSjitEdAmFW66UCe8WFjPk1YVNpL9srFbond7jrLg8tqAasIMpy
michael@0 2098 zkH0SY/6zVAwJrEc14zt14YRXdY+fcJ4qOd2XKB0/Kghw1ovd11t2o+zjt+txndo1ZDZ2T+uMVHT
michael@0 2099 VSXhedBAHoJIID9xm6wPQI3cXY+HR7vxtrJuCKh6kbXaW5KkVeJsdsjqsYsOwYSh0w5sMbu7LF8J
michael@0 2100 5T7U6LJdiTx+ca7RKlulGgS5Z1JSU2Llt32cHFipkaurtBrvNX5UtvNZjkufZ/r1/XyLl6yOpytL
michael@0 2101 Km8Fn+y4wkhlqZP5db0rooqy7xdL4wxzFVTX+6HaxuQJK5E5B1neSSovZ9ALB8091dDbbjVxhWNY
michael@0 2102 Ve5hn1VnI9OF0wpvaRm7SZuC1IRczwC7GnkhPt3muHV1YxUJfo+uh1sYnJy+vI0ZwuPV2uqWJYUH
michael@0 2103 bmBsi1zmFSxHrqwA+WIzLrHkwW4r+bad7xbOzJCnKIa3S3YvrzEBK1Dc0emzJW+SqysQfdEDorQG
michael@0 2104 9ZJlbQzEHQV8naPaF440YXzJk/7vHGK2xwuP+Gc5xITxyiP+WQ4x18oXHjFzCBy9kir1EFTAm0Zq
michael@0 2105 LYwS8MpiGhtfxiBRDXpxDWxk9g9Q2fzPPAhS6VFDAc/aiNGatUkPtZIStZFQ1qD0IlJa/5ZPAi5J
michael@0 2106 ySp1ETDomZMnvgiysZSBfMikrSDte/K5lqV6iwC5q7YN9I1dBZXUytDJNqU74MJsUyNNLAPopWK3
michael@0 2107 tzmLkCiDyl7WQnj9sm7Kd5kzgpoccdNeMw/6zPVB3pUwMgi4C7hj4AMFAf4G27oXH8NNT9zll/sK
michael@0 2108 S6wVlQwazjxWKWy20ZzXb9ne8ngGalPBWSUSj9xkc1drsXkZ8oOyvYT3e0rnYsGwx85xZB9wKeKg
michael@0 2109 cJKZnamYwiaMymZvzk6wtDUkxmdUg0mPad0YHtvzpjEfp2iMxvORhnx0kCVLf5Qa43WJsVoyfEyI
michael@0 2110 pzmf8ruM6xBr7dnBgzyxpqXuUPYaKahOaz1LrxNkS/Q3Ae5AC+xl6NbxAqXXlzghZBZHmOrM6Y6Y
michael@0 2111 ctAkltwlF7SKEsShjVh7QHuxMU0a08/eiu3x3M+07OijMcKFFltByXrpk8w+JNnZpnp3CfgjV1Ax
michael@0 2112 gUYCnWwYow42I5wHCcTzLXK0hMZN2DrPM/zCSqe9jRSlJnr70BPE4+zrwbk/xVIDHy2FAQyHoomT
michael@0 2113 Tt5jiM68nBQut35Y0qLclLiQrutxt/c0OlSqXAC8VrxW97lGoRWzhOnifE2zbF05W4xuyhg7JTUL
michael@0 2114 aqJ7SWDywhjlal0b+NLTpERBgnPW0+Nw99X2Ws72gOL27iER9jgzj7Uu09JaZ3n+hmCjjvZpjNst
michael@0 2115 vOWWTbuLrg+/1ltX8WpPauEDEvcunIgTxuMEHweWKCx2KQ9DU/UKdO/3za4Szm2iHYL+ss9AAttm
michael@0 2116 gZHq2pkUXFbV+FiJCKrpBms18zH75vax5jSo7FNunrVWY3Chvd8KKnHdaTt/6ealwaA1x17yTlft
michael@0 2117 8VBle3nAE+7R0MScC3MJofNCCkA9PGKBgGMYEwfB2QO5j8zUqa8F/EkWKCzGQJ5EZ05HTly1B01E
michael@0 2118 z813G5BY++RZ2sxbQS8ZveGPJNabp5kXAeoign6Tlt5+L8i5ZquY9+S+KEUHkmYMRFBxRrHnbl2X
michael@0 2119 rVemKnG+oB1yd9+zT+4c43jQ0wWmQRR6mTCkY1q3VG05Y120ZzKOMBe6Vy7I5Vz4ygPB3yY4G0FP
michael@0 2120 8RxiMx985YJPXsgRU58EuHj75gygTzejP+W/zKGe78UQN3yOJ1aMQV9hFH+GAfLRsza84WlPLAI/
michael@0 2121 9G/5JdcHftEfH+Y3/fHUG7/o8bv98dzzy3e8S+XCvgqB+VUf7sH0yDHpONdbRE8tAg9NWOzcTJ7q
michael@0 2122 TuAxe/AJ07c1Rs9okJvl1/0G60qvbdDzz5zO0FuPFQIHNp9y9Bd1CufYVx7dB26mAxwa8GMNrN/U
michael@0 2123 oGbNZ3EQ7inLzHy5tRg9AXJrN8cB59cCUBeCiVO7zKM0jU0MamhnRThkg/NMmBOGb6StNeD9tDfA
michael@0 2124 7czsAWopDdnGoXUHtA+s/k0vNPkBcxEI13jVd/axp85va3LpwGggXXWw12Gwr/JGAH0b8CPboiZd
michael@0 2125 QO1l0mk/UHukud4C+w5uRoNzpCmoW6GbgbMyaQNkga2pQINB18lOXOCJzSWPFOhZcwzdgrsQnne7
michael@0 2126 nvjBi+7cP2BbtBeDOW5uOLGf3z94FasKIguOqJl+8ss/6Kumns4cuWbqq5592TN/RNIbn5Qo6qbi
michael@0 2127 O4F0P9txxPAwagqPlftztO8cWBzdN/jz3b7GD6JHYP/Zp4ToAMaA74M+EGSft3hEGMuf8EwjnTk/
michael@0 2128 nz/P7SLipB/ogQ6xNX0fDqNncMCfHqGLCMM0ZzFa+6lPJYQ5p81vW4HkCvidYf6kb+P/oB965g8K
michael@0 2129 C6uR0rdjX1DNKc5pOSTquI8uQ6KXxYaKBn+30/09tK4kMpJPgUIQkbENEPbuezNPPje2Um83SgyX
michael@0 2130 GTCJb6MnGVIpgncdQg1qz2bvPfxYD9fewCXDomx9S+HQJuX6W3VAL+v5WZMudRQZk9ZdOk6GIUtC
michael@0 2131 PqEb/uwSIrtR7/edzqgEdtpEwq7p2J5OQV+RLrmtTvFwFpf03M/VrRyTZ73qVod7v7Jh2Dwe5J25
michael@0 2132 JqFOU2qEu1sP+CRotklediycKfLjeIZzjJQsvKmiGSNQhxuJpKa+hoWUizaE1PuIRGzJqropwgVB
michael@0 2133 oo1hr870MZLgnXF5ZIpr6mF0L8aSy2gVnTAuoB4WEd4d5NPVC9TMotYXERKlTcwQ2KiB/C48AEfH
michael@0 2134 Qbyq4CN8xTFnTvf/ebOc3isnjD95s0QF0nx9s+y+zMmz782xL0SgEmRpA3x1w1Ff9/74xcxKEPdS
michael@0 2135 IEFTz6GgU0+BK/UZ5Gwbl4gZwycxEw+Kqa5QmMkh4OzgzEVPnDAiAOGBFaBW4wkDmj1G4RyElKgj
michael@0 2136 NlLCq8zsp085MNh/+R4t1Q8yxoSv8PUpTt7izZwf2BTHZZ3pIZpUIpuLkL1nNL6sYcHqcKm237wp
michael@0 2137 T2+RCjgXweXd2Zp7ZM8W6dG5bZsqo0nrJBTx8EC0+CQQdzEGnabTnkzofu1pYkWl4E7XSniECdxy
michael@0 2138 vLYavPMcL9LW5SToJFNnos+uqweOHriUZ1ntIYZUonc7ltEQ6oTRtwOHNwez2sVREskHN+bqG3ua
michael@0 2139 eaEbJ8XpyO8CeD9QJc8nbLP2C2R3A437ISUNyt5Yd0TbDNcl11/DSsOzdbi/VhCC0KE6v1vqVNkq
michael@0 2140 45ZnG6fiV2NwzInxCNth3BwL0+8814jE6+1W1EeWtpWbSZJOJNYXmWRXa7vLnAljE692eHjZ4y5u
michael@0 2141 y1u63De0IzKca7As48Z3XshVF+3XiLNz0JIMh/JOpbiNLlMi672uO0wYzOCZjRxcxj3D+gVenGIE
michael@0 2142 MvFUGGXuRps2RzMcgWIRolHXpGUP6sMsQt1hspUBnVKUn/WQj2u6j3SXd9Xz0QtEzoM7qTu5y7gR
michael@0 2143 q9gNNsrlEMLdikBt9bFvBnfbUIh6voTw7eDsyTmPKUvF0bHqWLbHe3VRHyRZnNeSGKsB73q66Vsk
michael@0 2144 taxWYmwz1tYVFG/vOQhlM0gUkyvIab3nv2caJ1udU1F3pDMty7stubTE4OJqm0i0ECfrJIkLtraC
michael@0 2145 HwRWKzlqpfhEIqYH09eT9WrOhQyt8YEoyBlnXtAT37WHIQ03TIuEHbnRxZDdLun0iok9PUC79prU
michael@0 2146 m5beZzfQUelEXnhzb/pIROKx3F7qCttYIFGh5dXNzFzID7u8vKykA8Uejf7XXz//S4nKvW//ofS/
michael@0 2147 QastYw==
michael@0 2148 """)
michael@0 2149
michael@0 2150 ##file distutils-init.py
michael@0 2151 DISTUTILS_INIT = convert("""
michael@0 2152 eJytV1uL4zYUfvevOE0ottuMW9q3gVDa3aUMXXbLMlDKMBiNrSTqOJKRlMxkf33PkXyRbGe7Dw2E
michael@0 2153 UXTu37lpxLFV2oIyifAncxmOL0xLIfcG+gv80x9VW6maw7o/CANSWWBwFtqeWMPlGY6qPjV8A0bB
michael@0 2154 C4eKSTgZ5LRgFeyErMEeOBhbN+Ipgeizhjtnhkn7DdyjuNLPoCS0l/ayQTG0djwZC08cLXozeMss
michael@0 2155 aG5EzQ0IScpnWtHSTXuxByV/QCmxE7y+eS0uxWeoheaVVfqSJHiU7Mhhi6gULbOHorshkrEnKxpT
michael@0 2156 0n3A8Y8SMpuwZx6aoix3ouFlmW8gHRSkeSJ2g7hU+kiHLDaQw3bmRDaTGfTnty7gPm0FHbIBg9U9
michael@0 2157 oh1kZzAFLaue2R6htPCtAda2nGlDSUJ4PZBgCJBGVcwKTAMz/vJiLD+Oin5Z5QlvDPdulC6EsiyE
michael@0 2158 NFzb7McNTKJzbJqzphx92VKRFY1idenzmq3K0emRcbWBD0ryqc4NZGmKOOOX9Pz5x+/l27tP797c
michael@0 2159 f/z0d+4NruGNai8uAM0bfsYaw8itFk8ny41jsfpyO+BWlpqfhcG4yxLdi/0tQqoT4a8Vby382mt8
michael@0 2160 p7XSo7aWGdPBc+b6utaBmCQ7rQKQoWtAuthQCiold2KfJIPTT8xwg9blPumc+YDZC/wYGdAyHpJk
michael@0 2161 vUbHbHWAp5No6pK/WhhLEWrFjUwtPEv1Agf8YmnsuXUQYkeZoHm8ogP16gt2uHoxcEMdf2C6pmbw
michael@0 2162 hUMsWGhanboh4IzzmsIpWs134jVPqD/c74bZHdY69UKKSn/+KfVhxLgUlToemayLMYQOqfEC61bh
michael@0 2163 cbhwaqoGUzIyZRFHPmau5juaWqwRn3mpWmoEA5nhzS5gog/5jbcFQqOZvmBasZtwYlG93k5GEiyw
michael@0 2164 buHhMWLjDarEGpMGB2LFs5nIJkhp/nUmZneFaRth++lieJtHepIvKgx6PJqIlD9X2j6pG1i9x3pZ
michael@0 2165 5bHuCPFiirGHeO7McvoXkz786GaKVzC9DSpnOxJdc4xm6NSVq7lNEnKdVlnpu9BNYoKX2Iq3wvgh
michael@0 2166 gGEUM66kK6j4NiyoneuPLSwaCWDxczgaolEWpiMyDVDb7dNuLAbriL8ig8mmeju31oNvQdpnvEPC
michael@0 2167 1vAXbWacGRVrGt/uXN/gU0CDDwgooKRrHfTBb1/s9lYZ8ZqOBU0yLvpuP6+K9hLFsvIjeNhBi0KL
michael@0 2168 MlOuWRn3FRwx5oHXjl0YImUx0+gLzjGchrgzca026ETmYJzPD+IpuKzNi8AFn048Thd63OdD86M6
michael@0 2169 84zE8yQm0VqXdbbgvub2pKVnS76icBGdeTHHXTKspUmr4NYo/furFLKiMdQzFjHJNcdAnMhltBJK
michael@0 2170 0/IKX3DVFqvPJ2dLE7bDBkH0l/PJ29074+F0CsGYOxsb7U3myTUncYfXqnLLfa6sJybX4g+hmcjO
michael@0 2171 kMRBfA1JellfRRKJcyRpxdS4rIl6FdmQCWjo/o9Qz7yKffoP4JHjOvABcRn4CZIT2RH4jnxmfpVG
michael@0 2172 qgLaAvQBNfuO6X0/Ux02nb4FKx3vgP+XnkX0QW9pLy/NsXgdN24dD3LxO2Nwil7Zlc1dqtP3d7/h
michael@0 2173 kzp1/+7hGBuY4pk0XD/0Ao/oTe/XGrfyM773aB7iUhgkpy+dwAMalxMP0DrBcsVw/6p25+/hobP9
michael@0 2174 GBknrWExDhLJ1bwt1NcCNblaFbMKCyvmX0PeRaQ=
michael@0 2175 """)
michael@0 2176
michael@0 2177 ##file distutils.cfg
michael@0 2178 DISTUTILS_CFG = convert("""
michael@0 2179 eJxNj00KwkAMhfc9xYNuxe4Ft57AjYiUtDO1wXSmNJnK3N5pdSEEAu8nH6lxHVlRhtDHMPATA4uH
michael@0 2180 xJ4EFmGbvfJiicSHFRzUSISMY6hq3GLCRLnIvSTnEefN0FIjw5tF0Hkk9Q5dRunBsVoyFi24aaLg
michael@0 2181 9FDOlL0FPGluf4QjcInLlxd6f6rqkgPu/5nHLg0cXCscXoozRrP51DRT3j9QNl99AP53T2Q=
michael@0 2182 """)
michael@0 2183
michael@0 2184 ##file activate_this.py
michael@0 2185 ACTIVATE_THIS = convert("""
michael@0 2186 eJyNU01v2zAMvetXEB4K21jmDOstQA4dMGCHbeihlyEIDMWmG62yJEiKE//7kXKdpN2KzYBt8euR
michael@0 2187 fKSyLPs8wiEo8wh4wqZTGou4V6Hm0wJa1cSiTkJdr8+GsoTRHuCotBayiWqQEYGtMCgfD1KjGYBe
michael@0 2188 5a3p0cRKiAe2NtLADikftnDco0ko/SFEVgEZ8aRC5GLux7i3BpSJ6J1H+i7A2CjiHq9z7JRZuuQq
michael@0 2189 siwTIvpxJYCeuWaBpwZdhB+yxy/eWz+ZvVSU8C4E9FFZkyxFsvCT/ZzL8gcz9aXVE14Yyp2M+2W0
michael@0 2190 y7n5mp0qN+avKXvbsyyzUqjeWR8hjGE+2iCE1W1tQ82hsCZN9UzlJr+/e/iab8WfqsmPI6pWeUPd
michael@0 2191 FrMsd4H/55poeO9n54COhUs+sZNEzNtg/wanpjpuqHJaxs76HtZryI/K3H7KJ/KDIhqcbJ7kI4ar
michael@0 2192 XL+sMgXnX0D+Te2Iy5xdP8yueSlQB/x/ED2BTAtyE3K4SYUN6AMNfbO63f4lBW3bUJPbTL+mjSxS
michael@0 2193 PyRfJkZRgj+VbFv+EzHFi5pKwUEepa4JslMnwkowSRCXI+m5XvEOvtuBrxHdhLalG0JofYBok6qj
michael@0 2194 YdN2dEngUlbC4PG60M1WEN0piu7Nq7on0mgyyUw3iV1etLo6r/81biWdQ9MWHFaePWZYaq+nmp+t
michael@0 2195 s3az+sj7eA0jfgPfeoN1
michael@0 2196 """)
michael@0 2197
michael@0 2198 MH_MAGIC = 0xfeedface
michael@0 2199 MH_CIGAM = 0xcefaedfe
michael@0 2200 MH_MAGIC_64 = 0xfeedfacf
michael@0 2201 MH_CIGAM_64 = 0xcffaedfe
michael@0 2202 FAT_MAGIC = 0xcafebabe
michael@0 2203 BIG_ENDIAN = '>'
michael@0 2204 LITTLE_ENDIAN = '<'
michael@0 2205 LC_LOAD_DYLIB = 0xc
michael@0 2206 maxint = majver == 3 and getattr(sys, 'maxsize') or getattr(sys, 'maxint')
michael@0 2207
michael@0 2208
michael@0 2209 class fileview(object):
michael@0 2210 """
michael@0 2211 A proxy for file-like objects that exposes a given view of a file.
michael@0 2212 Modified from macholib.
michael@0 2213 """
michael@0 2214
michael@0 2215 def __init__(self, fileobj, start=0, size=maxint):
michael@0 2216 if isinstance(fileobj, fileview):
michael@0 2217 self._fileobj = fileobj._fileobj
michael@0 2218 else:
michael@0 2219 self._fileobj = fileobj
michael@0 2220 self._start = start
michael@0 2221 self._end = start + size
michael@0 2222 self._pos = 0
michael@0 2223
michael@0 2224 def __repr__(self):
michael@0 2225 return '<fileview [%d, %d] %r>' % (
michael@0 2226 self._start, self._end, self._fileobj)
michael@0 2227
michael@0 2228 def tell(self):
michael@0 2229 return self._pos
michael@0 2230
michael@0 2231 def _checkwindow(self, seekto, op):
michael@0 2232 if not (self._start <= seekto <= self._end):
michael@0 2233 raise IOError("%s to offset %d is outside window [%d, %d]" % (
michael@0 2234 op, seekto, self._start, self._end))
michael@0 2235
michael@0 2236 def seek(self, offset, whence=0):
michael@0 2237 seekto = offset
michael@0 2238 if whence == os.SEEK_SET:
michael@0 2239 seekto += self._start
michael@0 2240 elif whence == os.SEEK_CUR:
michael@0 2241 seekto += self._start + self._pos
michael@0 2242 elif whence == os.SEEK_END:
michael@0 2243 seekto += self._end
michael@0 2244 else:
michael@0 2245 raise IOError("Invalid whence argument to seek: %r" % (whence,))
michael@0 2246 self._checkwindow(seekto, 'seek')
michael@0 2247 self._fileobj.seek(seekto)
michael@0 2248 self._pos = seekto - self._start
michael@0 2249
michael@0 2250 def write(self, bytes):
michael@0 2251 here = self._start + self._pos
michael@0 2252 self._checkwindow(here, 'write')
michael@0 2253 self._checkwindow(here + len(bytes), 'write')
michael@0 2254 self._fileobj.seek(here, os.SEEK_SET)
michael@0 2255 self._fileobj.write(bytes)
michael@0 2256 self._pos += len(bytes)
michael@0 2257
michael@0 2258 def read(self, size=maxint):
michael@0 2259 assert size >= 0
michael@0 2260 here = self._start + self._pos
michael@0 2261 self._checkwindow(here, 'read')
michael@0 2262 size = min(size, self._end - here)
michael@0 2263 self._fileobj.seek(here, os.SEEK_SET)
michael@0 2264 bytes = self._fileobj.read(size)
michael@0 2265 self._pos += len(bytes)
michael@0 2266 return bytes
michael@0 2267
michael@0 2268
michael@0 2269 def read_data(file, endian, num=1):
michael@0 2270 """
michael@0 2271 Read a given number of 32-bits unsigned integers from the given file
michael@0 2272 with the given endianness.
michael@0 2273 """
michael@0 2274 res = struct.unpack(endian + 'L' * num, file.read(num * 4))
michael@0 2275 if len(res) == 1:
michael@0 2276 return res[0]
michael@0 2277 return res
michael@0 2278
michael@0 2279
michael@0 2280 def mach_o_change(path, what, value):
michael@0 2281 """
michael@0 2282 Replace a given name (what) in any LC_LOAD_DYLIB command found in
michael@0 2283 the given binary with a new name (value), provided it's shorter.
michael@0 2284 """
michael@0 2285
michael@0 2286 def do_macho(file, bits, endian):
michael@0 2287 # Read Mach-O header (the magic number is assumed read by the caller)
michael@0 2288 cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags = read_data(file, endian, 6)
michael@0 2289 # 64-bits header has one more field.
michael@0 2290 if bits == 64:
michael@0 2291 read_data(file, endian)
michael@0 2292 # The header is followed by ncmds commands
michael@0 2293 for n in range(ncmds):
michael@0 2294 where = file.tell()
michael@0 2295 # Read command header
michael@0 2296 cmd, cmdsize = read_data(file, endian, 2)
michael@0 2297 if cmd == LC_LOAD_DYLIB:
michael@0 2298 # The first data field in LC_LOAD_DYLIB commands is the
michael@0 2299 # offset of the name, starting from the beginning of the
michael@0 2300 # command.
michael@0 2301 name_offset = read_data(file, endian)
michael@0 2302 file.seek(where + name_offset, os.SEEK_SET)
michael@0 2303 # Read the NUL terminated string
michael@0 2304 load = file.read(cmdsize - name_offset).decode()
michael@0 2305 load = load[:load.index('\0')]
michael@0 2306 # If the string is what is being replaced, overwrite it.
michael@0 2307 if load == what:
michael@0 2308 file.seek(where + name_offset, os.SEEK_SET)
michael@0 2309 file.write(value.encode() + '\0'.encode())
michael@0 2310 # Seek to the next command
michael@0 2311 file.seek(where + cmdsize, os.SEEK_SET)
michael@0 2312
michael@0 2313 def do_file(file, offset=0, size=maxint):
michael@0 2314 file = fileview(file, offset, size)
michael@0 2315 # Read magic number
michael@0 2316 magic = read_data(file, BIG_ENDIAN)
michael@0 2317 if magic == FAT_MAGIC:
michael@0 2318 # Fat binaries contain nfat_arch Mach-O binaries
michael@0 2319 nfat_arch = read_data(file, BIG_ENDIAN)
michael@0 2320 for n in range(nfat_arch):
michael@0 2321 # Read arch header
michael@0 2322 cputype, cpusubtype, offset, size, align = read_data(file, BIG_ENDIAN, 5)
michael@0 2323 do_file(file, offset, size)
michael@0 2324 elif magic == MH_MAGIC:
michael@0 2325 do_macho(file, 32, BIG_ENDIAN)
michael@0 2326 elif magic == MH_CIGAM:
michael@0 2327 do_macho(file, 32, LITTLE_ENDIAN)
michael@0 2328 elif magic == MH_MAGIC_64:
michael@0 2329 do_macho(file, 64, BIG_ENDIAN)
michael@0 2330 elif magic == MH_CIGAM_64:
michael@0 2331 do_macho(file, 64, LITTLE_ENDIAN)
michael@0 2332
michael@0 2333 assert(len(what) >= len(value))
michael@0 2334 do_file(open(path, 'r+b'))
michael@0 2335
michael@0 2336
michael@0 2337 if __name__ == '__main__':
michael@0 2338 main()
michael@0 2339
michael@0 2340 ## TODO:
michael@0 2341 ## Copy python.exe.manifest
michael@0 2342 ## Monkeypatch distutils.sysconfig

mercurial