ยปCore Development>Code coverage>Lib/distutils/command/install_data.py

Python code coverage for Lib/distutils/command/install_data.py

#countcontent
1n/a"""distutils.command.install_data
2n/a
3n/aImplements the Distutils 'install_data' command, for installing
4n/aplatform-independent data files."""
5n/a
6n/a# contributed by Bastian Kleineidam
7n/a
8n/aimport os
9n/afrom distutils.core import Command
10n/afrom distutils.util import change_root, convert_path
11n/a
12n/aclass install_data(Command):
13n/a
14n/a description = "install data files"
15n/a
16n/a user_options = [
17n/a ('install-dir=', 'd',
18n/a "base directory for installing data files "
19n/a "(default: installation base dir)"),
20n/a ('root=', None,
21n/a "install everything relative to this alternate root directory"),
22n/a ('force', 'f', "force installation (overwrite existing files)"),
23n/a ]
24n/a
25n/a boolean_options = ['force']
26n/a
27n/a def initialize_options(self):
28n/a self.install_dir = None
29n/a self.outfiles = []
30n/a self.root = None
31n/a self.force = 0
32n/a self.data_files = self.distribution.data_files
33n/a self.warn_dir = 1
34n/a
35n/a def finalize_options(self):
36n/a self.set_undefined_options('install',
37n/a ('install_data', 'install_dir'),
38n/a ('root', 'root'),
39n/a ('force', 'force'),
40n/a )
41n/a
42n/a def run(self):
43n/a self.mkpath(self.install_dir)
44n/a for f in self.data_files:
45n/a if isinstance(f, str):
46n/a # it's a simple file, so copy it
47n/a f = convert_path(f)
48n/a if self.warn_dir:
49n/a self.warn("setup script did not provide a directory for "
50n/a "'%s' -- installing right in '%s'" %
51n/a (f, self.install_dir))
52n/a (out, _) = self.copy_file(f, self.install_dir)
53n/a self.outfiles.append(out)
54n/a else:
55n/a # it's a tuple with path to install to and a list of files
56n/a dir = convert_path(f[0])
57n/a if not os.path.isabs(dir):
58n/a dir = os.path.join(self.install_dir, dir)
59n/a elif self.root:
60n/a dir = change_root(self.root, dir)
61n/a self.mkpath(dir)
62n/a
63n/a if f[1] == []:
64n/a # If there are no files listed, the user must be
65n/a # trying to create an empty directory, so add the
66n/a # directory to the list of output files.
67n/a self.outfiles.append(dir)
68n/a else:
69n/a # Copy files, adding them to the list of output files.
70n/a for data in f[1]:
71n/a data = convert_path(data)
72n/a (out, _) = self.copy_file(data, dir)
73n/a self.outfiles.append(out)
74n/a
75n/a def get_inputs(self):
76n/a return self.data_files or []
77n/a
78n/a def get_outputs(self):
79n/a return self.outfiles