/Lib/distutils/command/install_scripts.py

http://unladen-swallow.googlecode.com/ · Python · 66 lines · 64 code · 0 blank · 2 comment · 0 complexity · 2e471722de325e023b94ad0d99c9ddfa MD5 · raw file

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