Skip to content

Commit

Permalink
[FEATURE] Enhance check for existing (already downloaded) polygons an…
Browse files Browse the repository at this point in the history
…d .osm.pbf files (#43)

- use the files modification date, not the creation time. On windows this seemed to occasionally see newly downloaded files as the ones they replaced.
- check for a full match instead of doing a wildcard match while checking for existing maps. This prevents matching to multiple maps like australia and australia-oceania.
  • Loading branch information
treee111 committed Oct 19, 2021
1 parent 4994f13 commit bbdedd1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions common_python/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def check_polygons_file(self):

# Check for expired land polygons file and delete it
try:
chg_time = os.path.getctime(fd_fct.LAND_POLYGONS_PATH)
chg_time = os.path.getmtime(fd_fct.LAND_POLYGONS_PATH)
if older_than_x_days(chg_time, self.max_days_old):
print('# Deleting old land polygons file')
os.remove(fd_fct.LAND_POLYGONS_PATH)
Expand Down Expand Up @@ -132,14 +132,14 @@ def check_osm_pbf_file(self):
transl_c = const_fct.translate_country_input_to_geofabrik(country)

# check for already existing .osm.pbf file
map_file_path = glob.glob(f'{fd_fct.MAPS_DIR}/{transl_c}*.osm.pbf')
map_file_path = glob.glob(f'{fd_fct.MAPS_DIR}/{transl_c}-latest.osm.pbf')
if len(map_file_path) != 1:
map_file_path = glob.glob(
f'{fd_fct.MAPS_DIR}/**/{transl_c}*.osm.pbf')
f'{fd_fct.MAPS_DIR}/**/{transl_c}-latest.osm.pbf')

# delete .osm.pbf file if out of date
if len(map_file_path) == 1 and os.path.isfile(map_file_path[0]):
chg_time = os.path.getctime(map_file_path[0])
chg_time = os.path.getmtime(map_file_path[0])
if older_than_x_days(chg_time, self.max_days_old) or self.force_download is True:
print(
f'+ mapfile for {transl_c}: deleted. Input: {country}.')
Expand Down

0 comments on commit bbdedd1

Please sign in to comment.