Files for 2.1b1 distribution.
[python/dscho.git] / Lib / distutils / command / install_data.py
blob28f593866cae2012398b720d364c59757f43afbc
1 """distutils.command.install_data
3 Implements the Distutils 'install_data' command, for installing
4 platform-independent data files."""
6 # contributed by Bastian Kleineidam
8 __revision__ = "$Id$"
10 import os
11 from types import StringType
12 from distutils.core import Command
13 from distutils.util import change_root, convert_path
15 class install_data (Command):
17 description = "install data files"
19 user_options = [
20 ('install-dir=', 'd',
21 "base directory for installing data files "
22 "(default: installation base dir)"),
23 ('root=', None,
24 "install everything relative to this alternate root directory"),
25 ('force', 'f', "force installation (overwrite existing files)"),
28 boolean_options = ['force']
30 def initialize_options (self):
31 self.install_dir = None
32 self.outfiles = []
33 self.root = None
34 self.force = 0
36 self.data_files = self.distribution.data_files
37 self.warn_dir = 1
39 def finalize_options (self):
40 self.set_undefined_options('install',
41 ('install_data', 'install_dir'),
42 ('root', 'root'),
43 ('force', 'force'),
46 def run (self):
47 self.mkpath(self.install_dir)
48 for f in self.data_files:
49 if type(f) == StringType:
50 # it's a simple file, so copy it
51 f = convert_path(f)
52 if self.warn_dir:
53 self.warn("setup script did not provide a directory for "
54 "'%s' -- installing right in '%s'" %
55 (f, self.install_dir))
56 (out, _) = self.copy_file(f, self.install_dir)
57 self.outfiles.append(out)
58 else:
59 # it's a tuple with path to install to and a list of files
60 dir = convert_path(f[0])
61 if not os.path.isabs(dir):
62 dir = os.path.join(self.install_dir, dir)
63 elif self.root:
64 dir = change_root(self.root, dir)
65 self.mkpath(dir)
66 for data in f[1]:
67 data = convert_path(data)
68 (out, _) = self.copy_file(data, dir)
69 self.outfiles.append(out)
71 def get_inputs (self):
72 return self.data_files or []
74 def get_outputs (self):
75 return self.outfiles