0001 """distutils.command.install_data 0002 0003 Implements the Distutils 'install_data' command, for installing 0004 platform-independent data files.""" 0005 0006 # contributed by Bastian Kleineidam 0007 0008 # This module should be kept compatible with Python 1.5.2. 0009 0010 __revision__ = "$Id: install_data.py,v 1.21 2002/11/26 21:28:23 fdrake Exp $" 0011 0012 import os 0013 from types import StringType 0014 from distutils.core import Command 0015 from distutils.util import change_root, convert_path 0016 0017 class install_data (Command): 0018 0019 description = "install data files" 0020 0021 user_options = [ 0022 ('install-dir=', 'd', 0023 "base directory for installing data files " 0024 "(default: installation base dir)"), 0025 ('root=', None, 0026 "install everything relative to this alternate root directory"), 0027 ('force', 'f', "force installation (overwrite existing files)"), 0028 ] 0029 0030 boolean_options = ['force'] 0031 0032 def initialize_options (self): 0033 self.install_dir = None 0034 self.outfiles = [] 0035 self.root = None 0036 self.force = 0 0037 0038 self.data_files = self.distribution.data_files 0039 self.warn_dir = 1 0040 0041 def finalize_options (self): 0042 self.set_undefined_options('install', 0043 ('install_data', 'install_dir'), 0044 ('root', 'root'), 0045 ('force', 'force'), 0046 ) 0047 0048 def run (self): 0049 self.mkpath(self.install_dir) 0050 for f in self.data_files: 0051 if type(f) is StringType: 0052 # it's a simple file, so copy it 0053 f = convert_path(f) 0054 if self.warn_dir: 0055 self.warn("setup script did not provide a directory for " 0056 "'%s' -- installing right in '%s'" % 0057 (f, self.install_dir)) 0058 (out, _) = self.copy_file(f, self.install_dir) 0059 self.outfiles.append(out) 0060 else: 0061 # it's a tuple with path to install to and a list of files 0062 dir = convert_path(f[0]) 0063 if not os.path.isabs(dir): 0064 dir = os.path.join(self.install_dir, dir) 0065 elif self.root: 0066 dir = change_root(self.root, dir) 0067 self.mkpath(dir) 0068 0069 if f[1] == []: 0070 # If there are no files listed, the user must be 0071 # trying to create an empty directory, so add the 0072 # directory to the list of output files. 0073 self.outfiles.append(dir) 0074 else: 0075 # Copy files, adding them to the list of output files. 0076 for data in f[1]: 0077 data = convert_path(data) 0078 (out, _) = self.copy_file(data, dir) 0079 self.outfiles.append(out) 0080 0081 def get_inputs (self): 0082 return self.data_files or [] 0083 0084 def get_outputs (self): 0085 return self.outfiles 0086
Generated by PyXR 0.9.4