home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / BDIST.PY < prev    next >
Encoding:
Python Source  |  2000-10-14  |  4.9 KB  |  140 lines

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