home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / INSTALL_DATA.PY < prev    next >
Encoding:
Python Source  |  2001-09-04  |  3.0 KB  |  84 lines

  1. """distutils.command.install_data
  2.  
  3. Implements the Distutils 'install_data' command, for installing
  4. platform-independent data files."""
  5.  
  6. # contributed by Bastian Kleineidam
  7.  
  8. __revision__ = "$Id: install_data.py,v 1.19 2001/09/04 20:42:08 akuchling Exp $"
  9.  
  10. import os
  11. from types import StringType
  12. from distutils.core import Command
  13. from distutils.util import change_root, convert_path
  14.  
  15. class install_data (Command):
  16.  
  17.     description = "install data files"
  18.  
  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)"),
  26.         ]
  27.  
  28.     boolean_options = ['force']
  29.  
  30.     def initialize_options (self):
  31.         self.install_dir = None
  32.         self.outfiles = []
  33.         self.root = None
  34.         self.force = 0
  35.  
  36.         self.data_files = self.distribution.data_files
  37.         self.warn_dir = 1
  38.  
  39.     def finalize_options (self):
  40.         self.set_undefined_options('install',
  41.                                    ('install_data', 'install_dir'),
  42.                                    ('root', 'root'),
  43.                                    ('force', 'force'),
  44.                                   )
  45.  
  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.  
  67.                 if f[1] == []:
  68.                     # If there are no files listed, the user must be
  69.                     # trying to create an empty directory, so add the
  70.                     # directory to the list of output files.
  71.                     self.outfiles.append(dir)
  72.                 else:
  73.                     # Copy files, adding them to the list of output files.
  74.                     for data in f[1]:
  75.                         data = convert_path(data)
  76.                         (out, _) = self.copy_file(data, dir)
  77.                         self.outfiles.append(out)
  78.  
  79.     def get_inputs (self):
  80.         return self.data_files or []
  81.  
  82.     def get_outputs (self):
  83.         return self.outfiles
  84.