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