Guest User

Untitled

a guest
Oct 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. from setuptools.command.install import install
  2. import subprocess
  3. from threading import Timer
  4.  
  5.  
  6. class CustomInstallCommand(install):
  7. """Custom install command to allow dcr installation."""
  8.  
  9. def _install_dcr(self, install_script='install_dcr.sh'):
  10. print("Running DCR installer")
  11. command = 'sh {:s}'.format(install_script)
  12.  
  13. try:
  14. install_dcr = subprocess.Popen(command.split(),
  15. stdout=subprocess.PIPE,
  16. stderr=subprocess.PIPE)
  17.  
  18. except OSError as error:
  19. print(error)
  20.  
  21. install_timer = Timer(10, self._kill_process, [install_dcr])
  22.  
  23. try:
  24. install_timer.start()
  25. stdout, stderr = install_dcr.communicate()
  26. finally:
  27. install_timer.cancel()
  28.  
  29. for _line in stdout.split(b'\n'):
  30. print(_line.decode("utf-8"))
  31.  
  32. for _line in stderr.split(b'\n'):
  33. print(_line.decode("utf-8"))
  34.  
  35. @staticmethod
  36. def _kill_process(process):
  37. process.kill()
  38.  
  39. def run(self):
  40.  
  41. self._install_dcr(install_script='install_dcr.sh')
  42. install.run(self)
  43.  
  44.  
  45. cmdclassd = {'install': CustomInstallCommand}
  46.  
  47.  
  48. setup(....
  49. cmdclass=cmdclassd,
  50. .....)
Add Comment
Please, Sign In to add comment