ยปCore Development>Code coverage>Lib/distutils/command/bdist.py

Python code coverage for Lib/distutils/command/bdist.py

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