def download(s, l):
filename = get_filename(s)
if not filename:
return False
print "Filename found: %s" % filename
print "Checking if url is valid"
r = s.get(url=download_url + filename, stream=True)
print "Status code: %s" % str(r.status_code)
if int(r.status_code) == 200:
print "Url returned '200', downloading file"
if not create_backup_location(l):
result = ['Failed to create backup location', False]
return result
date_time = datetime.datetime.now().strftime("%Y%m%d")
with open(l + '/' + application + '-' + date_time + '.zip', 'wb') as f:
file_total = 0
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
file_total = file_total + 1024
file_total_m = float(file_total)/1048576
# Clears the line before re-writing to avoid artifacts
stdout.write("\r\x1b[2k")
stdout.write("\r\x1b[2K%.2fMB downloaded" % file_total_m)
stdout.flush()
stdout.write("\n")
result = ['Backup downloaded successfully', True]
return result
else:
print "Download file not found on remote server - response code %s" % \
str(r.status_code)
print "Download url: %s" % download_url + filename
result = ['Download file not found on remote server', False]
return result
jira_confluence_backup.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录