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