bdist_dumb.py 5.01 KB
Newer Older
1 2 3 4 5 6 7 8 9
"""distutils.command.bdist_dumb

Implements the Distutils 'bdist_dumb' command (create a "dumb" built
distribution -- i.e., just an archive to be unpacked under $prefix or
$exec_prefix)."""

__revision__ = "$Id$"

import os
10

11
from sysconfig import get_python_version
12

13
from distutils.util import get_platform
14
from distutils.core import Command
15
from distutils.dir_util import remove_tree, ensure_relative
16
from distutils.errors import DistutilsPlatformError
17
from distutils import log
18 19 20

class bdist_dumb (Command):

21
    description = 'create a "dumb" built distribution'
22

23 24
    user_options = [('bdist-dir=', 'd',
                     "temporary directory for creating the distribution"),
25 26 27
                    ('plat-name=', 'p',
                     "platform name to embed in generated filenames "
                     "(default: %s)" % get_platform()),
28
                    ('format=', 'f',
29
                     "archive format to create (tar, ztar, gztar, zip)"),
30
                    ('keep-temp', 'k',
31 32
                     "keep the pseudo-installation tree around after " +
                     "creating the distribution archive"),
33 34
                    ('dist-dir=', 'd',
                     "directory to put final built distributions in"),
35 36
                    ('skip-build', None,
                     "skip rebuilding everything (for testing/debugging)"),
37 38 39
                    ('relative', None,
                     "build the archive using relative paths"
                     "(default: false)"),
40 41 42 43 44 45
                    ('owner=', 'u',
                     "Owner name used when creating a tar file"
                     " [default: current user]"),
                    ('group=', 'g',
                     "Group name used when creating a tar file"
                     " [default: current group]"),
46 47
                   ]

48
    boolean_options = ['keep-temp', 'skip-build', 'relative']
49

50
    default_format = { 'posix': 'gztar',
51 52
                       'nt': 'zip',
                       'os2': 'zip' }
53 54 55


    def initialize_options (self):
56
        self.bdist_dir = None
57
        self.plat_name = None
58
        self.format = None
59
        self.keep_temp = 0
60
        self.dist_dir = None
61
        self.skip_build = 0
62
        self.relative = 0
63 64
        self.owner = None
        self.group = None
65

66
    def finalize_options(self):
67
        if self.bdist_dir is None:
68
            bdist_base = self.get_finalized_command('bdist').bdist_base
69 70
            self.bdist_dir = os.path.join(bdist_base, 'dumb')

71 72 73 74 75 76 77 78
        if self.format is None:
            try:
                self.format = self.default_format[os.name]
            except KeyError:
                raise DistutilsPlatformError, \
                      ("don't know how to create dumb built distributions " +
                       "on platform %s") % os.name

79 80 81
        self.set_undefined_options('bdist',
                                   ('dist_dir', 'dist_dir'),
                                   ('plat_name', 'plat_name'))
82

83
    def run(self):
84 85
        if not self.skip_build:
            self.run_command('build')
86

87
        install = self.reinitialize_command('install', reinit_subcommands=1)
88
        install.root = self.bdist_dir
89
        install.skip_build = self.skip_build
90
        install.warn_dir = 0
91

92
        log.info("installing to %s" % self.bdist_dir)
93
        self.run_command('install')
94 95 96

        # And make an archive relative to the root of the
        # pseudo-installation tree.
97
        archive_basename = "%s.%s" % (self.distribution.get_fullname(),
98
                                      self.plat_name)
99 100 101 102 103 104

        # OS/2 objects to any ":" characters in a filename (such as when
        # a timestamp is used in a version) so change them to hyphens.
        if os.name == "os2":
            archive_basename = archive_basename.replace(":", "-")

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
        if not self.relative:
            archive_root = self.bdist_dir
        else:
            if (self.distribution.has_ext_modules() and
                (install.install_base != install.install_platbase)):
                raise DistutilsPlatformError, \
                      ("can't make a dumb built distribution where "
                       "base and platbase are different (%s, %s)"
                       % (repr(install.install_base),
                          repr(install.install_platbase)))
            else:
                archive_root = os.path.join(self.bdist_dir,
                                   ensure_relative(install.install_base))

        # Make the archive
121
        filename = self.make_archive(pseudoinstall_root,
122 123
                                     self.format, root_dir=archive_root,
                                     owner=self.owner, group=self.group)
124 125 126 127 128 129
        if self.distribution.has_ext_modules():
            pyversion = get_python_version()
        else:
            pyversion = 'any'
        self.distribution.dist_files.append(('bdist_dumb', pyversion,
                                             filename))
130

131
        if not self.keep_temp:
132
            remove_tree(self.bdist_dir, dry_run=self.dry_run)