Home | History | Annotate | Download | only in command
      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$"
      9 
     10 import os
     11 from distutils.core import Command
     12 from distutils import log
     13 from stat import ST_MODE
     14 
     15 class install_scripts (Command):
     16 
     17     description = "install scripts (Python or otherwise)"
     18 
     19     user_options = [
     20         ('install-dir=', 'd', "directory to install scripts to"),
     21         ('build-dir=','b', "build directory (where to install from)"),
     22         ('force', 'f', "force installation (overwrite existing files)"),
     23         ('skip-build', None, "skip the build steps"),
     24     ]
     25 
     26     boolean_options = ['force', 'skip-build']
     27 
     28 
     29     def initialize_options (self):
     30         self.install_dir = None
     31         self.force = 0
     32         self.build_dir = None
     33         self.skip_build = None
     34 
     35     def finalize_options (self):
     36         self.set_undefined_options('build', ('build_scripts', 'build_dir'))
     37         self.set_undefined_options('install',
     38                                    ('install_scripts', 'install_dir'),
     39                                    ('force', 'force'),
     40                                    ('skip_build', 'skip_build'),
     41                                   )
     42 
     43     def run (self):
     44         if not self.skip_build:
     45             self.run_command('build_scripts')
     46         self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
     47         if os.name == 'posix':
     48             # Set the executable bits (owner, group, and world) on
     49             # all the scripts we just installed.
     50             for file in self.get_outputs():
     51                 if self.dry_run:
     52                     log.info("changing mode of %s", file)
     53                 else:
     54                     mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777
     55                     log.info("changing mode of %s to %o", file, mode)
     56                     os.chmod(file, mode)
     57 
     58     def get_inputs (self):
     59         return self.distribution.scripts or []
     60 
     61     def get_outputs(self):
     62         return self.outfiles or []
     63 
     64 # class install_scripts
     65