| OLD | NEW |
| (Empty) |
| 1 """ | |
| 2 A release-automation toolkit. | |
| 3 | |
| 4 Don't use this outside of Twisted. | |
| 5 | |
| 6 Maintainer: U{Christopher Armstrong<mailto:radix@twistedmatrix.com>} | |
| 7 """ | |
| 8 | |
| 9 import os | |
| 10 import re | |
| 11 | |
| 12 | |
| 13 # errors | |
| 14 | |
| 15 class DirectoryExists(OSError): | |
| 16 """Some directory exists when it shouldn't.""" | |
| 17 pass | |
| 18 | |
| 19 | |
| 20 | |
| 21 class DirectoryDoesntExist(OSError): | |
| 22 """Some directory doesn't exist when it should.""" | |
| 23 pass | |
| 24 | |
| 25 | |
| 26 | |
| 27 class CommandFailed(OSError): | |
| 28 pass | |
| 29 | |
| 30 | |
| 31 | |
| 32 # utilities | |
| 33 | |
| 34 def sh(command, null=True, prompt=False): | |
| 35 """ | |
| 36 I'll try to execute `command', and if `prompt' is true, I'll | |
| 37 ask before running it. If the command returns something other | |
| 38 than 0, I'll raise CommandFailed(command). | |
| 39 """ | |
| 40 print "--$", command | |
| 41 | |
| 42 if prompt: | |
| 43 if raw_input("run ?? ").startswith('n'): | |
| 44 return | |
| 45 if null: | |
| 46 command = "%s > /dev/null" % command | |
| 47 if os.system(command) != 0: | |
| 48 raise CommandFailed(command) | |
| 49 | |
| 50 | |
| 51 | |
| 52 def runChdirSafe(f, *args, **kw): | |
| 53 origdir = os.path.abspath('.') | |
| 54 try: | |
| 55 return f(*args, **kw) | |
| 56 finally: | |
| 57 os.chdir(origdir) | |
| OLD | NEW |