Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Release v1.5.0 - #minor #89

Merged
merged 59 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
59daec7
PB-470: Add scripts to shift icons to center them
LukasJoss May 2, 2024
94015c3
PB-470: Add shifted icons
LukasJoss May 3, 2024
655bc54
PB-470: Remove average icon script
LukasJoss May 3, 2024
e63a6b0
Merge pull request #79 from geoadmin/feat-PB-470-icons-are-not-centered
LukasJoss May 3, 2024
97ef6a1
PB-63: Add new babs icons in all three languages
LukasJoss Aug 23, 2024
43ed52e
PB-63: Update tests to not fail on non square babs icons
LukasJoss Aug 23, 2024
d346dba
PB-63: Disable too many locals lint warning in icon image test
LukasJoss Aug 23, 2024
514573f
PB-63: Delete square check test as some icons are not square
LukasJoss Aug 23, 2024
e74422c
Merge pull request #80 from geoadmin/feat-PB-63-deploy-new-babs-icons
LukasJoss Aug 23, 2024
a54655a
PB-227: add script to generate JSON dictionary for babs2 icons
LukasJoss Jan 17, 2024
8f104b4
PB-227: moved json so that tests wont fail
LukasJoss Jan 17, 2024
851933e
PB-227: Change script to read excel file instead
LukasJoss Jan 18, 2024
08bd176
PB-227: Add special characters to json file
LukasJoss Jan 18, 2024
f306a45
PB-227: Add translation from json file to metadata
LukasJoss Jan 19, 2024
716e296
PB-227: Added Metadata Response for entire set
LukasJoss Jan 19, 2024
86f566b
PB-227: Added tests for babs2 helptext
LukasJoss Jan 22, 2024
926a561
PB-227: Update formating
LukasJoss Jan 22, 2024
7f4a99d
PB-227: Add pandas to pipfile
LukasJoss Jan 23, 2024
aaa4528
PB-227: Adapt script to updated excel file
LukasJoss Aug 23, 2024
98eeefd
PB-227: Create translation file for each language
LukasJoss Aug 23, 2024
ad1478a
PB-227: Add endpoint for description off all icons in icon set
LukasJoss Aug 26, 2024
3e5073c
PB-227: Rename and restructure code
LukasJoss Aug 26, 2024
363ded7
PB-227: Add additional tests
LukasJoss Aug 26, 2024
3de017e
PB-227: Add exception if icon does not have description in file
LukasJoss Aug 29, 2024
e1dfd45
PB-227: Implement changes from PR review
LukasJoss Aug 30, 2024
32d84df
Merge pull request #76 from geoadmin/feat-PB-227_helptext_translations
LukasJoss Aug 30, 2024
a2c8079
PB-302: Add icon size to metadata
LukasJoss Aug 28, 2024
65a733c
PB-302: Icon ration is now preserved for new babs icons
LukasJoss Aug 28, 2024
d928cee
PB-302: Restructure calculation of default icon size
LukasJoss Aug 29, 2024
d0834d4
PB-302: Change resize icon logic
LukasJoss Aug 30, 2024
96fb91f
PB-302: Change all babs icons to size 48x48
LukasJoss Sep 2, 2024
1f170a3
PB-302: Add backup of default images in original size
LukasJoss Sep 2, 2024
1aae2b7
PB-302: Resize all default icons to 48x48
LukasJoss Sep 2, 2024
616f25b
PB-302: Update scaling functionality and tests
LukasJoss Sep 2, 2024
5af89c1
PB-302: Update image resizing calculation
LukasJoss Sep 4, 2024
d9fc68b
Merge pull request #81 from geoadmin/feat-PB-302-add-icon-size-to-met…
LukasJoss Sep 4, 2024
6f29231
PB-227: Add babs to legacy icon sets which will no longer be listed
LukasJoss Sep 5, 2024
d00ac0d
Merge pull request #82 from geoadmin/feat-PB-227-add-babs-to-legacy-i…
LukasJoss Sep 5, 2024
f41e35e
PB-227: Update python version of service-icons
LukasJoss Sep 6, 2024
31fed3a
PB-227: Update libraries as recommended by dependabot
LukasJoss Sep 6, 2024
ddfeb0a
PB-227: Fix serialization error after updating flask
LukasJoss Sep 6, 2024
bc65824
PB-227: Fix building errors after updating python
LukasJoss Sep 6, 2024
4eeffa4
PB-227: Check previous slim-buster version
LukasJoss Sep 6, 2024
2514036
Merge pull request #83 from geoadmin/feat-PB-227-update-libraries
LukasJoss Sep 9, 2024
8b47fcb
PB-227: Remove unnecessary endpoint
LukasJoss Sep 9, 2024
8e2e9e5
Merge pull request #84 from geoadmin/feat-PB-227-remove-description-e…
LukasJoss Sep 9, 2024
60246c4
PB-227 Update python version from 3.9 to 3.12
LukasJoss Sep 9, 2024
3e97082
PB-227: Fix error from updating pillow
LukasJoss Sep 9, 2024
d0432d4
Merge pull request #85 from geoadmin/feat-PB-227-update-python
LukasJoss Sep 9, 2024
b755c02
PB-227: Change babs folder to use language iso-codes
LukasJoss Sep 11, 2024
257aa96
PB-227: Add language to icon-set metadata
LukasJoss Sep 11, 2024
43e4e20
PB-227: Use dictionary for icon-set language metadata
LukasJoss Sep 11, 2024
8cc7db3
Merge pull request #86 from geoadmin/feat-PB-227-update-language
LukasJoss Sep 11, 2024
a9be0fe
PB-227: Rename dict files
LukasJoss Sep 11, 2024
1f84ae4
Merge pull request #87 from geoadmin/feat-PB-227-rename-dict-files
LukasJoss Sep 11, 2024
30789b6
PB-508: unlist new babs icon sets so that new image can be made for m…
LukasJoss Sep 12, 2024
f975549
PB-508: Fix variable names
LukasJoss Sep 12, 2024
10a1567
PB-508: Made the unlisted icon set configurable
ltshb Sep 12, 2024
35235fd
Merge pull request #88 from geoadmin/unlist-new-babs-icon-sets
ltshb Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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