daca2: removing readonly files/folders

This commit is contained in:
Daniel Marjamäki 2013-10-14 15:49:11 +02:00
parent 9debeab47c
commit cee40beee1
1 changed files with 9 additions and 1 deletions

View File

@ -21,12 +21,20 @@ FTPSERVER = 'ftp.sunet.se'
FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/'
FOLDER = 'b'
def handleRemoveReadonly(func, path, exc):
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
def removeAllExceptResults():
filenames = glob.glob('[A-Za-z]*')
for filename in filenames:
if os.path.isdir(filename):
shutil.rmtree(filename)
shutil.rmtree(filename, onerror=handleRemoveReadonly)
elif filename != 'results.txt':
os.remove(filename)