Skip to content

Commit

Permalink
Merge pull request #89 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v1.5.0 - #minor
  • Loading branch information
ltshb authored Sep 12, 2024
2 parents 2fd722f + 35235fd commit fbfcb1d
Show file tree
Hide file tree
Showing 596 changed files with 2,550 additions and 462 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buster slim python 3.9 base image.
FROM python:3.9-slim-buster
# Buster slim python 3.12 base image.
FROM python:3.12-slim-bookworm
ENV HTTP_PORT 8080
RUN groupadd -r geoadmin && useradd -r -s /bin/false -g geoadmin geoadmin

Expand Down
18 changes: 9 additions & 9 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ verify_ssl = true
name = "pypi"

[packages]
PyYAML = "~=5.4.1"
gevent = "~=21.1.2"
gunicorn = "~=20.1.0"
Flask = "~=2.0.1"
Pillow = "~=9.0.1"
python-dotenv = "~=0.17.0"
logging-utilities = "~=3.0"
werkzeug = "~=2.2"
PyYAML = "~=6.0.2"
gevent = "~=24.2.1"
gunicorn = "~=23.0.0"
Flask = "~=3.0.3"
pillow = "~=10.4.0"
python-dotenv = "~=1.0.1"
logging-utilities = "~=4.5.0"
werkzeug = "~=3.0.4"

[dev-packages]
yapf = "*"
Expand All @@ -21,4 +21,4 @@ pylint-flask = "*"
cairosvg = "*"

