2000-05-11 22:58:29 -03:00
|
|
|
"""distutils.command.install_data
|
|
|
|
|
|
|
|
Implements the Distutils 'install_data' command, for installing
|
|
|
|
platform-independent data files."""
|
|
|
|
|
|
|
|
# contributed by Bastian Kleineidam
|
|
|
|
|
2002-11-19 09:12:28 -04:00
|
|
|
# This module should be kept compatible with Python 1.5.2.
|
|
|
|
|
2000-05-11 22:58:29 -03:00
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2000-05-24 22:19:18 -03:00
|
|
|
import os
|
|
|
|
from types import StringType
|
|
|
|
from distutils.core import Command
|
2001-01-28 08:22:14 -04:00
|
|
|
from distutils.util import change_root, convert_path
|
2000-05-11 21:52:23 -03:00
|
|
|
|
2000-05-24 22:19:18 -03:00
|
|
|
class install_data (Command):
|
2000-05-11 21:52:23 -03:00
|
|
|
|
|
|
|
description = "install data files"
|
|
|
|
|
2000-05-24 22:19:18 -03:00
|
|
|
user_options = [
|
|
|
|
('install-dir=', 'd',
|
2000-07-26 23:13:20 -03:00
|
|
|
"base directory for installing data files "
|
2000-06-24 14:36:24 -03:00
|
|
|
"(default: installation base dir)"),
|
2000-05-24 22:19:18 -03:00
|
|
|
('root=', None,
|
|
|
|
"install everything relative to this alternate root directory"),
|
2000-09-12 22:02:25 -03:00
|
|
|
('force', 'f', "force installation (overwrite existing files)"),
|
2000-05-24 22:19:18 -03:00
|
|
|
]
|
|
|
|
|
2000-09-24 22:41:15 -03:00
|
|
|
boolean_options = ['force']
|
|
|
|
|
2000-05-24 22:19:18 -03:00
|
|
|
def initialize_options (self):
|
|
|
|
self.install_dir = None
|
2000-06-21 00:13:51 -03:00
|
|
|
self.outfiles = []
|
2000-05-24 22:19:18 -03:00
|
|
|
self.root = None
|
2000-09-12 22:02:25 -03:00
|
|
|
self.force = 0
|
2000-09-14 22:21:07 -03:00
|
|
|
|
2000-05-24 22:19:18 -03:00
|
|
|
self.data_files = self.distribution.data_files
|
2000-09-14 22:21:07 -03:00
|
|
|
self.warn_dir = 1
|
2000-05-24 22:19:18 -03:00
|
|
|
|
2000-05-11 21:52:23 -03:00
|
|
|
def finalize_options (self):
|
2000-05-24 22:19:18 -03:00
|
|
|
self.set_undefined_options('install',
|
2000-10-14 01:06:40 -03:00
|
|
|
('install_data', 'install_dir'),
|
|
|
|
('root', 'root'),
|
2000-09-12 22:02:25 -03:00
|
|
|
('force', 'force'),
|
2000-10-14 01:06:40 -03:00
|
|
|
)
|
2000-05-11 21:52:23 -03:00
|
|
|
|
|
|
|
def run (self):
|
2000-05-24 22:19:18 -03:00
|
|
|
self.mkpath(self.install_dir)
|
|
|
|
for f in self.data_files:
|
2002-11-26 17:28:23 -04:00
|
|
|
if type(f) is StringType:
|
2000-06-24 14:36:24 -03:00
|
|
|
# it's a simple file, so copy it
|
2001-01-28 08:22:14 -04:00
|
|
|
f = convert_path(f)
|
2000-09-14 22:21:07 -03:00
|
|
|
if self.warn_dir:
|
|
|
|
self.warn("setup script did not provide a directory for "
|
|
|
|
"'%s' -- installing right in '%s'" %
|
|
|
|
(f, self.install_dir))
|
2000-09-30 14:34:50 -03:00
|
|
|
(out, _) = self.copy_file(f, self.install_dir)
|
2000-06-21 00:13:51 -03:00
|
|
|
self.outfiles.append(out)
|
2000-05-24 22:19:18 -03:00
|
|
|
else:
|
2000-06-24 14:36:24 -03:00
|
|
|
# it's a tuple with path to install to and a list of files
|
2001-01-28 08:22:14 -04:00
|
|
|
dir = convert_path(f[0])
|
2000-05-24 22:19:18 -03:00
|
|
|
if not os.path.isabs(dir):
|
|
|
|
dir = os.path.join(self.install_dir, dir)
|
|
|
|
elif self.root:
|
2000-05-24 23:14:26 -03:00
|
|
|
dir = change_root(self.root, dir)
|
2000-05-24 22:19:18 -03:00
|
|
|
self.mkpath(dir)
|
2001-09-04 17:42:08 -03:00
|
|
|
|
|
|
|
if f[1] == []:
|
|
|
|
# If there are no files listed, the user must be
|
|
|
|
# trying to create an empty directory, so add the
|
|
|
|
# directory to the list of output files.
|
|
|
|
self.outfiles.append(dir)
|
|
|
|
else:
|
|
|
|
# Copy files, adding them to the list of output files.
|
|
|
|
for data in f[1]:
|
|
|
|
data = convert_path(data)
|
|
|
|
(out, _) = self.copy_file(data, dir)
|
|
|
|
self.outfiles.append(out)
|
2000-05-13 00:07:53 -03:00
|
|
|
|
|
|
|
def get_inputs (self):
|
2000-05-24 22:19:18 -03:00
|
|
|
return self.data_files or []
|
|
|
|
|
|
|
|
def get_outputs (self):
|
2000-06-21 00:13:51 -03:00
|
|
|
return self.outfiles
|