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.

release.py 1.2KB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. A release-automation toolkit.
  5. Don't use this outside of Twisted.
  6. Maintainer: Christopher Armstrong
  7. """
  8. from __future__ import print_function
  9. import os
  10. from twisted.python.compat import raw_input
  11. # errors
  12. class DirectoryExists(OSError):
  13. """
  14. Some directory exists when it shouldn't.
  15. """
  16. pass
  17. class DirectoryDoesntExist(OSError):
  18. """
  19. Some directory doesn't exist when it should.
  20. """
  21. pass
  22. class CommandFailed(OSError):
  23. pass
  24. # utilities
  25. def sh(command, null=True, prompt=False):
  26. """
  27. I'll try to execute C{command}, and if C{prompt} is true, I'll
  28. ask before running it. If the command returns something other
  29. than 0, I'll raise C{CommandFailed(command)}.
  30. """
  31. print("--$", command)
  32. if prompt:
  33. if raw_input("run ?? ").startswith('n'):
  34. return
  35. if null:
  36. command = "%s > /dev/null" % command
  37. if os.system(command) != 0:
  38. raise CommandFailed(command)
  39. def runChdirSafe(f, *args, **kw):
  40. origdir = os.path.abspath('.')
  41. try:
  42. return f(*args, **kw)
  43. finally:
  44. os.chdir(origdir)