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