From f6f2d8dca99760da464e57cc6c47cbad3627f05a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 7 Oct 2015 22:26:19 +0200 Subject: [PATCH] First version of an icon import script (cf #201) --- .gitignore | 1 + osmic-white.yaml | 31 +++++++++++++ osmic.yaml | 31 +++++++++++++ umap/management/__init__.py | 0 umap/management/commands/__init__.py | 0 umap/management/commands/import_pictograms.py | 46 +++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 osmic-white.yaml create mode 100644 osmic.yaml create mode 100644 umap/management/__init__.py create mode 100644 umap/management/commands/__init__.py create mode 100644 umap/management/commands/import_pictograms.py diff --git a/.gitignore b/.gitignore index e88576f4..a44ba26e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ umap/settings/local/* docs/_build umap/remote_static .idea +tmp/* diff --git a/osmic-white.yaml b/osmic-white.yaml new file mode 100644 index 00000000..6bf0c5ac --- /dev/null +++ b/osmic-white.yaml @@ -0,0 +1,31 @@ +input_dirs: + - "accommodation" + - "administration" + - "amenity" + - "barrier" + - "eat-drink" + - "emergency" + - "energy" + - "health" + - "money" + - "nature" + - "outdoor" + - "religious" + - "shop" + - "sports" + - "tourism" + - "transport" + +output: "tmp/white" +empty_output: true +format: "png" +subdirs: false + +global_style: + padding: 4 + fill: "#ededed" + + halo: + fill: "#444444" + width: 1 + opacity: 0.3 diff --git a/osmic.yaml b/osmic.yaml new file mode 100644 index 00000000..47d9831f --- /dev/null +++ b/osmic.yaml @@ -0,0 +1,31 @@ +input_dirs: + - "accommodation" + - "administration" + - "amenity" + - "barrier" + - "eat-drink" + - "emergency" + - "energy" + - "health" + - "money" + - "nature" + - "outdoor" + - "religious" + - "shop" + - "sports" + - "tourism" + - "transport" + +output: "tmp/grey" +empty_output: true +format: "png" +subdirs: false + +global_style: + padding: 4 + fill: "#444444" + + halo: + fill: "#ededed" + width: 1 + opacity: 0.3 diff --git a/umap/management/__init__.py b/umap/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/umap/management/commands/__init__.py b/umap/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/umap/management/commands/import_pictograms.py b/umap/management/commands/import_pictograms.py new file mode 100644 index 00000000..11cae597 --- /dev/null +++ b/umap/management/commands/import_pictograms.py @@ -0,0 +1,46 @@ +import os + +from django.core.files import File +from django.core.management.base import BaseCommand + +from leaflet_storage.models import Pictogram + + +class Command(BaseCommand): + help = 'Import pictograms from a folder' + + def add_arguments(self, parser): + parser.add_argument('path') + parser.add_argument('--attribution', required=True, + help='Attribution of the imported pictograms') + parser.add_argument('--suffix', + help='Optionnal suffix to add to each name') + parser.add_argument('--force', action='store_true', + help='Update picto if it already exists.') + + def handle(self, *args, **options): + path = options['path'] + attribution = options['attribution'] + suffix = options['suffix'] + force = options['force'] + for filename in os.listdir(path): + if filename.endswith("-24.png"): + name = self.extract_name(filename) + if suffix: + name = '{name}{suffix}'.format(name=name, suffix=suffix) + picto = Pictogram.objects.filter(name=name).last() + if picto: + if not force: + self.stdout.write(u"⚠ Pictogram with name '{name}' already exists. Skipping.".format(name=name)) # noqa + continue + else: + picto = Pictogram() + picto.name = name + filepath = os.path.join(path, filename) + with open(filepath, 'rb') as f: + picto.attribution = attribution + picto.pictogram.save(filename, File(f), save=True) + self.stdout.write(u"✔ Imported pictogram {filename}.".format(filename=filename)) # noqa + + def extract_name(self, filename): + return filename[:-7].replace('-', ' ')