def check_mzURL(mz_server, file_name):
'''Checks if an mzURL actually exists.
mz_server should be the base URL of the server
file_name is the name of the specific file (without its extension)
'''
if mz_server[-1] == '/':
mz_server = mz_server[:-1]
# Handle to libcurl object
crl = pycurl.Curl()
# set some general options
crl.setopt(pycurl.FOLLOWLOCATION, True)
crl.setopt(pycurl.URL, str(mz_server + '/files.txt'))
output = cStringIO.StringIO()
crl.setopt(pycurl.WRITEFUNCTION, output.write)
try:
for i in range(5):
#print 'check mzurl %d' % i
crl.perform()
if output.getvalue():
break
except pycurl.error, e:
return False
for f in output.getvalue().splitlines():
if os.path.splitext(f)[0].lower() == file_name.lower():
return True
else:
return False
评论列表
文章目录