Ignore:
Timestamp:
Apr 11, 2020, 4:46:15 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
3db3d13
Parents:
da2be70
Message:
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/server_impl/controllers/TilesController.py

    rda2be70 r7be94aa  
    2222from ..HttpErrors import MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound
    2323
     24
    2425def tiles_tile_get(accuracy, resolution, zoom, x_tile, y_tile):
    25         if not 'TILES_CACHE_PATH' in flask.current_app.config or not os.access(flask.current_app.config['TILES_CACHE_PATH'], os.R_OK):
    26                 raise MapserviceInternalServerError(detail='TILES_CACHE_PATH not configured or not accessible')
    27         tiles_cache_path = flask.current_app.config['TILES_CACHE_PATH']
    28        
    29         if not 'TILES_DENSITIES' in flask.current_app.config:
    30                 raise MapserviceInternalServerError(details='TILES_DENSITIES not configured')
    31         tiles_densities = flask.current_app.config['TILES_DENSITIES']
    32        
    33         if not 'TILES_DENSITY_BASEE' in flask.current_app.config:
    34                 raise MapserviceInternalServerError(details='TILES_DENSITY_BASEE not configured')
    35         tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
    36        
    37         if not 'TILES_SKIP_EMPTY' in flask.current_app.config:
    38                 raise MapserviceInternalServerError(details='TILES_SKIP_EMPTY not configured')
    39         tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
    40        
    41         if accuracy == 'high':
    42                 accuracy = '{}_{}'.format(max(tiles_densities), tiles_densitiy_base)
    43         elif accuracy == 'low':
    44                 accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
    45         else:
    46                 raise MapserviceBadRequest(details='No valid accuracy requested. Valid are high, low. Requested was: {}'.format(accuracy))
    47        
    48         tile__empty_path = os.path.join(tiles_cache_path, '{}/{}/empty_tile.png'.format(accuracy, resolution))
    49         tile_path = os.path.join(tiles_cache_path, '{}/{}/{}/{}/{}.png'.format(accuracy, resolution, zoom, x_tile, y_tile))
    50         if not os.path.isfile(tile_path):
    51                 if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
    52                         raise MapserviceNotFound(detail='Tile ({}, {}) for accuracy {} with resolution {} at zoomlevel {} not found'.format(x_tile, y_tile, accuracy, resolution, zoom))
    53                 tile_path = tile__empty_path
    54        
    55         response = flask.send_file(tile_path, mimetype='image/png', as_attachment=True, attachment_filename='{}.png'.format(y_tile))
    56         response.direct_passthrough = False
    57         #response.headers['Content-Transfer-Encoding']='base64'
    58         return response
     26    if not 'TILES_CACHE_PATH' in flask.current_app.config or not os.access(
     27        flask.current_app.config['TILES_CACHE_PATH'], os.R_OK
     28    ):
     29        raise MapserviceInternalServerError(
     30            detail='TILES_CACHE_PATH not configured or not accessible'
     31        )
     32    tiles_cache_path = flask.current_app.config['TILES_CACHE_PATH']
     33
     34    if not 'TILES_DENSITIES' in flask.current_app.config:
     35        raise MapserviceInternalServerError(
     36            details='TILES_DENSITIES not configured'
     37        )
     38    tiles_densities = flask.current_app.config['TILES_DENSITIES']
     39
     40    if not 'TILES_DENSITY_BASEE' in flask.current_app.config:
     41        raise MapserviceInternalServerError(
     42            details='TILES_DENSITY_BASEE not configured'
     43        )
     44    tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
     45
     46    if not 'TILES_SKIP_EMPTY' in flask.current_app.config:
     47        raise MapserviceInternalServerError(
     48            details='TILES_SKIP_EMPTY not configured'
     49        )
     50    tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
     51
     52    if accuracy == 'high':
     53        accuracy = '{}_{}'.format(max(tiles_densities), tiles_densitiy_base)
     54    elif accuracy == 'low':
     55        accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
     56    else:
     57        raise MapserviceBadRequest(
     58            details=
     59            'No valid accuracy requested. Valid are high, low. Requested was: {}'
     60            .format(accuracy)
     61        )
     62
     63    tile__empty_path = os.path.join(
     64        tiles_cache_path, '{}/{}/empty_tile.png'.format(accuracy, resolution)
     65    )
     66    tile_path = os.path.join(
     67        tiles_cache_path, '{}/{}/{}/{}/{}.png'.format(
     68            accuracy, resolution, zoom, x_tile, y_tile
     69        )
     70    )
     71    if not os.path.isfile(tile_path):
     72        if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
     73            raise MapserviceNotFound(
     74                detail=
     75                'Tile ({}, {}) for accuracy {} with resolution {} at zoomlevel {} not found'
     76                .format(x_tile, y_tile, accuracy, resolution, zoom)
     77            )
     78        tile_path = tile__empty_path
     79
     80    response = flask.send_file(
     81        tile_path,
     82        mimetype='image/png',
     83        as_attachment=True,
     84        attachment_filename='{}.png'.format(y_tile)
     85    )
     86    response.direct_passthrough = False
     87    #response.headers['Content-Transfer-Encoding']='base64'
     88    return response
Note: See TracChangeset for help on using the changeset viewer.