Package buildbot :: Package slave :: Package commands :: Module utils
[frames] | no frames]

Source Code for Module buildbot.slave.commands.utils

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