comaps-map-distributor 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: comaps-map-distributor
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: A small CLI tool to download and then serve map files for CoMaps.
5
5
  Keywords: comaps,openstreetmap,map server
6
6
  Author: Bastian Greshake Tzovaras
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "comaps-map-distributor"
3
- version = "0.2.0"
3
+ version = "0.4.0"
4
4
  description = "A small CLI tool to download and then serve map files for CoMaps."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -41,8 +41,8 @@ def cli_download_maps(directory, map_version, download_server):
41
41
  map_version, country_list = get_map_names(download_server,
42
42
  map_version,
43
43
  user_specified_server)
44
- selected_maps = select_maps(country_list)
45
44
  download_location = select_download_path(map_version,directory)
45
+ selected_maps = select_maps(country_list, download_location)
46
46
  download_maps(selected_maps,
47
47
  download_server,
48
48
  map_version,
@@ -66,7 +66,7 @@ def recurse_map_json(countries, name_list=[]):
66
66
  return name_list
67
67
 
68
68
 
69
- def select_maps(country_list):
69
+ def select_maps(country_list, download_location):
70
70
  """
71
71
  build fuzzy match UI for selecting which maps to download
72
72
  """
@@ -83,8 +83,12 @@ def select_maps(country_list):
83
83
  }
84
84
 
85
85
  # make world map and world coast map selected by default
86
+ # also pre-select existing maps to help find which maps already exist
87
+ # (existing files won't be re-downloaded from 0.4.0)
86
88
 
87
- country_list = list(map(lambda x: Choice(x, enabled=True) if x == 'World' or x == 'WorldCoasts' else x, country_list))
89
+ old_maps = [i.name.replace('.mwm','') for i in Path(download_location).glob("*.mwm")]
90
+
91
+ country_list = list(map(lambda x: Choice(x, enabled=True) if (x == 'World') or (x == 'WorldCoasts') or (x in old_maps) else x, country_list))
88
92
 
89
93
  questions = [
90
94
  {
@@ -154,20 +158,28 @@ def download_maps(selected_maps, base_url, map_version, download_location):
154
158
  for map_name in selected_maps:
155
159
  download_url = create_download_url(base_url, map_version, map_name)
156
160
  local_filename = "{}/{}.mwm".format(download_location, map_name)
157
- with requests.get(download_url, stream=True) as r:
158
- r.raise_for_status()
159
- per_file_progress = download_progress.add_task(
160
- "[yellow]File: {}".format(map_name),
161
- total=int(r.headers.get("content-length", 0)))
162
- with open(local_filename, 'wb') as f:
163
- for chunk in r.iter_content(chunk_size=8192):
164
- f.write(chunk)
165
- download_progress.update(per_file_progress, advance=8192)
166
- download_progress.update(per_file_progress, visible=False)
167
- download_progress.update(overall_progress, advance=1)
168
- print(":white_check_mark:[bold] Downloaded: [/bold][italic]{}[/italic] from {}".format(
169
- map_name,
170
- download_url))
161
+ if Path(local_filename).is_file():
162
+ # if local file is already existing, skip downloading it
163
+ print(":white_check_mark:[bold] Already existed: [/bold][italic]{}[/italic]".format(
164
+ map_name,
165
+ ))
166
+ continue
167
+ else:
168
+ with requests.get(download_url, stream=True) as r:
169
+ r.raise_for_status()
170
+ per_file_progress = download_progress.add_task(
171
+ "[yellow]File: {}".format(map_name),
172
+ total=int(r.headers.get("content-length", 0)))
173
+ with open(local_filename+".part", 'wb') as f:
174
+ for chunk in r.iter_content(chunk_size=8192):
175
+ f.write(chunk)
176
+ download_progress.update(per_file_progress, advance=8192)
177
+ download_progress.update(per_file_progress, visible=False)
178
+ os.rename(local_filename+".part", local_filename)
179
+ download_progress.update(overall_progress, advance=1)
180
+ print(":white_check_mark:[bold] Downloaded: [/bold][italic]{}[/italic] from {}".format(
181
+ map_name,
182
+ download_url))
171
183
  download_progress.stop()
172
184
  print("[bold]:rocket: All files downloaded! [/bold]")
173
185