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