Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/install_data.py @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 3e26c9033306 |
| children |
| 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 |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
8 import os |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
9 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
|
10 from distutils.util import change_root, convert_path |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
11 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
12 class install_data(Command): |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
13 |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
14 description = "install data files" |
|
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
15 |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
16 user_options = [ |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
17 ('install-dir=', 'd', |
|
13725
449dd3a00bd7
Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents:
13004
diff
changeset
|
18 "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
|
19 "(default: installation base dir)"), |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
20 ('root=', None, |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
21 "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
|
22 ('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
|
23 ] |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
24 |
|
14829
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14576
diff
changeset
|
25 boolean_options = ['force'] |
|
b1f220f636ed
Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents:
14576
diff
changeset
|
26 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
27 def initialize_options(self): |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
28 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
|
29 self.outfiles = [] |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
30 self.root = None |
|
14540
35ae8dff8ed0
Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents:
13725
diff
changeset
|
31 self.force = 0 |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
32 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
|
33 self.warn_dir = 1 |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
34 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
35 def finalize_options(self): |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
36 self.set_undefined_options('install', |
| 15216 | 37 ('install_data', 'install_dir'), |
| 38 ('root', 'root'), | |
|
14540
35ae8dff8ed0
Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents:
13725
diff
changeset
|
39 ('force', 'force'), |
| 15216 | 40 ) |
|
12675
de435a59a4d5
Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
41 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
42 def run(self): |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
43 self.mkpath(self.install_dir) |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
44 for f in self.data_files: |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
45 if isinstance(f, str): |
|
13004
37ba7056d4ab
Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents:
12981
diff
changeset
|
46 # 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
|
47 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
|
48 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
|
49 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
|
50 "'%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
|
51 (f, self.install_dir)) |
|
14945
a59600a975d1
Expect a tuple (dest_name, copied) from 'copy_file()'.
Greg Ward <gward@python.net>
parents:
14829
diff
changeset
|
52 (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
|
53 self.outfiles.append(out) |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
54 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
|
55 # 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
|
56 dir = convert_path(f[0]) |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
57 if not os.path.isabs(dir): |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
58 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
|
59 elif self.root: |
|
12749
bce49a6fa8b9
Fix to use 'change_root()' rather than directly mangling path.
Greg Ward <gward@python.net>
parents:
12744
diff
changeset
|
60 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
|
61 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
|
62 |
|
fbaf4e55263f
[Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents:
16456
diff
changeset
|
63 if f[1] == []: |
|
fbaf4e55263f
[Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents:
16456
diff
changeset
|
64 # 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
|
65 # 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
|
66 # 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
|
67 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
|
68 else: |
|
fbaf4e55263f
[Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents:
16456
diff
changeset
|
69 # 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
|
70 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
|
71 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
|
72 (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
|
73 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
|
74 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
75 def get_inputs(self): |
|
12744
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
76 return self.data_files or [] |
|
eeafab8c925b
Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents:
12704
diff
changeset
|
77 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
78 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
|
79 return self.outfiles |
