Update docker-ce.py

This commit is contained in:
Yuxiang Zhang 2019-07-03 09:10:23 +08:00 committed by GitHub
parent 39bc4a0d4a
commit facf125102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,8 @@ from pyquery import PyQuery as pq
BASE_URL = os.getenv("TUNASYNC_UPSTREAM_URL", "https://download.docker.com/") BASE_URL = os.getenv("TUNASYNC_UPSTREAM_URL", "https://download.docker.com/")
WORKING_DIR = os.getenv("TUNASYNC_WORKING_DIR") WORKING_DIR = os.getenv("TUNASYNC_WORKING_DIR")
# connect and read timeout value
TIMEOUT_OPTION = (7, 10)
class RemoteSite: class RemoteSite:
@ -47,7 +49,7 @@ class RemoteSite:
yield base_url yield base_url
return return
r = requests.get(base_url) r = requests.get(base_url, timeout=TIMEOUT_OPTION)
if not r.ok: if not r.ok:
return return
@ -101,7 +103,7 @@ def main():
remote_filelist.append(dst_file.relative_to(working_dir)) remote_filelist.append(dst_file.relative_to(working_dir))
if dst_file.is_file(): if dst_file.is_file():
r = requests.head(url) r = requests.head(url, timeout=TIMEOUT_OPTION)
remote_filesize = int(r.headers['content-length']) remote_filesize = int(r.headers['content-length'])
remote_date = parsedate_to_datetime(r.headers['last-modified']) remote_date = parsedate_to_datetime(r.headers['last-modified'])
stat = dst_file.stat() stat = dst_file.stat()