Skip to content

Commit 2aedb71

Browse files
authored
Merge pull request #4185 from orblivion/map-download-touchups
Map download touchups
2 parents fd3a317 + f52cecc commit 2aedb71

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

roles/maps/tasks/download_large_file.yml

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,20 @@
3535
#
3636
# TODO - files should be owned by www-data
3737

38-
- block:
38+
39+
- vars:
40+
# Where the file eventually goes
41+
dest_path: "{{ dest_base_path }}/{{ item }}"
42+
43+
# Use md5sum to generate the log file name:
44+
# * Name has short, consistent length. The "to check progress..." message
45+
# fits within 80 characters on terminal (at least in the current
46+
# ansible version) in case users have small screens.
47+
# * If the user mis-copies, it's less likely to do anything destructive.
48+
log_file: "{{ item | hash('md5') }}.log"
49+
working_dir: "/library/downloads/maps"
50+
51+
block:
3952
- name: "Fetching file size for {{ iiab_map_host_url }}/{{ item }} via .meta4 file"
4053
shell: |
4154
import sys, xmltodict, requests, os
@@ -56,26 +69,39 @@
5669
size_disp = str(round(size / MiB, 2)) + ' MiB'
5770
else:
5871
size_disp = str(round(size / GiB, 2)) + ' GiB'
59-
print(' (' + size_disp + ') To check progress, run: "tail {{ working_dir }}/{{ log_file }}"')
72+
print('(' + size_disp + ') To check download progress, see previous step (above).')
6073
args:
6174
executable: /usr/bin/python3
62-
vars:
63-
# Where the file eventually goes
64-
dest_path: "{{ dest_base_path }}/{{ item }}"
6575

66-
log_file: "{{ item }}.log"
67-
working_dir: "/library/downloads/maps"
68-
register: download_file_size
76+
# The existence of console output in download_file_details
77+
# implies that the download should happen.
78+
register: download_file_details
79+
80+
# Put in some space to make it easier to read by implementers.
81+
- debug:
82+
msg:
83+
- ""
84+
- ""
85+
- " To check download progress, run: "
86+
- ""
87+
- " tail {{ working_dir }}/{{ log_file }} "
88+
- ""
89+
- ""
90+
# If the file already exists (and thus no download will happen) the above
91+
# task should exit before any console output.
92+
when: download_file_details.stdout_lines|length != 0
6993

70-
- name: "Download {{ item }}{{ download_file_size.stdout_lines.0 | default(' (done)')}}"
94+
- name: "Download {{ item }} {{ download_file_details.stdout_lines.0 | default('(done)')}}"
7195
# cd to the temp directory so that the aria2c file, data file, and (perhaps
7296
# eventually) torrent file all end up there.
7397
shell: |
7498
set -euo pipefail
7599
76100
cd {{ working_dir }}
77101
78-
echo "Starting download..." > "{{ log_file }}"
102+
date > "{{ log_file }}"
103+
echo "Downloading {{ item }}..." >> "{{ log_file }}"
104+
echo >> "{{ log_file }}"
79105
aria2c \
80106
--connect-timeout="{{ download_timeout }}" \
81107
--log-level=warn \
@@ -97,12 +123,7 @@
97123
args:
98124
executable: /bin/bash
99125
creates: "{{ dest_path }}"
100-
vars:
101-
# Where the file eventually goes
102-
dest_path: "{{ dest_base_path }}/{{ item }}"
103126

104-
log_file: "{{ item }}.log"
105-
working_dir: "/library/downloads/maps"
106127
rescue:
107128
# We output summaries to a log file for the user's benefit,
108129
# but all of the errors necessarily show up there as well.
@@ -118,6 +139,3 @@
118139
echo "aria2c error:" 1>&2
119140
tac "{{ log_file }}" | sed '/'"Download Progress Summary as of"'/q' | tac 1>&2
120141
exit 1
121-
vars:
122-
log_file: "{{ item }}.log"
123-
working_dir: "/library/downloads/maps"

0 commit comments

Comments
 (0)