[requires]
python_version = "3.9"
python_version = "3.12"
1,006 changes: 579 additions & 427 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See also [Git Flow - Versioning](https://github.com/geoadmin/doc-guidelines/blob

### Make Dependencies

The **Make** targets assume you have **python3.9**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed.
The **Make** targets assume you have **python3.12**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed.

### Setting up to work

Expand Down Expand Up @@ -192,3 +192,4 @@ The service is configured by Environment Variable:
| WSGI_TIMEOUT | `5` | WSGI timeout. |
| GUNICORN_TMPFS_DIR | `None` |The working directory for the gunicorn workers. |
| WSGI_WORKERS | `2` | The number of workers per CPU. |
| UNLISTED_ICON_SETS | `'babs'`| Comma separated list of icon set to un-list. Those sets won't be listed in the /sets endpoint. |
40 changes: 40 additions & 0 deletions app/helpers/description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import logging
import os

from flask import abort

from app.settings import DESCRIPTION_FOLDER

logger = logging.getLogger(__name__)


def get_icon_description(icon_name='', icon_set=''):
'''
Return json containing the description in all available languages for an icon in the specified
icon set
'''
path = find_descripton_file(icon_set)
if not os.path.isfile(path):
return None

with open(path, encoding='utf-8') as f:
df = json.load(f)

try:
icon_description = df[icon_name]
except KeyError:
logger.error("Description for icon not found: %s", icon_name)
abort(404, "Description for icon not found")

return icon_description


def find_descripton_file(icon_set):
'''
Return file path of description file if it exists or False in case it doesn't
'''
path = os.path.abspath(os.path.join(DESCRIPTION_FOLDER, icon_set)) + '-dictionary.json'
if os.path.isfile(path):
return path
return False
17 changes: 16 additions & 1 deletion app/icon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

from PIL import Image

from flask import url_for

from app.helpers.description import get_icon_description
from app.helpers.icons import get_icon_template_url
from app.helpers.url import get_base_url
from app.settings import DEFAULT_COLOR
Expand Down Expand Up @@ -82,6 +85,16 @@ def get_icon_filepath(self):
name_with_extension = f"{name_with_extension}.png"
return os.path.abspath(os.path.join(IMAGE_FOLDER, self.icon_set.name, name_with_extension))

def get_size(self):
"""
Lazily open image of icon to get the size of the icon from the metadata.
Returns:
A tuple with the size of the specified icon (x,y)
"""
with Image.open(self.get_icon_filepath()) as img:
return img.size

def serialize(self):
"""
As we want to add "url" to the __dict__, we can't really use a json.dumps to generate our
Expand All @@ -97,5 +110,7 @@ def serialize(self):
"anchor": self.anchor,
"icon_set": self.icon_set.name,
"url": self.get_icon_url(),
"template_url": get_icon_template_url(get_base_url())
"template_url": get_icon_template_url(get_base_url()),
"description": get_icon_description(self.name, self.icon_set.name),
"size": self.get_size()
}
21 changes: 9 additions & 12 deletions app/icon_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from flask import url_for

from app.helpers.description import find_descripton_file
from app.helpers.icons import get_icon_set_template_url
from app.helpers.url import get_base_url
from app.icon import Icon
from app.settings import COLORABLE_ICON_SETS
from app.settings import ICON_SET_LANGUAGE
from app.settings import IMAGE_FOLDER
from app.settings import UNLISTED_ICON_SETS


def get_icon_set(icon_set_name):
Expand All @@ -28,7 +31,9 @@ def get_all_icon_sets():
icon_sets = []
for root, dirs, files in os.walk(IMAGE_FOLDER):
for icon_set_name in dirs:
icon_sets.append(get_icon_set(icon_set_name))
# icons of legacy icon sets are still available, but the icon set will not be listed
if icon_set_name not in UNLISTED_ICON_SETS:
icon_sets.append(get_icon_set(icon_set_name))
return icon_sets


Expand Down Expand Up @@ -85,16 +90,6 @@ def get_icon(self, icon_name):
"""
return Icon(f"{icon_name}", self)

def get_default_pixel_size(self):
"""
Returns:
the size in pixel of this icon set's icon (icons are always square images). This is
helpful to calculate if an icon requires a resize before being served to the user.
"""
if self.name == 'default':
return 96
return 48

def get_all_icons(self):
"""
Generate a list of all icons belonging to this icon set.
Expand Down Expand Up @@ -126,5 +121,7 @@ def serialize(self):
"name": self.name,
"colorable": self.colorable,
"icons_url": self.get_icons_url(),
"template_url": get_icon_set_template_url(get_base_url())
"template_url": get_icon_set_template_url(get_base_url()),
"has_description": bool(find_descripton_file(self.name)),
"language": ICON_SET_LANGUAGE[self.name] if self.name in ICON_SET_LANGUAGE else None
}
12 changes: 9 additions & 3 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def make_api_compliant_response(response_object):
"""
if isinstance(response_object, (Icon, IconSet)):
return make_response(jsonify({'success': True, **response_object.serialize()}))
if all(isinstance(r, (Icon, IconSet)) for r in response_object):
return make_response(
jsonify({
'success': True, "items": [r.serialize() for r in response_object]
})
)
if isinstance(response_object, list):
return make_response(jsonify({'success': True, "items": response_object}))
return make_response(jsonify({'success': True, **response_object}))
Expand Down Expand Up @@ -86,9 +92,9 @@ def colorized_icon(
image = Image.open(fd)
if image.mode == 'P':
image = image.convert('RGBA')
new_size = int(48 * scale)
if new_size != icon_set.get_default_pixel_size():
image = image.resize((new_size, new_size))
if scale != 1:
new_size = map(lambda s: int(s * scale), icon.get_size())
image = image.resize(tuple(new_size))
if icon_set.colorable:
image = Image.composite(Image.new("RGB", image.size, (red, green, blue)), image, image)
output = BytesIO()
Expand Down
6 changes: 6 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
load_dotenv(ENV_FILE, override=True, verbose=True)

IMAGE_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), '../static/images/'))
DESCRIPTION_FOLDER = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../metadata/description/')
)

