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/' FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/'
FOLDER = 'b' 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(): def removeAllExceptResults():
filenames = glob.glob('[A-Za-z]*') filenames = glob.glob('[A-Za-z]*')
for filename in filenames: for filename in filenames:
if os.path.isdir(filename): if os.path.isdir(filename):
shutil.rmtree(filename) shutil.rmtree(filename, onerror=handleRemoveReadonly)
elif filename != 'results.txt': elif filename != 'results.txt':
os.remove(filename) os.remove(filename)