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