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