/Lib/distutils/command/bdist_dumb.py

http://unladen-swallow.googlecode.com/ · Python · 135 lines · 133 code · 0 blank · 2 comment · 0 complexity · 3bd83cd6028ecc895323219ecdbe3b8f MD5 · raw file

  1. """distutils.command.bdist_dumb
  2. Implements the Distutils 'bdist_dumb' command (create a "dumb" built
  3. distribution -- i.e., just an archive to be unpacked under $prefix or
  4. $exec_prefix)."""
  5. # This module should be kept compatible with Python 2.1.
  6. __revision__ = "$Id: bdist_dumb.py 61000 2008-02-23 17:40:11Z christian.heimes $"
  7. import os
  8. from distutils.core import Command
  9. from distutils.util import get_platform
  10. from distutils.dir_util import remove_tree, ensure_relative
  11. from distutils.errors import *
  12. from distutils.sysconfig import get_python_version
  13. from distutils import log
  14. class bdist_dumb (Command):
  15. description = "create a \"dumb\" built distribution"
  16. user_options = [('bdist-dir=', 'd',
  17. "temporary directory for creating the distribution"),
  18. ('plat-name=', 'p',
  19. "platform name to embed in generated filenames "
  20. "(default: %s)" % get_platform()),
  21. ('format=', 'f',
  22. "archive format to create (tar, ztar, gztar, zip)"),
  23. ('keep-temp', 'k',
  24. "keep the pseudo-installation tree around after " +
  25. "creating the distribution archive"),
  26. ('dist-dir=', 'd',
  27. "directory to put final built distributions in"),
  28. ('skip-build', None,
  29. "skip rebuilding everything (for testing/debugging)"),
  30. ('relative', None,
  31. "build the archive using relative paths"
  32. "(default: false)"),
  33. ]
  34. boolean_options = ['keep-temp', 'skip-build', 'relative']
  35. default_format = { 'posix': 'gztar',
  36. 'nt': 'zip',
  37. 'os2': 'zip' }
  38. def initialize_options (self):
  39. self.bdist_dir = None
  40. self.plat_name = None
  41. self.format = None
  42. self.keep_temp = 0
  43. self.dist_dir = None
  44. self.skip_build = 0
  45. self.relative = 0
  46. # initialize_options()
  47. def finalize_options (self):
  48. if self.bdist_dir is None:
  49. bdist_base = self.get_finalized_command('bdist').bdist_base
  50. self.bdist_dir = os.path.join(bdist_base, 'dumb')
  51. if self.format is None:
  52. try:
  53. self.format = self.default_format[os.name]
  54. except KeyError:
  55. raise DistutilsPlatformError, \
  56. ("don't know how to create dumb built distributions " +
  57. "on platform %s") % os.name
  58. self.set_undefined_options('bdist',
  59. ('dist_dir', 'dist_dir'),
  60. ('plat_name', 'plat_name'))
  61. # finalize_options()
  62. def run (self):
  63. if not self.skip_build:
  64. self.run_command('build')
  65. install = self.reinitialize_command('install', reinit_subcommands=1)
  66. install.root = self.bdist_dir
  67. install.skip_build = self.skip_build
  68. install.warn_dir = 0
  69. log.info("installing to %s" % self.bdist_dir)
  70. self.run_command('install')
  71. # And make an archive relative to the root of the
  72. # pseudo-installation tree.
  73. archive_basename = "%s.%s" % (self.distribution.get_fullname(),
  74. self.plat_name)
  75. # OS/2 objects to any ":" characters in a filename (such as when
  76. # a timestamp is used in a version) so change them to hyphens.
  77. if os.name == "os2":
  78. archive_basename = archive_basename.replace(":", "-")
  79. pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
  80. if not self.relative:
  81. archive_root = self.bdist_dir
  82. else:
  83. if (self.distribution.has_ext_modules() and
  84. (install.install_base != install.install_platbase)):
  85. raise DistutilsPlatformError, \
  86. ("can't make a dumb built distribution where "
  87. "base and platbase are different (%s, %s)"
  88. % (repr(install.install_base),
  89. repr(install.install_platbase)))
  90. else:
  91. archive_root = os.path.join(self.bdist_dir,
  92. ensure_relative(install.install_base))
  93. # Make the archive
  94. filename = self.make_archive(pseudoinstall_root,
  95. self.format, root_dir=archive_root)
  96. if self.distribution.has_ext_modules():
  97. pyversion = get_python_version()
  98. else:
  99. pyversion = 'any'
  100. self.distribution.dist_files.append(('bdist_dumb', pyversion,
  101. filename))
  102. if not self.keep_temp:
  103. remove_tree(self.bdist_dir, dry_run=self.dry_run)
  104. # run()
  105. # class bdist_dumb