~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/distutils/command/bdist.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

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