First version of an icon import script (cf #201)

This commit is contained in:
Yohan Boniface 2015-10-07 22:26:19 +02:00
parent fd8e9aa0bb
commit f6f2d8dca9
6 changed files with 109 additions and 0 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ umap/settings/local/*
docs/_build
umap/remote_static
.idea
tmp/*

31
osmic-white.yaml Normal file
View file

@ -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

31
osmic.yaml Normal file
View file

@ -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

View file

View file

View file

@ -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('-', ' ')