daca2: removing readonly files/folders
This commit is contained in:
parent
9debeab47c
commit
cee40beee1
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue