home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / INSTALL_DATA.PY < prev    next >
Encoding:
Python Source  |  2000-10-14  |  2.5 KB  |  74 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.16 2000/10/14 04:06:40 gward Exp $"
  9.  
  10. import os
  11. from types import StringType
  12. from distutils.core import Command
  13. from distutils.util import change_root
  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.                 if self.warn_dir:
  52.                     self.warn("setup script did not provide a directory for "
  53.                               "'%s' -- installing right in '%s'" %
  54.                               (f, self.install_dir))
  55.                 (out, _) = self.copy_file(f, self.install_dir)
  56.                 self.outfiles.append(out)
  57.             else:
  58.                 # it's a tuple with path to install to and a list of files
  59.                 dir = f[0]
  60.                 if not os.path.isabs(dir):
  61.                     dir = os.path.join(self.install_dir, dir)
  62.                 elif self.root:
  63.                     dir = change_root(self.root, dir)
  64.                 self.mkpath(dir)
  65.                 for data in f[1]:
  66.                     (out, _) = self.copy_file(data, dir)
  67.                     self.outfiles.append(out)
  68.  
  69.     def get_inputs (self):
  70.         return self.data_files or []
  71.  
  72.     def get_outputs (self):
  73.         return self.outfiles
  74.