Package buildslave :: Package commands :: Module utils
[frames] | no frames]

Source Code for Module buildslave.commands.utils

 1  import os 
 2   
 3  from twisted.python.procutils import which 
 4  from twisted.python import runtime 
 5   
6 -def getCommand(name):
7 possibles = which(name) 8 if not possibles: 9 raise RuntimeError("Couldn't find executable for '%s'" % name) 10 # 11 # Under windows, if there is more than one executable "thing" 12 # that matches (e.g. *.bat, *.cmd and *.exe), we not just use 13 # the first in alphabet (*.bat/*.cmd) if there is a *.exe. 14 # e.g. under MSysGit/Windows, there is both a git.cmd and a 15 # git.exe on path, but we want the git.exe, since the git.cmd 16 # does not seem to work properly with regard to errors raised 17 # and catched in buildbot slave command (vcs.py) 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':
26 - def rmdirRecursive(dir):
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 # Verify the directory is read/write/execute for the current user 37 os.chmod(dir, 0700) 38 39 for name in os.listdir(dir): 40 full_name = os.path.join(dir, name) 41 # on Windows, if we don't have write permission we can't remove 42 # the file/directory either, so turn that on 43 if os.name == 'nt': 44 if not os.access(full_name, os.W_OK): 45 # I think this is now redundant, but I don't have an NT 46 # machine to test on, so I'm going to leave it in place 47 # -warner 48 os.chmod(full_name, 0600) 49 50 if os.path.islink(full_name): 51 os.remove(full_name) # as suggested in bug #792 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 # use rmtree on POSIX 61 import shutil 62 rmdirRecursive = shutil.rmtree 63