Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Lib / distutils / command / bdist_dumb.py
blob5456e57ac32ae4e1c9876550e1dfade6bd129517
1 """distutils.command.bdist_dumb
3 Implements the Distutils 'bdist_dumb' command (create a "dumb" built
4 distribution -- i.e., just an archive to be unpacked under $prefix or
5 $exec_prefix)."""
7 # created 2000/03/29, Greg Ward
9 __revision__ = "$Id$"
11 import os
12 from distutils.core import Command
13 from distutils.util import get_platform, create_tree, remove_tree
16 class bdist_dumb (Command):
18 description = "create a \"dumb\" built distribution"
20 user_options = [('format=', 'f',
21 "archive format to create (tar, ztar, gztar, zip)"),
22 ('keep-tree', 'k',
23 "keep the pseudo-installation tree around after " +
24 "creating the distribution archive"),
27 default_format = { 'posix': 'gztar',
28 'nt': 'zip', }
31 def initialize_options (self):
32 self.format = None
33 self.keep_tree = 0
35 # initialize_options()
38 def finalize_options (self):
39 if self.format is None:
40 try:
41 self.format = self.default_format[os.name]
42 except KeyError:
43 raise DistutilsPlatformError, \
44 ("don't know how to create dumb built distributions " +
45 "on platform %s") % os.name
47 # finalize_options()
50 def run (self):
52 self.run_peer ('build')
53 install = self.find_peer ('install')
54 inputs = install.get_inputs ()
55 outputs = install.get_outputs ()
56 assert (len (inputs) == len (outputs))
58 # First, strip the installation base directory (prefix or
59 # exec-prefix) from all the output filenames.
60 self.strip_base_dirs (outputs, install)
62 # Figure out where to copy them to: "build/bdist" by default; this
63 # directory masquerades as prefix/exec-prefix (ie. we'll make the
64 # archive from 'output_dir').
65 build_base = self.get_peer_option ('build', 'build_base')
66 output_dir = os.path.join (build_base, "bdist")
68 # Copy the built files to the pseudo-installation tree.
69 self.make_install_tree (output_dir, inputs, outputs)
71 # And make an archive relative to the root of the
72 # pseudo-installation tree.
73 archive_basename = "%s.%s" % (self.distribution.get_full_name(),
74 get_platform())
75 print "output_dir = %s" % output_dir
76 print "self.format = %s" % self.format
77 self.make_archive (archive_basename, self.format,
78 root_dir=output_dir)
80 if not self.keep_tree:
81 remove_tree (output_dir, self.verbose, self.dry_run)
83 # run()
86 def strip_base_dirs (self, outputs, install_cmd):
87 # XXX this throws away the prefix/exec-prefix distinction, and
88 # means we can only correctly install the resulting archive on a
89 # system where prefix == exec-prefix (but at least we can *create*
90 # it on one where they differ). I don't see a way to fix this
91 # without either 1) generating two archives, one for prefix and one
92 # for exec-prefix, or 2) putting absolute paths in the archive
93 # rather than making them relative to one of the prefixes.
95 base = install_cmd.install_base + os.sep
96 platbase = install_cmd.install_platbase + os.sep
97 b_len = len (base)
98 pb_len = len (platbase)
99 for i in range (len (outputs)):
100 if outputs[i][0:b_len] == base:
101 outputs[i] = outputs[i][b_len:]
102 elif outputs[i][0:pb_len] == platbase:
103 outputs[i] = outputs[i][pb_len:]
104 else:
105 raise DistutilsInternalError, \
106 ("installation output filename '%s' doesn't start " +
107 "with either install_base ('%s') or " +
108 "install_platbase ('%s')") % \
109 (outputs[i], base, platbase)
111 # strip_base_dirs()
114 def make_install_tree (self, output_dir, inputs, outputs):
116 assert (len(inputs) == len(outputs))
118 # Create all the directories under 'output_dir' necessary to
119 # put 'outputs' there.
120 create_tree (output_dir, outputs,
121 verbose=self.verbose, dry_run=self.dry_run)
124 # XXX this bit of logic is duplicated in sdist.make_release_tree():
125 # would be nice to factor it out...
126 if hasattr (os, 'link'): # can make hard links on this system
127 link = 'hard'
128 msg = "making hard links in %s..." % output_dir
129 else: # nope, have to copy
130 link = None
131 msg = "copying files to %s..." % output_dir
133 for i in range (len(inputs)):
134 output = os.path.join (output_dir, outputs[i])
135 self.copy_file (inputs[i], output, link=link)
137 # make_install_tree ()
140 # class bdist_dumb