COLORABLE_ICON_SETS = ['default']
UNLISTED_ICON_SETS = os.environ.get('UNLISTED_ICON_SETS', 'babs').split(',')
ICON_SET_LANGUAGE = {'babs-de': 'de', 'babs-fr': 'fr', 'babs-it': 'it'}
DEFAULT_COLOR = {"r": '255', "g": '0', "b": '0'}
DEFAULT_ICON_SIZE = 48
TRAP_HTTP_EXCEPTIONS = True
LOGS_DIR = os.getenv('LOGS_DIR', str(BASE_DIR / 'logs'))
os.environ['LOGS_DIR'] = LOGS_DIR # Set default if not set
Expand Down
Binary file added backup/default/001-marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/002-circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/003-square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/004-triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/005-star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/006-star-stroked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/007-marker-stroked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/008-circle-stroked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/009-square-stroked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/010-triangle-stroked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/011-cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/012-disability.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/013-danger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/014-art-gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/015-alcohol-shop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/016-bakery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/017-bank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/018-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/019-beer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/020-cafe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/021-cinema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/022-commercial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/023-clothing-store.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/024-grocery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/025-fast-food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backup/default/026-hairdresser.png
Binary file added backup/default/027-fuel.png
Binary file added backup/default/028-laundry.png
Binary file added backup/default/029-library.png
Binary file added backup/default/030-lodging.png
Binary file added backup/default/031-pharmacy.png
Binary file added backup/default/032-restaurant.png
Binary file added backup/default/033-shop.png
Binary file added backup/default/034-airport.png
Binary file added backup/default/035-bicycle.png
Binary file added backup/default/036-bus.png
Binary file added backup/default/037-car.png
Binary file added backup/default/038-ferry.png
Binary file added backup/default/039-london-underground.png
Binary file added backup/default/040-rail.png
Binary file added backup/default/041-rail-above.png
Binary file added backup/default/042-rail-light.png
Binary file added backup/default/043-rail-metro.png
Binary file added backup/default/044-rail-underground.png
Binary file added backup/default/045-scooter.png
Binary file added backup/default/046-america-football.png
Binary file added backup/default/047-baseball.png
Binary file added backup/default/048-basketball.png
Binary file added backup/default/049-cricket.png
Binary file added backup/default/050-golf.png
Binary file added backup/default/051-skiing.png
Binary file added backup/default/052-soccer.png
Binary file added backup/default/053-swimming.png
Binary file added backup/default/054-tennis.png
Binary file added backup/default/055-airfield.png
Binary file added backup/default/056-building.png
Binary file added backup/default/057-campsite.png
Binary file added backup/default/058-cemetery.png
Binary file added backup/default/059-city.png
Binary file added backup/default/060-college.png
Binary file added backup/default/061-dog-park.png
Binary file added backup/default/062-embassy.png
Binary file added backup/default/063-farm.png
Binary file added backup/default/064-fire-station.png
Binary file added backup/default/065-garden.png
Binary file added backup/default/066-harbor.png
Binary file added backup/default/067-heliport.png
Binary file added backup/default/068-hospital.png
Binary file added backup/default/069-industrial.png
Binary file added backup/default/070-land-use.png
Binary file added backup/default/071-lighthouse.png
Binary file added backup/default/072-monument.png
Binary file added backup/default/073-minefield.png
Binary file added backup/default/074-museum.png
Binary file added backup/default/075-oil-well.png
Binary file added backup/default/076-park2.png
Binary file added backup/default/077-park.png
Binary file added backup/default/078-parking.png
Binary file added backup/default/079-parking-garage.png
Binary file added backup/default/080-pitch.png
Binary file added backup/default/081-place-of-worship.png
Binary file added backup/default/082-playground.png
Binary file added backup/default/083-police.png
Binary file added backup/default/084-polling-place.png
Binary file added backup/default/085-post.png
Binary file added backup/default/086-religious-christian.png
Binary file added backup/default/087-religious-jewish.png
Binary file added backup/default/088-religious-muslim.png
Binary file added backup/default/089-prison.png
Binary file added backup/default/090-school.png
Binary file added backup/default/091-slaughterhouse.png
Binary file added backup/default/092-theatre.png
Binary file added backup/default/093-toilets.png
Binary file added backup/default/094-town.png
Binary file added backup/default/095-town-hall.png
Binary file added backup/default/096-village.png
Binary file added backup/default/097-warehouse.png
Binary file added backup/default/098-wetland.png
Binary file added backup/default/099-zoo.png
Binary file added backup/default/100-camera.png
Binary file added backup/default/101-chemist.png
Binary file added backup/default/102-dam.png
Binary file added backup/default/103-emergency-telephone.png
Binary file added backup/default/104-entrance.png
Binary file added backup/default/105-heart.png
Binary file added backup/default/106-logging.png
Binary file added backup/default/107-mobilephone.png
Binary file added backup/default/108-music.png
Binary file added backup/default/109-roadblock.png
Binary file added backup/default/110-rocket.png
Binary file added backup/default/111-suitcase.png
Binary file added backup/default/112-telephone.png
Binary file added backup/default/113-waste-basket.png
Binary file added backup/default/114-water.png
Binary file added backup/default/115-gift.png
Binary file added backup/default/116-ice-cream.png
Loading

0 comments on commit fbfcb1d

Please sign in to comment.