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

Source Code for Module buildslave.commands.utils

 1  import os 
 2   
 3  from twisted.python import log 
 4  from twisted.python.procutils import which 
 5  from twisted.python import runtime 
 6   
7 -def getCommand(name):
8 possibles = which(name) 9 if not possibles: 10 raise RuntimeError("Couldn't find executable for '%s'" % name) 11 # 12 # Under windows, if there is more than one executable "thing" 13 # that matches (e.g. *.bat, *.cmd and *.exe), we not just use 14 # the first in alphabet (*.bat/*.cmd) if there is a *.exe. 15 # e.g. under MSysGit/Windows, there is both a git.cmd and a 16 # git.exe on path, but we want the git.exe, since the git.cmd 17 # does not seem to work properly with regard to errors raised 18 # and catched in buildbot slave command (vcs.py) 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':
27 - def rmdirRecursive(dir):
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 # Verify the directory is read/write/execute for the current user 38 os.chmod(dir, 0700) 39 40 # os.listdir below only returns a list of unicode filenames if the parameter is unicode 41 # Thus, if a non-unicode-named dir contains a unicode filename, that filename will get garbled. 42 # So force dir to be unicode. 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 # on Windows, if we don't have write permission we can't remove 51 # the file/directory either, so turn that on 52 if os.name == 'nt': 53 if not os.access(full_name, os.W_OK): 54 # I think this is now redundant, but I don't have an NT 55 # machine to test on, so I'm going to leave it in place 56 # -warner 57 os.chmod(full_name, 0600) 58 59 if os.path.islink(full_name): 60 os.remove(full_name) # as suggested in bug #792 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 # use rmtree on POSIX 70 import shutil 71 rmdirRecursive = shutil.rmtree 72