X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/b2d0ed3e9e4f2fc899db7265a23156d5dd5cf139..58368b10fb37cfcd56738324f90942a8fd8e3793:/cookbooks/tile/files/default/bin/expire-tiles-single diff --git a/cookbooks/tile/files/default/bin/expire-tiles-single b/cookbooks/tile/files/default/bin/expire-tiles-single index fa45be9ee..30b41c343 100644 --- a/cookbooks/tile/files/default/bin/expire-tiles-single +++ b/cookbooks/tile/files/default/bin/expire-tiles-single @@ -1,10 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/python3 """ Expire meta tiles from a OSM change file by resetting their modified time. """ import argparse -import os.path as ospath +import os import osmium as o import pyproj @@ -12,8 +12,7 @@ EXPIRY_TIME = 946681200 # 2000-01-01 00:00:00 # width/height of the spherical mercator projection SIZE = 40075016.6855784 -proj_wsg84 = pyproj.Proj(init='epsg:4326') -proj_merc = pyproj.Proj(init='epsg:3857') +proj_transformer = pyproj.Transformer.from_crs('epsg:4326', 'epsg:3857', always_xy = True) class TileCollector(o.SimpleHandler): @@ -29,7 +28,7 @@ class TileCollector(o.SimpleHandler): return lat = max(-85, min(85.0, location.lat)) - x, y = pyproj.transform(proj_wsg84, proj_merc, location.lon, lat) + x, y = proj_transformer.transform(location.lon, lat) # renormalise into unit space [0,1] x = 0.5 + x / SIZE @@ -52,7 +51,7 @@ class TileCollector(o.SimpleHandler): self.done_nodes.add(n.ref) try: self.add_tile_from_node(self.node_cache.get(n.ref)) - except o.NotFoundError: + except KeyError: pass # no coordinate @@ -73,15 +72,15 @@ def xyz_to_meta(x, y, z, meta_size): if path is None: path = (part + ".meta") else: - path = ospath.join(part, path) + path = os.path.join(part, path) - return ospath.join(str(z), path) + return os.path.join(str(z), path) def expire_meta(meta): """Expire the meta tile by setting the modified time back. """ - if ospath.exists(meta): + if os.path.exists(meta): print("Expiring " + meta) os.utime(meta, (EXPIRY_TIME, EXPIRY_TIME)) @@ -101,7 +100,7 @@ def expire_meta_tiles(options): meta = xyz_to_meta(xy[0], xy[1], xy[2], options.meta_size) for tile_dir in options.tile_dir: - meta_set.add(ospath.join(tile_dir, meta)) + meta_set.add(os.path.join(tile_dir, meta)) # add the parent into the set for the next round new_set.add((int(xy[0]/2), int(xy[1]/2), xy[2] - 1))