Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

166 рядки
5.6 KiB

  1. ##############################################################################
  2. #
  3. # Copyright (c) 2006 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE.
  12. #
  13. ##############################################################################
  14. """Bootstrap a buildout-based project
  15. Simply run this script in a directory containing a buildout.cfg.
  16. The script accepts buildout command-line options, so you can
  17. use the -c option to specify an alternate configuration file.
  18. """
  19. import os, shutil, sys, tempfile
  20. from optparse import OptionParser
  21. tmpeggs = tempfile.mkdtemp()
  22. usage = '''\
  23. [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
  24. Bootstraps a buildout-based project.
  25. Simply run this script in a directory containing a buildout.cfg, using the
  26. Python that you want bin/buildout to use.
  27. Note that by using --setup-source and --download-base to point to
  28. local resources, you can keep this script from going over the network.
  29. '''
  30. parser = OptionParser(usage=usage)
  31. parser.add_option("-v", "--version", help="use a specific zc.buildout version")
  32. parser.add_option("-t", "--accept-buildout-test-releases",
  33. dest='accept_buildout_test_releases',
  34. action="store_true", default=False,
  35. help=("Normally, if you do not specify a --version, the "
  36. "bootstrap script and buildout gets the newest "
  37. "*final* versions of zc.buildout and its recipes and "
  38. "extensions for you. If you use this flag, "
  39. "bootstrap and buildout will get the newest releases "
  40. "even if they are alphas or betas."))
  41. parser.add_option("-c", "--config-file",
  42. help=("Specify the path to the buildout configuration "
  43. "file to be used."))
  44. parser.add_option("-f", "--find-links",
  45. help=("Specify a URL to search for buildout releases"))
  46. options, args = parser.parse_args()
  47. ######################################################################
  48. # load/install distribute
  49. to_reload = False
  50. try:
  51. import pkg_resources, setuptools
  52. if not hasattr(pkg_resources, '_distribute'):
  53. to_reload = True
  54. raise ImportError
  55. except ImportError:
  56. ez = {}
  57. try:
  58. from urllib.request import urlopen
  59. except ImportError:
  60. from urllib2 import urlopen
  61. exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
  62. setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
  63. ez['use_setuptools'](**setup_args)
  64. if to_reload:
  65. reload(pkg_resources)
  66. import pkg_resources
  67. # This does not (always?) update the default working set. We will
  68. # do it.
  69. for path in sys.path:
  70. if path not in pkg_resources.working_set.entries:
  71. pkg_resources.working_set.add_entry(path)
  72. ######################################################################
  73. # Install buildout
  74. ws = pkg_resources.working_set
  75. cmd = [sys.executable, '-c',
  76. 'from setuptools.command.easy_install import main; main()',
  77. '-mZqNxd', tmpeggs]
  78. find_links = os.environ.get(
  79. 'bootstrap-testing-find-links',
  80. options.find_links or
  81. ('http://downloads.buildout.org/'
  82. if options.accept_buildout_test_releases else None)
  83. )
  84. if find_links:
  85. cmd.extend(['-f', find_links])
  86. distribute_path = ws.find(
  87. pkg_resources.Requirement.parse('distribute')).location
  88. requirement = 'zc.buildout'
  89. version = options.version
  90. if version is None and not options.accept_buildout_test_releases:
  91. # Figure out the most recent final version of zc.buildout.
  92. import setuptools.package_index
  93. _final_parts = '*final-', '*final'
  94. def _final_version(parsed_version):
  95. for part in parsed_version:
  96. if (part[:1] == '*') and (part not in _final_parts):
  97. return False
  98. return True
  99. index = setuptools.package_index.PackageIndex(
  100. search_path=[distribute_path])
  101. if find_links:
  102. index.add_find_links((find_links,))
  103. req = pkg_resources.Requirement.parse(requirement)
  104. if index.obtain(req) is not None:
  105. best = []
  106. bestv = None
  107. for dist in index[req.project_name]:
  108. distv = dist.parsed_version
  109. if _final_version(distv):
  110. if bestv is None or distv > bestv:
  111. best = [dist]
  112. bestv = distv
  113. elif distv == bestv:
  114. best.append(dist)
  115. if best:
  116. best.sort()
  117. version = best[-1].version
  118. if version:
  119. requirement = '=='.join((requirement, version))
  120. cmd.append(requirement)
  121. import subprocess
  122. if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
  123. raise Exception(
  124. "Failed to execute command:\n%s",
  125. repr(cmd)[1:-1])
  126. ######################################################################
  127. # Import and run buildout
  128. ws.add_entry(tmpeggs)
  129. ws.require(requirement)
  130. import zc.buildout.buildout
  131. if not [a for a in args if '=' not in a]:
  132. args.append('bootstrap')
  133. # if -c was provided, we push it back into args for buildout' main function
  134. if options.config_file is not None:
  135. args[0:0] = ['-c', options.config_file]
  136. zc.buildout.buildout.main(args)
  137. shutil.rmtree(tmpeggs)