logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

bdist.py (5433B)


  1. """distutils.command.bdist
  2. Implements the Distutils 'bdist' command (create a built [binary]
  3. distribution)."""
  4. import os
  5. from distutils.core import Command
  6. from distutils.errors import *
  7. from distutils.util import get_platform
  8. def show_formats():
  9. """Print list of available formats (arguments to "--format" option).
  10. """
  11. from distutils.fancy_getopt import FancyGetopt
  12. formats = []
  13. for format in bdist.format_commands:
  14. formats.append(("formats=" + format, None,
  15. bdist.format_command[format][1]))
  16. pretty_printer = FancyGetopt(formats)
  17. pretty_printer.print_help("List of available distribution formats:")
  18. class bdist(Command):
  19. description = "create a built (binary) distribution"
  20. user_options = [('bdist-base=', 'b',
  21. "temporary directory for creating built distributions"),
  22. ('plat-name=', 'p',
  23. "platform name to embed in generated filenames "
  24. "(default: %s)" % get_platform()),
  25. ('formats=', None,
  26. "formats for distribution (comma-separated list)"),
  27. ('dist-dir=', 'd',
  28. "directory to put final built distributions in "
  29. "[default: dist]"),
  30. ('skip-build', None,
  31. "skip rebuilding everything (for testing/debugging)"),
  32. ('owner=', 'u',
  33. "Owner name used when creating a tar file"
  34. " [default: current user]"),
  35. ('group=', 'g',
  36. "Group name used when creating a tar file"
  37. " [default: current group]"),
  38. ]
  39. boolean_options = ['skip-build']
  40. help_options = [
  41. ('help-formats', None,
  42. "lists available distribution formats", show_formats),
  43. ]
  44. # The following commands do not take a format option from bdist
  45. no_format_option = ('bdist_rpm',)
  46. # This won't do in reality: will need to distinguish RPM-ish Linux,
  47. # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
  48. default_format = {'posix': 'gztar',
  49. 'nt': 'zip'}
  50. # Establish the preferred order (for the --help-formats option).
  51. format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar',
  52. 'zip', 'msi']
  53. # And the real information.
  54. format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
  55. 'gztar': ('bdist_dumb', "gzip'ed tar file"),
  56. 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
  57. 'xztar': ('bdist_dumb', "xz'ed tar file"),
  58. 'ztar': ('bdist_dumb', "compressed tar file"),
  59. 'tar': ('bdist_dumb', "tar file"),
  60. 'zip': ('bdist_dumb', "ZIP file"),
  61. 'msi': ('bdist_msi', "Microsoft Installer")
  62. }
  63. def initialize_options(self):
  64. self.bdist_base = None
  65. self.plat_name = None
  66. self.formats = None
  67. self.dist_dir = None
  68. self.skip_build = 0
  69. self.group = None
  70. self.owner = None
  71. def finalize_options(self):
  72. # have to finalize 'plat_name' before 'bdist_base'
  73. if self.plat_name is None:
  74. if self.skip_build:
  75. self.plat_name = get_platform()
  76. else:
  77. self.plat_name = self.get_finalized_command('build').plat_name
  78. # 'bdist_base' -- parent of per-built-distribution-format
  79. # temporary directories (eg. we'll probably have
  80. # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
  81. if self.bdist_base is None:
  82. build_base = self.get_finalized_command('build').build_base
  83. self.bdist_base = os.path.join(build_base,
  84. 'bdist.' + self.plat_name)
  85. self.ensure_string_list('formats')
  86. if self.formats is None:
  87. try:
  88. self.formats = [self.default_format[os.name]]
  89. except KeyError:
  90. raise DistutilsPlatformError(
  91. "don't know how to create built distributions "
  92. "on platform %s" % os.name)
  93. if self.dist_dir is None:
  94. self.dist_dir = "dist"
  95. def run(self):
  96. # Figure out which sub-commands we need to run.
  97. commands = []
  98. for format in self.formats:
  99. try:
  100. commands.append(self.format_command[format][0])
  101. except KeyError:
  102. raise DistutilsOptionError("invalid format '%s'" % format)
  103. # Reinitialize and run each command.
  104. for i in range(len(self.formats)):
  105. cmd_name = commands[i]
  106. sub_cmd = self.reinitialize_command(cmd_name)
  107. if cmd_name not in self.no_format_option:
  108. sub_cmd.format = self.formats[i]
  109. # passing the owner and group names for tar archiving
  110. if cmd_name == 'bdist_dumb':
  111. sub_cmd.owner = self.owner
  112. sub_cmd.group = self.group
  113. # If we're going to need to run this command again, tell it to
  114. # keep its temporary files around so subsequent runs go faster.
  115. if cmd_name in commands[i+1:]:
  116. sub_cmd.keep_temp = 1
  117. self.run_command(cmd_name)