| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | """distutils.command.bdist
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Implements the Distutils 'bdist' command (create a built [binary] | 
					
						
							|  |  |  | distribution)."""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # created 2000/03/29, Greg Ward | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __revision__ = "$Id$" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os, string | 
					
						
							| 
									
										
										
										
											2000-03-31 04:53:41 +00:00
										 |  |  | from types import * | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | from distutils.core import Command | 
					
						
							| 
									
										
										
										
											2000-03-31 05:08:50 +00:00
										 |  |  | from distutils.errors import * | 
					
						
							| 
									
										
										
										
											2000-05-13 03:08:28 +00:00
										 |  |  | from distutils.util import get_platform | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-24 01:23:37 +00:00
										 |  |  | def show_formats (): | 
					
						
							|  |  |  |     """Print list of available formats (arguments to "--format" option).
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2001-12-06 21:01:19 +00:00
										 |  |  |     from distutils.fancy_getopt import FancyGetopt | 
					
						
							| 
									
										
										
										
											2000-06-24 01:23:37 +00:00
										 |  |  |     formats=[] | 
					
						
							|  |  |  |     for format in bdist.format_commands: | 
					
						
							|  |  |  |         formats.append(("formats=" + format, None, | 
					
						
							|  |  |  |                         bdist.format_command[format][1])) | 
					
						
							|  |  |  |     pretty_printer = FancyGetopt(formats) | 
					
						
							|  |  |  |     pretty_printer.print_help("List of available distribution formats:") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | class bdist (Command): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     description = "create a built (binary) distribution" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-13 03:08:28 +00:00
										 |  |  |     user_options = [('bdist-base=', 'b', | 
					
						
							|  |  |  |                      "temporary directory for creating built distributions"), | 
					
						
							| 
									
										
										
										
											2000-09-11 00:47:35 +00:00
										 |  |  |                     ('plat-name=', 'p', | 
					
						
							|  |  |  |                      "platform name to embed in generated filenames " | 
					
						
							|  |  |  |                      "(default: %s)" % get_platform()), | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |                     ('formats=', None, | 
					
						
							| 
									
										
										
										
											2000-06-24 00:23:20 +00:00
										 |  |  |                      "formats for distribution (comma-separated list)"), | 
					
						
							| 
									
										
										
										
											2000-07-05 03:07:18 +00:00
										 |  |  |                     ('dist-dir=', 'd', | 
					
						
							|  |  |  |                      "directory to put final built distributions in " | 
					
						
							|  |  |  |                      "[default: dist]"), | 
					
						
							| 
									
										
										
										
											2002-01-12 11:27:42 +00:00
										 |  |  |                     ('skip-build', None, | 
					
						
							|  |  |  |                      "skip rebuilding everything (for testing/debugging)"), | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  |                    ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-12 11:27:42 +00:00
										 |  |  |     boolean_options = ['skip-build'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-24 01:23:37 +00:00
										 |  |  |     help_options = [ | 
					
						
							|  |  |  |         ('help-formats', None, | 
					
						
							|  |  |  |          "lists available distribution formats", show_formats), | 
					
						
							| 
									
										
										
										
											2000-10-14 04:06:40 +00:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2000-06-24 01:23:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-13 01:49:56 +00:00
										 |  |  |     # The following commands do not take a format option from bdist | 
					
						
							| 
									
										
										
										
											2002-10-04 09:30:06 +00:00
										 |  |  |     no_format_option = ('bdist_rpm', | 
					
						
							|  |  |  |                         #'bdist_sdux', 'bdist_pkgtool' | 
					
						
							|  |  |  |                         ) | 
					
						
							| 
									
										
										
										
											2000-05-13 01:49:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  |     # This won't do in reality: will need to distinguish RPM-ish Linux, | 
					
						
							|  |  |  |     # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. | 
					
						
							|  |  |  |     default_format = { 'posix': 'gztar', | 
					
						
							| 
									
										
										
										
											2002-01-31 18:56:00 +00:00
										 |  |  |                        'nt': 'zip', | 
					
						
							|  |  |  |                        'os2': 'zip', } | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 01:44:44 +00:00
										 |  |  |     # Establish the preferred order (for the --help-formats option). | 
					
						
							|  |  |  |     format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', | 
					
						
							| 
									
										
										
										
											2002-10-04 09:30:06 +00:00
										 |  |  |                        'wininst', 'zip', | 
					
						
							|  |  |  |                        #'pkgtool', 'sdux' | 
					
						
							|  |  |  |                        ] | 
					
						
							| 
									
										
										
										
											2000-08-02 01:44:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # And the real information. | 
					
						
							| 
									
										
										
										
											2000-06-24 00:23:20 +00:00
										 |  |  |     format_command = { 'rpm':   ('bdist_rpm',  "RPM distribution"), | 
					
						
							| 
									
										
										
										
											2002-10-04 09:30:06 +00:00
										 |  |  |                        'zip':   ('bdist_dumb', "ZIP file"), | 
					
						
							|  |  |  |                        'gztar': ('bdist_dumb', "gzip'ed tar file"), | 
					
						
							| 
									
										
										
										
											2000-06-24 00:23:20 +00:00
										 |  |  |                        'bztar': ('bdist_dumb', "bzip2'ed tar file"), | 
					
						
							|  |  |  |                        'ztar':  ('bdist_dumb', "compressed tar file"), | 
					
						
							|  |  |  |                        'tar':   ('bdist_dumb', "tar file"), | 
					
						
							| 
									
										
										
										
											2000-06-27 01:24:07 +00:00
										 |  |  |                        'wininst': ('bdist_wininst', | 
					
						
							|  |  |  |                                    "Windows executable installer"), | 
					
						
							| 
									
										
										
										
											2000-08-02 01:44:44 +00:00
										 |  |  |                        'zip':   ('bdist_dumb', "ZIP file"), | 
					
						
							| 
									
										
										
										
											2002-10-04 09:30:06 +00:00
										 |  |  |                        #'pkgtool': ('bdist_pkgtool',  | 
					
						
							|  |  |  |                        #            "Solaris pkgtool distribution"), | 
					
						
							|  |  |  |                        #'sdux':  ('bdist_sdux', "HP-UX swinstall depot"), | 
					
						
							| 
									
										
										
										
											2002-04-17 20:30:10 +00:00
										 |  |  |                       } | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def initialize_options (self): | 
					
						
							| 
									
										
										
										
											2000-05-13 03:08:28 +00:00
										 |  |  |         self.bdist_base = None | 
					
						
							| 
									
										
										
										
											2000-09-11 00:47:35 +00:00
										 |  |  |         self.plat_name = None | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |         self.formats = None | 
					
						
							| 
									
										
										
										
											2000-07-05 03:07:18 +00:00
										 |  |  |         self.dist_dir = None | 
					
						
							| 
									
										
										
										
											2002-01-12 11:27:42 +00:00
										 |  |  |         self.skip_build = 0 | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # initialize_options() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def finalize_options (self): | 
					
						
							| 
									
										
										
										
											2000-09-11 00:47:35 +00:00
										 |  |  |         # have to finalize 'plat_name' before 'bdist_base' | 
					
						
							|  |  |  |         if self.plat_name is None: | 
					
						
							|  |  |  |             self.plat_name = get_platform() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-13 03:08:28 +00:00
										 |  |  |         # 'bdist_base' -- parent of per-built-distribution-format | 
					
						
							|  |  |  |         # temporary directories (eg. we'll probably have | 
					
						
							|  |  |  |         # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.) | 
					
						
							|  |  |  |         if self.bdist_base is None: | 
					
						
							| 
									
										
										
										
											2000-05-27 17:27:23 +00:00
										 |  |  |             build_base = self.get_finalized_command('build').build_base | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |             self.bdist_base = os.path.join(build_base, | 
					
						
							|  |  |  |                                            'bdist.' + self.plat_name) | 
					
						
							| 
									
										
										
										
											2000-05-13 03:08:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |         self.ensure_string_list('formats') | 
					
						
							|  |  |  |         if self.formats is None: | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  |             try: | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |                 self.formats = [self.default_format[os.name]] | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  |             except KeyError: | 
					
						
							|  |  |  |                 raise DistutilsPlatformError, \ | 
					
						
							|  |  |  |                       "don't know how to create built distributions " + \ | 
					
						
							|  |  |  |                       "on platform %s" % os.name | 
					
						
							| 
									
										
										
										
											2000-07-05 03:07:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.dist_dir is None: | 
					
						
							|  |  |  |             self.dist_dir = "dist" | 
					
						
							| 
									
										
										
										
											2001-12-06 21:01:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  |     # finalize_options() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def run (self): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |         # Figure out which sub-commands we need to run. | 
					
						
							|  |  |  |         commands = [] | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |         for format in self.formats: | 
					
						
							|  |  |  |             try: | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |                 commands.append(self.format_command[format][0]) | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |             except KeyError: | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |                 raise DistutilsOptionError, "invalid format '%s'" % format | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |         # Reinitialize and run each command. | 
					
						
							|  |  |  |         for i in range(len(self.formats)): | 
					
						
							|  |  |  |             cmd_name = commands[i] | 
					
						
							| 
									
										
										
										
											2000-06-06 02:51:38 +00:00
										 |  |  |             sub_cmd = self.reinitialize_command(cmd_name) | 
					
						
							|  |  |  |             if cmd_name not in self.no_format_option: | 
					
						
							| 
									
										
										
										
											2000-09-16 16:04:59 +00:00
										 |  |  |                 sub_cmd.format = self.formats[i] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # If we're going to need to run this command again, tell it to | 
					
						
							|  |  |  |             # keep its temporary files around so subsequent runs go faster. | 
					
						
							|  |  |  |             if cmd_name in commands[i+1:]: | 
					
						
							|  |  |  |                 sub_cmd.keep_temp = 1 | 
					
						
							| 
									
										
										
										
											2000-09-30 18:27:54 +00:00
										 |  |  |             self.run_command(cmd_name) | 
					
						
							| 
									
										
										
										
											2000-03-31 02:55:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # run() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # class bdist |