skip package files only

This commit is contained in:
Yuxiang Zhang 2020-02-01 15:55:25 +08:00 committed by GitHub
parent 108ea8426f
commit 7d1b156b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,7 +98,23 @@ def downloading_worker(q):
if item is None: if item is None:
break break
url, dst_file = item url, dst_file, working_dir = item
if dst_file.is_file():
print("checking", url, flush=True)
r = requests.head(url, timeout=TIMEOUT_OPTION)
remote_filesize = int(r.headers['content-length'])
remote_date = parsedate_to_datetime(r.headers['last-modified'])
stat = dst_file.stat()
local_filesize = stat.st_size
local_mtime = stat.st_mtime
if remote_filesize == local_filesize and remote_date.timestamp() == local_mtime:
print("skipping", dst_file.relative_to(working_dir), flush=True)
q.task_done()
continue
dst_file.unlink()
print("downloading", url, flush=True) print("downloading", url, flush=True)
try: try:
requests_download(url, dst_file) requests_download(url, dst_file)
@ -106,6 +122,7 @@ def downloading_worker(q):
print("Failed to download", url, flush=True) print("Failed to download", url, flush=True)
if dst_file.is_file(): if dst_file.is_file():
dst_file.unlink() dst_file.unlink()
q.task_done() q.task_done()
@ -125,7 +142,7 @@ def main():
parser.add_argument("--workers", default=1, type=int, parser.add_argument("--workers", default=1, type=int,
help='number of concurrent downloading jobs') help='number of concurrent downloading jobs')
parser.add_argument("--fast-skip", action='store_true', parser.add_argument("--fast-skip", action='store_true',
help='do not verify size and timestamp of existing files') help='do not verify size and timestamp of existing package files')
args = parser.parse_args() args = parser.parse_args()
if args.working_dir is None: if args.working_dir is None:
@ -141,26 +158,13 @@ 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():
if args.fast_skip: if args.fast_skip and dst_file.suffix in ['.rpm', '.deb', '.tgz', '.zip']:
print("Skipping", dst_file.relative_to(working_dir), flush=True) print("fast skipping", dst_file.relative_to(working_dir), flush=True)
continue continue
r = requests.head(url, timeout=TIMEOUT_OPTION)
remote_filesize = int(r.headers['content-length'])
remote_date = parsedate_to_datetime(r.headers['last-modified'])
stat = dst_file.stat()
local_filesize = stat.st_size
local_mtime = stat.st_mtime
if remote_filesize == local_filesize and remote_date.timestamp() == local_mtime:
print("Skipping", dst_file.relative_to(working_dir), flush=True)
continue
dst_file.unlink()
else: else:
dst_file.parent.mkdir(parents=True, exist_ok=True) dst_file.parent.mkdir(parents=True, exist_ok=True)
task_queue.put((url, dst_file)) task_queue.put((url, dst_file, working_dir))
# block until all tasks are done # block until all tasks are done
task_queue.join() task_queue.join()