Skip to content

Commit fd3a317

Browse files
authored
Merge pull request #4181 from orblivion/file-sizes-ansible
Add file sizes and log reading instructions to map downloads
2 parents 3dffa37 + 2a66055 commit fd3a317

File tree

3 files changed

+95
-37
lines changed

3 files changed

+95
-37
lines changed

roles/maps/defaults/main.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ maplibre_search_js_and_styles:
6868

6969
maps_dot_black_naturalearth6_symlink_name: "naturalearth6-NE2_HR_SR_W_DR-WEBP.pmtiles"
7070

71-
# Mostly colors, topography, etc. 58M
71+
# Mostly colors, topography, etc.
7272
maps_dot_black_naturalearth6_tiles: "naturalearth6-NE2_HR_SR_W_DR-WEBP.{{ maps_slow_data_date }}.full.pmtiles"
7373

7474
# Two different symlinks because the front end could requset openstreetmap or naturalearth
@@ -80,37 +80,37 @@ maps_dot_black_ne_symlink_name: naturalearth-openmaptiles.pmtiles
8080
# option and just have low zoom osm. So then it will be `maps_vector_zoom` and
8181
# just have numbers, like for satellite.
8282
maps_dot_black_vector_tiles:
83-
# "high res" full osm, including 3d buildings. 78GiB as of Oct 2025
83+
# "high res" full osm, including 3d buildings.
8484
# (TODO does this include colors and topography? Or is it used along with naturalearth6 above in most styles?)
8585
# maps_vector_quality = "osm-full"
8686
osm-full: "openstreetmap-openmaptiles.{{ maps_data_date }}.full.pmtiles"
8787

88-
# "medium res" osm, up to zoom level 9 (original file has 14). 1.9GiB as of Oct 2025
88+
# "medium res" osm, up to zoom level 9 (original file has 14).
8989
# (TODO does this include colors and topography? Or is it used along with naturalearth6 above in most styles?)
9090
# maps_vector_quality = "osm-z9"
9191
osm-z9: "openstreetmap-openmaptiles.{{ maps_data_date }}.zoom_0-09.pmtiles"
9292

93-
# "low res" - mostly borders, rivers, country names, large roads. 85MB
93+
# "low res" - mostly borders, rivers, country names, large roads.
9494
# maps_vector_quality = "ne"
9595
# (ne = "Natural Earth")
9696
ne: "naturalearth-openmaptiles.{{ maps_slow_data_date }}.full.pmtiles"
9797

9898
maps_dot_black_satellite_symlink_name: s2maps-sentinel2-2023.pmtiles
9999

100100
maps_dot_black_satellite_tiles:
101-
# Low quality satellite, up to zoom level 7 (original file has 13), 85MiB
101+
# Low quality satellite, up to zoom level 7 (original file has 13)
102102
# maps_sat_zoom = 7
103103
7: "s2maps-sentinel2-2023.{{ maps_slow_data_date }}.zoom_0-07.pmtiles"
104104

105-
# Moderately high quality satellite, up to zoom level 9 (original file has 13), 1.2GiB
105+
# Moderately high quality satellite, up to zoom level 9 (original file has 13)
106106
# maps_sat_zoom = 9
107107
9: "s2maps-sentinel2-2023.{{ maps_slow_data_date }}.zoom_0-09.pmtiles"
108108

109-
# Pretty high quality satellite, up to zoom level 11 (original file has 13), 21GiB
109+
# Pretty high quality satellite, up to zoom level 11 (original file has 13)
110110
# maps_sat_zoom = 11
111111
11: "s2maps-sentinel2-2023.{{ maps_slow_data_date }}.zoom_0-11.pmtiles"
112112

113-
# Pretty high quality satellite, up to zoom level 12 (original file has 13), 80GiB
113+
# Pretty high quality satellite, up to zoom level 12 (original file has 13)
114114
# maps_sat_zoom = 12
115115
12: "s2maps-sentinel2-2023.{{ maps_slow_data_date }}.zoom_0-12.pmtiles"
116116

roles/maps/tasks/download_large_file.yml

Lines changed: 83 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,89 @@
3535
#
3636
# TODO - files should be owned by www-data
3737

