You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

  1. """Install scripts."""
  2. # Contributed by Bastian Kleineidam
  3. import os
  4. from packaging.command.cmd import Command
  5. from packaging import logger
  6. class install_scripts(Command):
  7. description = "install scripts (Python or otherwise)"
  8. user_options = [
  9. ('install-dir=', 'd', "directory to install scripts to"),
  10. ('build-dir=','b', "build directory (where to install from)"),
  11. ('force', 'f', "force installation (overwrite existing files)"),
  12. ('skip-build', None, "skip the build steps"),
  13. ]
  14. boolean_options = ['force', 'skip-build']
  15. def initialize_options(self):
  16. self.install_dir = None
  17. self.force = False
  18. self.build_dir = None
  19. self.skip_build = None
  20. def finalize_options(self):
  21. self.set_undefined_options('build', ('build_scripts', 'build_dir'))
  22. self.set_undefined_options('install_dist',
  23. ('install_scripts', 'install_dir'),
  24. 'force', 'skip_build')
  25. def run(self):
  26. if not self.skip_build:
  27. self.run_command('build_scripts')
  28. if not os.path.exists(self.build_dir):
  29. self.outfiles = []
  30. return
  31. self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
  32. if os.name == 'posix':
  33. # Set the executable bits (owner, group, and world) on
  34. # all the scripts we just installed.
  35. for file in self.get_outputs():
  36. if self.dry_run:
  37. logger.info("changing mode of %s", file)
  38. else:
  39. mode = (os.stat(file).st_mode | 0o555) & 0o7777
  40. logger.info("changing mode of %s to %o", file, mode)
  41. os.chmod(file, mode)
  42. def get_inputs(self):
  43. return self.distribution.scripts or []
  44. def get_outputs(self):
  45. return self.outfiles or []