annotate Lib/distutils/command/install_data.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 893d46576737
children a5229237eb50 29ae667f3239
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12682
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
1 """distutils.command.install_data
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
2
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
3 Implements the Distutils 'install_data' command, for installing
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
4 platform-independent data files."""
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
5
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
6 # contributed by Bastian Kleineidam
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
7
33965
893d46576737 Update compatibility comments to 2.1, corresponding to PEP 291 1.13.
Martin v. Löwis <martin@v.loewis.de>
parents: 26427
diff changeset
8 # This module should be kept compatible with Python 2.1.
26285
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 19700
diff changeset
9
12682
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
10 __revision__ = "$Id$"
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
11
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
12 import os
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
13 from types import StringType
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
14 from distutils.core import Command
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
15 from distutils.util import change_root, convert_path
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
17 class install_data (Command):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
18
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 description = "install data files"
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
21 user_options = [
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
22 ('install-dir=', 'd',
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 13004
diff changeset
23 "base directory for installing data files "
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
24 "(default: installation base dir)"),
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
25 ('root=', None,
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
26 "install everything relative to this alternate root directory"),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
27 ('force', 'f', "force installation (overwrite existing files)"),
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
28 ]
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
29
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
30 boolean_options = ['force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
31
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
32 def initialize_options (self):
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
33 self.install_dir = None
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
34 self.outfiles = []
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
35 self.root = None
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
36 self.force = 0
14576
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
37
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
38 self.data_files = self.distribution.data_files
14576
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
39 self.warn_dir = 1
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
40
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
41 def finalize_options (self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
42 self.set_undefined_options('install',
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
43 ('install_data', 'install_dir'),
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
44 ('root', 'root'),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
45 ('force', 'force'),
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
46 )
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
47
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
48 def run (self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
49 self.mkpath(self.install_dir)
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
50 for f in self.data_files:
26427
6511b16ffe89 Use "is" to test type objects, not "==".
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
51 if type(f) is StringType:
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
52 # it's a simple file, so copy it
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
53 f = convert_path(f)
14576
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
54 if self.warn_dir:
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
55 self.warn("setup script did not provide a directory for "
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
56 "'%s' -- installing right in '%s'" %
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
57 (f, self.install_dir))
14945
a59600a975d1 Expect a tuple (dest_name, copied) from 'copy_file()'.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
58 (out, _) = self.copy_file(f, self.install_dir)
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
59 self.outfiles.append(out)
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
60 else:
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
61 # it's a tuple with path to install to and a list of files
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
62 dir = convert_path(f[0])
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
63 if not os.path.isabs(dir):
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
64 dir = os.path.join(self.install_dir, dir)
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
65 elif self.root:
12749
bce49a6fa8b9 Fix to use 'change_root()' rather than directly mangling path.
Greg Ward <gward@python.net>
parents: 12744
diff changeset
66 dir = change_root(self.root, dir)
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
67 self.mkpath(dir)
19700
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
68
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
69 if f[1] == []:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
70 # If there are no files listed, the user must be
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
71 # trying to create an empty directory, so add the
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
72 # directory to the list of output files.
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
73 self.outfiles.append(dir)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
74 else:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
75 # Copy files, adding them to the list of output files.
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
76 for data in f[1]:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
77 data = convert_path(data)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
78 (out, _) = self.copy_file(data, dir)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
79 self.outfiles.append(out)
12702
58ad6196d81f Added 'get_inputs()' methods, needed by the "install" command's
Gregory P. Smith <greg@mad-scientist.com>
parents: 12682
diff changeset
80
58ad6196d81f Added 'get_inputs()' methods, needed by the "install" command's
Gregory P. Smith <greg@mad-scientist.com>
parents: 12682
diff changeset
81 def get_inputs (self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
82 return self.data_files or []
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
83
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
84 def get_outputs (self):
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
85 return self.outfiles