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

Source Code for Module buildslave.commands.utils

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  import os 
17   
18  from twisted.python import log 
19  from twisted.python.procutils import which 
20  from twisted.python import runtime 
21   
22 -def getCommand(name):
23 possibles = which(name) 24 if not possibles: 25 raise RuntimeError("Couldn't find executable for '%s'" % name) 26 # 27 # Under windows, if there is more than one executable "thing" 28 # that matches (e.g. *.bat, *.cmd and *.exe), we not just use 29 # the first in alphabet (*.bat/*.cmd) if there is a *.exe. 30 # e.g. under MSysGit/Windows, there is both a git.cmd and a 31 # git.exe on path, but we want the git.exe, since the git.cmd 32 # does not seem to work properly with regard to errors raised 33 # and catched in buildbot slave command (vcs.py) 34 # 35 if runtime.platformType == 'win32' and len(possibles) > 1: 36 possibles_exe = which(name + ".exe") 37 if possibles_exe: 38 return possibles_exe[0] 39 return possibles[0]
40 41 if runtime.platformType == 'win32':
42 - def rmdirRecursive(dir):
43 """This is a replacement for shutil.rmtree that works better under 44 windows. Thanks to Bear at the OSAF for the code.""" 45 if not os.path.exists(dir): 46 return 47 48 if os.path.islink(dir): 49 os.remove(dir) 50 return 51 52 # Verify the directory is read/write/execute for the current user 53 os.chmod(dir, 0700) 54 55 # os.listdir below only returns a list of unicode filenames if the parameter is unicode 56 # Thus, if a non-unicode-named dir contains a unicode filename, that filename will get garbled. 57 # So force dir to be unicode. 58 try: 59 dir = unicode(dir, "utf-8") 60 except: 61 log.msg("rmdirRecursive: decoding from UTF-8 failed") 62 63 for name in os.listdir(dir): 64 full_name = os.path.join(dir, name) 65 # on Windows, if we don't have write permission we can't remove 66 # the file/directory either, so turn that on 67 if os.name == 'nt': 68 if not os.access(full_name, os.W_OK): 69 # I think this is now redundant, but I don't have an NT 70 # machine to test on, so I'm going to leave it in place 71 # -warner 72 os.chmod(full_name, 0600) 73 74 if os.path.islink(full_name): 75 os.remove(full_name) # as suggested in bug #792 76 elif os.path.isdir(full_name): 77 rmdirRecursive(full_name) 78 else: 79 if os.path.isfile(full_name): 80 os.chmod(full_name, 0700) 81 os.remove(full_name) 82 os.rmdir(dir)
83 else: 84 # use rmtree on POSIX 85 import shutil 86 rmdirRecursive = shutil.rmtree 87