38-
- name: "Download {{ iiab_map_host_url }}/{{ item }} via .meta4 file"
39-
# cd to the temp directory so that the aria2c file, data file, and (perhaps
40-
# eventually) torrent file all end up there.
41-
shell: |
42-
set -euo pipefail
38+
- block:
39+
- name: "Fetching file size for {{ iiab_map_host_url }}/{{ item }} via .meta4 file"
40+
shell: |
41+
import sys, xmltodict, requests, os
4342
44-
cd /library/downloads/maps/
43+
if os.path.exists("{{ dest_path }}"):
44+
sys.exit(0)
4545
46-
aria2c \
47-
--connect-timeout="{{ download_timeout }}" \
48-
--log-level=warn \
49-
--console-log-level=warn \
50-
--summary-interval=0 \
51-
--show-console-readout=false \
52-
--download-result=hide \
53-
--follow-metalink=mem \
54-
--max-connection-per-server=4 \
55-
--file-allocation=falloc \
56-
--enable-http-pipelining=true \
57-
--seed-time=0 \
58-
"{{ iiab_map_host_url }}/{{ item }}.meta4"
46+
size = int(xmltodict.parse(
47+
requests.get("{{ iiab_map_host_url }}/{{ item }}.meta4").content
48+
)['metalink']['file']['size'])
49+
KiB = 1024
50+
MiB = KiB * 1024
51+
GiB = MiB * 1024
5952
60-
chmod 644 "{{ item }}"
61-
mv "{{ item }}" "{{ dest_path }}"
62-
args:
63-
executable: /bin/bash
64-
creates: "{{ dest_path }}"
65-
vars:
66-
# Where the file eventually goes
67-
dest_path: "{{ dest_base_path }}/{{ item }}"
53+
if size < MiB:
54+
size_disp = str(round(size / KiB, 2)) + ' KiB'
55+
elif size < GiB:
56+
size_disp = str(round(size / MiB, 2)) + ' MiB'
57+
else:
58+
size_disp = str(round(size / GiB, 2)) + ' GiB'
59+
print(' (' + size_disp + ') To check progress, run: "tail {{ working_dir }}/{{ log_file }}"')
60+
args:
61+
executable: /usr/bin/python3
62+
vars:
63+
# Where the file eventually goes
64+
dest_path: "{{ dest_base_path }}/{{ item }}"
65+
66+
log_file: "{{ item }}.log"
67+
working_dir: "/library/downloads/maps"
68+
register: download_file_size
69+
70+
- name: "Download {{ item }}{{ download_file_size.stdout_lines.0 | default(' (done)')}}"
71+
# cd to the temp directory so that the aria2c file, data file, and (perhaps
72+
# eventually) torrent file all end up there.
73+
shell: |
74+
set -euo pipefail
75+
76+
cd {{ working_dir }}
77+
78+
echo "Starting download..." > "{{ log_file }}"
79+
aria2c \
80+
--connect-timeout="{{ download_timeout }}" \
81+
--log-level=warn \
82+
--console-log-level=warn \
83+
--summary-interval=60 \
84+
--download-result=hide \
85+
--follow-metalink=mem \
86+
--max-connection-per-server=4 \
87+
--file-allocation=falloc \
88+
--show-console-readout=false \
89+
--enable-http-pipelining=true \
90+
--seed-time=0 \
91+
"{{ iiab_map_host_url }}/{{ item }}.meta4" \
92+
>> "{{ log_file }}"
93+
94+
chmod 644 "{{ item }}"
95+
mv "{{ item }}" "{{ dest_path }}"
96+
rm "{{ log_file }}"
97+
args:
98+
executable: /bin/bash
99+
creates: "{{ dest_path }}"
100+
vars:
101+
# Where the file eventually goes
102+
dest_path: "{{ dest_base_path }}/{{ item }}"
103+
104+
log_file: "{{ item }}.log"
105+
working_dir: "/library/downloads/maps"
106+
rescue:
107+
# We output summaries to a log file for the user's benefit,
108+
# but all of the errors necessarily show up there as well.
109+
# Here, we parse out the error message, ignoring almost all of
110+
# the summary lines, which could be a lot.
111+
# Finally, we exit 1 so Ansible shows this error.
112+
- name: "Error downloading {{ item }}"
113+
shell: |
114+
set -euo pipefail
115+
116+
cd {{ working_dir }}
117+
118+
echo "aria2c error:" 1>&2
119+
tac "{{ log_file }}" | sed '/'"Download Progress Summary as of"'/q' | tac 1>&2
120+
exit 1
121+
vars:
122+
log_file: "{{ item }}.log"
123+
working_dir: "/library/downloads/maps"

roles/maps/tasks/install.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
state: directory
55
# mode: 0755
66

7-
- name: Install aria2
7+
- name: Install downloading tools
88
apt:
9-
name: aria2
9+
name:
10+
- aria2
11+
- python3-xmltodict
1012

1113
- include_tasks: install_frontend.yml
1214

0 commit comments

Comments
 (0)