• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""distutils.command.bdist_dumb
2
3Implements the Distutils 'bdist_dumb' command (create a "dumb" built
4distribution -- i.e., just an archive to be unpacked under $prefix or
5$exec_prefix)."""
6
7__revision__ = "$Id$"
8
9import os
10
11from sysconfig import get_python_version
12
13from distutils.util import get_platform
14from distutils.core import Command
15from distutils.dir_util import remove_tree, ensure_relative
16from distutils.errors import DistutilsPlatformError
17from distutils import log
18
19class bdist_dumb (Command):
20
21    description = 'create a "dumb" built distribution'
22
23    user_options = [('bdist-dir=', 'd',
24                     "temporary directory for creating the distribution"),
25                    ('plat-name=', 'p',
26                     "platform name to embed in generated filenames "
27                     "(default: %s)" % get_platform()),
28                    ('format=', 'f',
29                     "archive format to create (tar, ztar, gztar, zip)"),
30                    ('keep-temp', 'k',
31                     "keep the pseudo-installation tree around after " +
32                     "creating the distribution archive"),
33                    ('dist-dir=', 'd',
34                     "directory to put final built distributions in"),
35                    ('skip-build', None,
36                     "skip rebuilding everything (for testing/debugging)"),
37                    ('relative', None,
38                     "build the archive using relative paths"
39                     "(default: false)"),
40                    ('owner=', 'u',
41                     "Owner name used when creating a tar file"
42                     " [default: current user]"),
43                    ('group=', 'g',
44                     "Group name used when creating a tar file"
45                     " [default: current group]"),
46                   ]
47
48    boolean_options = ['keep-temp', 'skip-build', 'relative']
49
50    default_format = { 'posix': 'gztar',
51                       'nt': 'zip',
52                       '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 = None
62        self.relative = 0
63        self.owner = None
64        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            self.bdist_dir = os.path.join(bdist_base, 'dumb')
70
71        if self.format is None:
72            try:
73                self.format = self.default_format[os.name]
74            except KeyError:
75                raise DistutilsPlatformError, \
76                      ("don't know how to create dumb built distributions " +
77                       "on platform %s") % os.name
78
79        self.set_undefined_options('bdist',
80                                   ('dist_dir', 'dist_dir'),
81                                   ('plat_name', 'plat_name'),
82                                   ('skip_build', 'skip_build'))
83
84    def run(self):
85        if not self.skip_build:
86            self.run_command('build')
87
88        install = self.reinitialize_command('install', reinit_subcommands=1)
89        install.root = self.bdist_dir
90        install.skip_build = self.skip_build
91        install.warn_dir = 0
92
93        log.info("installing to %s" % self.bdist_dir)
94        self.run_command('install')
95
96        # And make an archive relative to the root of the
97        # pseudo-installation tree.
98        archive_basename = "%s.%s" % (self.distribution.get_fullname(),
99                                      self.plat_name)
100
101        # OS/2 objects to any ":" characters in a filename (such as when
102        # a timestamp is used in a version) so change them to hyphens.
103        if os.name == "os2":
104            archive_basename = archive_basename.replace(":", "-")
105
106        pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
107        if not self.relative:
108            archive_root = self.bdist_dir
109        else:
110            if (self.distribution.has_ext_modules() and
111                (install.install_base != install.install_platbase)):
112                raise DistutilsPlatformError, \
113                      ("can't make a dumb built distribution where "
114                       "base and platbase are different (%s, %s)"
115                       % (repr(install.install_base),
116                          repr(install.install_platbase)))
117            else:
118                archive_root = os.path.join(self.bdist_dir,
119                                   ensure_relative(install.install_base))
120
121        # Make the archive
122        filename = self.make_archive(pseudoinstall_root,
123                                     self.format, root_dir=archive_root,
124                                     owner=self.owner, group=self.group)
125        if self.distribution.has_ext_modules():
126            pyversion = get_python_version()
127        else:
128            pyversion = 'any'
129        self.distribution.dist_files.append(('bdist_dumb', pyversion,
130                                             filename))
131
132        if not self.keep_temp:
133            remove_tree(self.bdist_dir, dry_run=self.dry_run)
134