1 import os
2
3 from twisted.python.procutils import which
4 from twisted.python import runtime
5
7 possibles = which(name)
8 if not possibles:
9 raise RuntimeError("Couldn't find executable for '%s'" % name)
10
11
12
13
14
15
16
17
18
19 if runtime.platformType == 'win32' and len(possibles) > 1:
20 possibles_exe = which(name + ".exe")
21 if possibles_exe:
22 return possibles_exe[0]
23 return possibles[0]
24
25 if runtime.platformType == 'win32':
27 """This is a replacement for shutil.rmtree that works better under
28 windows. Thanks to Bear at the OSAF for the code."""
29 if not os.path.exists(dir):
30 return
31
32 if os.path.islink(dir):
33 os.remove(dir)
34 return
35
36
37 os.chmod(dir, 0700)
38
39 for name in os.listdir(dir):
40 full_name = os.path.join(dir, name)
41
42
43 if os.name == 'nt':
44 if not os.access(full_name, os.W_OK):
45
46
47
48 os.chmod(full_name, 0600)
49
50 if os.path.islink(full_name):
51 os.remove(full_name)
52 elif os.path.isdir(full_name):
53 rmdirRecursive(full_name)
54 else:
55 if os.path.isfile(full_name):
56 os.chmod(full_name, 0700)
57 os.remove(full_name)
58 os.rmdir(dir)
59 else:
60
61 import shutil
62 rmdirRecursive = shutil.rmtree
63