daca2: bailout if download fails

This commit is contained in:
Daniel Marjamäki 2013-10-24 17:39:37 +02:00
parent 7349d4b767
commit fc9998e439
1 changed files with 25 additions and 31 deletions

View File

@ -31,40 +31,26 @@ def getpackages(folder):
archives = [] archives = []
for package in packages: for package in packages:
print(package) print(package)
count = 10 filename = None
while count > 0: path = FTPPATH + folder + '/' + package
filename = None
path = FTPPATH + folder + '/' + package
try:
time.sleep(0.01)
files = f.nlst(path)
for s in files: time.sleep(1)
if s.find('.orig.tar.') > 0: files = f.nlst(path)
filename = s
if not filename: for s in files:
for s in files: if s.find('.orig.tar.') > 0:
if s.find('.tar.') > 0: filename = s
filename = s
except socket.error as err: if not filename:
print(str(err)) for s in files:
except ftplib.error_temp as err: if s.find('.tar.') > 0:
print(str(err)) filename = s
except EOFError as err:
print(str(err))
if not filename: if not filename:
print('Retry..') archives = []
f.close() return archives
time.sleep(1)
f = ftplib.FTP(FTPSERVER) archives.append(package + '/' + filename)
f.login()
count = count - 1
else:
archives.append(package + '/' + filename)
count = 0
return archives return archives
@ -131,7 +117,12 @@ def scanarchive(fullpath):
results.close() results.close()
filename = fullpath[fullpath.rfind('/') + 1:] filename = fullpath[fullpath.rfind('/') + 1:]
subprocess.call(['wget', fullpath]) subprocess.call(['nice', 'wget', fullpath])
if not os.path.isfile(filename):
removeAllExceptResults()
os.remove(filename)
sys.exit(1)
if filename[-3:] == '.gz': if filename[-3:] == '.gz':
subprocess.call(['tar', 'xzvf', filename]) subprocess.call(['tar', 'xzvf', filename])
elif filename[-3:] == '.xz': elif filename[-3:] == '.xz':
@ -183,6 +174,9 @@ if not FOLDER:
sys.exit(1) sys.exit(1)
archives = getpackages(FOLDER) archives = getpackages(FOLDER)
if len(archives) == 0:
print('failed to load packages')
sys.exit(1)
time.sleep(30) time.sleep(30)