Trees | Indices | Help |
|
---|
|
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 2123 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 # this just keeps pyflakes happy on non-Windows systems 42 if runtime.platformType != 'win32': 43 WindowsError = RuntimeError 44 45 if runtime.platformType == 'win32':47 """This is a replacement for shutil.rmtree that works better under 48 windows. Thanks to Bear at the OSAF for the code.""" 49 if not os.path.exists(dir): 50 return 51 52 if os.path.islink(dir) or os.path.isfile(dir): 53 os.remove(dir) 54 return 55 56 # Verify the directory is read/write/execute for the current user 57 os.chmod(dir, 0700) 58 59 # os.listdir below only returns a list of unicode filenames if the parameter is unicode 60 # Thus, if a non-unicode-named dir contains a unicode filename, that filename will get garbled. 61 # So force dir to be unicode. 62 if not isinstance(dir, unicode): 63 try: 64 dir = unicode(dir, "utf-8") 65 except: 66 log.err("rmdirRecursive: decoding from UTF-8 failed (ignoring)") 67 68 try: 69 list = os.listdir(dir) 70 except WindowsError, e: 71 msg = ("rmdirRecursive: unable to listdir %s (%s). Trying to " 72 "remove like a dir" % (dir, e.strerror.decode('mbcs'))) 73 log.msg(msg.encode('utf-8')) 74 os.rmdir(dir) 75 return 76 77 for name in list: 78 full_name = os.path.join(dir, name) 79 # on Windows, if we don't have write permission we can't remove 80 # the file/directory either, so turn that on 81 if os.name == 'nt': 82 if not os.access(full_name, os.W_OK): 83 # I think this is now redundant, but I don't have an NT 84 # machine to test on, so I'm going to leave it in place 85 # -warner 86 os.chmod(full_name, 0600) 87 88 if os.path.islink(full_name): 89 os.remove(full_name) # as suggested in bug #792 90 elif os.path.isdir(full_name): 91 rmdirRecursive(full_name) 92 else: 93 if os.path.isfile(full_name): 94 os.chmod(full_name, 0700) 95 os.remove(full_name) 96 os.rmdir(dir)97 else: 98 # use rmtree on POSIX 99 import shutil 100 rmdirRecursive = shutil.rmtree 101
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 25 19:40:45 2012 | http://epydoc.sourceforge.net |