home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / INSTALL_SCRIPTS.PY < prev    next >
Encoding:
Python Source  |  2002-02-22  |  2.1 KB  |  64 lines

  1. """distutils.command.install_scripts
  2.  
  3. Implements the Distutils 'install_scripts' command, for installing
  4. Python scripts."""
  5.  
  6. # contributed by Bastian Kleineidam
  7.  
  8. __revision__ = "$Id: install_scripts.py,v 1.10.26.1 2002/02/22 13:19:54 mwh Exp $"
  9.  
  10. import os
  11. from distutils.core import Command
  12. from stat import ST_MODE
  13.  
  14. class install_scripts (Command):
  15.  
  16.     description = "install scripts (Python or otherwise)"
  17.  
  18.     user_options = [
  19.         ('install-dir=', 'd', "directory to install scripts to"),
  20.         ('build-dir=','b', "build directory (where to install from)"),
  21.         ('force', 'f', "force installation (overwrite existing files)"),
  22.         ('skip-build', None, "skip the build steps"),
  23.     ]
  24.  
  25.     boolean_options = ['force', 'skip-build']
  26.  
  27.  
  28.     def initialize_options (self):
  29.         self.install_dir = None
  30.         self.force = 0
  31.         self.build_dir = None
  32.         self.skip_build = None
  33.  
  34.     def finalize_options (self):
  35.         self.set_undefined_options('build', ('build_scripts', 'build_dir'))
  36.         self.set_undefined_options('install',
  37.                                    ('install_scripts', 'install_dir'),
  38.                                    ('force', 'force'),
  39.                                    ('skip_build', 'skip_build'),
  40.                                   )
  41.  
  42.     def run (self):
  43.         if not self.skip_build:
  44.             self.run_command('build_scripts')
  45.         self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
  46.         if os.name == 'posix':
  47.             # Set the executable bits (owner, group, and world) on
  48.             # all the scripts we just installed.
  49.             for file in self.get_outputs():
  50.                 if self.dry_run:
  51.                     self.announce("changing mode of %s" % file)
  52.                 else:
  53.                     mode = ((os.stat(file)[ST_MODE]) | 0111) & 07777
  54.                     self.announce("changing mode of %s to %o" % (file, mode))
  55.                     os.chmod(file, mode)
  56.  
  57.     def get_inputs (self):
  58.         return self.distribution.scripts or []
  59.  
  60.     def get_outputs(self):
  61.         return self.outfiles or []
  62.  
  63. # class install_scripts
  64.