diff --git a/db_apps/oemof_results.py b/db_apps/oemof_results.py
index 606c932..0782660 100644
--- a/db_apps/oemof_results.py
+++ b/db_apps/oemof_results.py
@@ -1,9 +1,7 @@
-
import re
import pandas
import transaction
-from sqlalchemy import (
- Column, Integer, String, ARRAY, ForeignKey)
+from sqlalchemy import Column, Integer, String, ARRAY, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION
from sqlalchemy.ext.declarative import declarative_base
@@ -48,90 +46,49 @@
class OemofInputResult(Base):
- __tablename__ = 'stemp_oemof_input_result'
+ __tablename__ = "stemp_oemof_input_result"
- input_result_id = Column(
- Integer,
- primary_key=True
- )
- input_id = Column(Integer, ForeignKey('stemp_oemof_data.data_id'))
- result_id = Column(Integer, ForeignKey('stemp_oemof_data.data_id'))
+ input_result_id = Column(Integer, primary_key=True)
+ input_id = Column(Integer, ForeignKey("stemp_oemof_data.data_id"))
+ result_id = Column(Integer, ForeignKey("stemp_oemof_data.data_id"))
input = relationship(
- "OemofData",
- backref="input",
- uselist=False,
- foreign_keys=[input_id],
+ "OemofData", backref="input", uselist=False, foreign_keys=[input_id],
)
result = relationship(
- "OemofData",
- backref="result",
- uselist=False,
- foreign_keys=[result_id],
+ "OemofData", backref="result", uselist=False, foreign_keys=[result_id],
)
class OemofData(Base):
- __tablename__ = 'stemp_oemof_data'
+ __tablename__ = "stemp_oemof_data"
- data_id = Column(
- Integer,
- primary_key=True
- )
+ data_id = Column(Integer, primary_key=True)
scalars = relationship("OemofScalar", cascade="delete")
sequences = relationship("OemofSequence", cascade="delete")
class OemofScalar(Base):
- __tablename__ = 'stemp_oemof_scalar'
+ __tablename__ = "stemp_oemof_scalar"
- scalar_id = Column(
- Integer,
- primary_key=True
- )
- data_id = Column(
- Integer, ForeignKey('stemp_oemof_data.data_id'))
- from_node = Column(
- String
- )
- to_node = Column(
- String
- )
- attribute = Column(
- String
- )
- value = Column(
- String
- )
- type = Column(
- String
- )
+ scalar_id = Column(Integer, primary_key=True)
+ data_id = Column(Integer, ForeignKey("stemp_oemof_data.data_id"))
+ from_node = Column(String)
+ to_node = Column(String)
+ attribute = Column(String)
+ value = Column(String)
+ type = Column(String)
class OemofSequence(Base):
- __tablename__ = 'stemp_oemof_sequence'
+ __tablename__ = "stemp_oemof_sequence"
- sequence_id = Column(
- Integer,
- primary_key=True
- )
- data_id = Column(
- Integer, ForeignKey('stemp_oemof_data.data_id'))
- from_node = Column(
- String
- )
- to_node = Column(
- String,
- nullable=True
- )
- attribute = Column(
- String
- )
- value = Column(
- ARRAY(DOUBLE_PRECISION)
- )
- type = Column(
- String
- )
+ sequence_id = Column(Integer, primary_key=True)
+ data_id = Column(Integer, ForeignKey("stemp_oemof_data.data_id"))
+ from_node = Column(String)
+ to_node = Column(String, nullable=True)
+ attribute = Column(String)
+ value = Column(ARRAY(DOUBLE_PRECISION))
+ type = Column(String)
def store_results(session, input_data, result_data):
@@ -166,34 +123,33 @@ def store_results(session, input_data, result_data):
result_data = convert_keys_to_strings(result_data)
input_result = OemofInputResult()
- for input_result_attr, data in (
- ('input', input_data), ('result', result_data)):
+ for input_result_attr, data in (("input", input_data), ("result", result_data)):
scalars = []
sequences = []
for (from_node, to_node), sc_sq_dict in data.items():
- for key, value in sc_sq_dict['scalars'].items():
+ for key, value in sc_sq_dict["scalars"].items():
scalars.append(
OemofScalar(
from_node=from_node,
to_node=to_node,
attribute=key,
value=value,
- type=type(value).__name__
+ type=type(value).__name__,
)
)
session.add_all(scalars)
- for key, series in sc_sq_dict['sequences'].items():
- list_type = 'list'
+ for key, series in sc_sq_dict["sequences"].items():
+ list_type = "list"
if isinstance(series, pandas.Series):
series = series.values.tolist()
- list_type = 'series'
+ list_type = "series"
sequences.append(
OemofSequence(
from_node=from_node,
to_node=to_node,
attribute=key,
value=series,
- type=list_type
+ type=list_type,
)
)
session.add_all(sequences)
@@ -208,8 +164,9 @@ def store_results(session, input_data, result_data):
return result_id
-def restore_results(session, input_result_id, restore_none_type=False,
- advanced_label=None):
+def restore_results(
+ session, input_result_id, restore_none_type=False, advanced_label=None
+):
"""
Restores input and result data from OemofInputResult from DB
@@ -229,49 +186,47 @@ def restore_results(session, input_result_id, restore_none_type=False,
(dict, dict):
Restored input- and result-data
"""
+
def type_conversion(value_str, value_type):
- if value_type == 'str':
+ if value_type == "str":
return value_str
- elif value_type == 'float':
+ elif value_type == "float":
return float(value_str)
- elif value_type == 'int':
+ elif value_type == "int":
return int(value_str)
- elif value_type == 'bool':
+ elif value_type == "bool":
return bool(value_str)
else:
raise TypeError('Unknown conversion type "' + value_type + '"')
def convert_label_to_namedtuple(label):
def unpack_tuples(value):
- if value.startswith('(') and value.endswith(')'):
- value_list = value[1:-1].split(', ')
+ if value.startswith("(") and value.endswith(")"):
+ value_list = value[1:-1].split(", ")
if len(value_list) == 1:
single = value_list[0][:-1]
- return (None, ) if single == 'None' else (single, )
+ return (None,) if single == "None" else (single,)
else:
- return (None if v == 'None' else v for v in value_list)
+ return (None if v == "None" else v for v in value_list)
else:
- return None if value == 'None' else value
+ return None if value == "None" else value
pattern = (
- f"{advanced_label.__name__}\(" +
- ', '.join(
+ f"{advanced_label.__name__}\("
+ + ", ".join(
[
f"{field}=(?P<{field}>[\(\)A-Za-z0-9#._\-,\ ']*)"
for field in advanced_label._fields
]
- ) +
- "\)"
+ )
+ + "\)"
)
try:
- match = re.match(pattern, label.replace('\'', ''))
+ match = re.match(pattern, label.replace("'", ""))
except AttributeError:
return label
if match is not None:
- fields = {
- k: unpack_tuples(v)
- for k, v in match.groupdict().items()
- }
+ fields = {k: unpack_tuples(v) for k, v in match.groupdict().items()}
return advanced_label(**fields)
else:
return label
@@ -281,35 +236,39 @@ def get_nodes(scalar_or_sequence):
if advanced_label is not None:
raw_nodes = tuple(map(convert_label_to_namedtuple, raw_nodes))
if restore_none_type:
- return tuple(map(lambda x: None if x == 'None' else x, raw_nodes))
+ return tuple(map(lambda x: None if x == "None" else x, raw_nodes))
else:
return raw_nodes
# Find results:
- input_result = session.query(OemofInputResult).filter(
- OemofInputResult.input_result_id == input_result_id).first()
+ input_result = (
+ session.query(OemofInputResult)
+ .filter(OemofInputResult.input_result_id == input_result_id)
+ .first()
+ )
if input_result is None:
raise IndexError(
- 'Could not find OemofInputResult with ID #' + str(input_result_id))
+ "Could not find OemofInputResult with ID #" + str(input_result_id)
+ )
input_data = {}
result_data = {}
- for input_result_attr, data in (
- ('input', input_data), ('result', result_data)):
+ for input_result_attr, data in (("input", input_data), ("result", result_data)):
ir_attr = getattr(input_result, input_result_attr)
for scalar in ir_attr.scalars:
nodes = get_nodes(scalar)
if nodes not in data:
- data[nodes] = {'scalars': {}, 'sequences': {}}
- data[nodes]['scalars'][scalar.attribute] = type_conversion(
- scalar.value, scalar.type)
+ data[nodes] = {"scalars": {}, "sequences": {}}
+ data[nodes]["scalars"][scalar.attribute] = type_conversion(
+ scalar.value, scalar.type
+ )
for sequence in ir_attr.sequences:
nodes = get_nodes(sequence)
if nodes not in data:
- data[nodes] = {'scalars': {}, 'sequences': {}}
- if sequence.type == 'series':
+ data[nodes] = {"scalars": {}, "sequences": {}}
+ if sequence.type == "series":
series = pandas.Series(sequence.value)
else:
series = sequence.value
- data[nodes]['sequences'][sequence.attribute] = series
+ data[nodes]["sequences"][sequence.attribute] = series
return input_data, result_data
diff --git a/doc/_static/run_tasks.py b/doc/_static/run_tasks.py
index 3b590f0..1bf1165 100644
--- a/doc/_static/run_tasks.py
+++ b/doc/_static/run_tasks.py
@@ -1,4 +1,3 @@
-
from app_name import tasks
diff --git a/doc/_static/tasks.py b/doc/_static/tasks.py
index 8092883..8b6d4dc 100644
--- a/doc/_static/tasks.py
+++ b/doc/_static/tasks.py
@@ -1,4 +1,3 @@
-
from wam.celery import app
diff --git a/doc/conf.py b/doc/conf.py
index b9ea50f..54175ac 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -19,14 +19,14 @@
# -- Project information -----------------------------------------------------
-project = 'WAM-Server'
-copyright = '2018, Hendrik Huyskens'
-author = 'Hendrik Huyskens'
+project = "WAM-Server"
+copyright = "2018, Hendrik Huyskens"
+author = "Hendrik Huyskens"
# The short X.Y version
-version = ''
+version = ""
# The full version, including alpha/beta/rc tags
-release = ''
+release = ""
# -- General configuration ---------------------------------------------------
@@ -39,25 +39,25 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
- 'sphinx.ext.autodoc',
- 'sphinx.ext.doctest',
- 'sphinx.ext.intersphinx',
- 'sphinx.ext.todo',
- 'sphinx.ext.coverage',
- 'sphinx.ext.viewcode',
+ "sphinx.ext.autodoc",
+ "sphinx.ext.doctest",
+ "sphinx.ext.intersphinx",
+ "sphinx.ext.todo",
+ "sphinx.ext.coverage",
+ "sphinx.ext.viewcode",
]
# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
+templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
-source_suffix = '.rst'
+source_suffix = ".rst"
# The master toctree document.
-master_doc = 'index'
+master_doc = "index"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -80,7 +80,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
-html_theme = 'alabaster'
+html_theme = "alabaster"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@@ -91,7 +91,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+html_static_path = ["_static"]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
@@ -107,7 +107,7 @@
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
-htmlhelp_basename = 'WAM-Serverdoc'
+htmlhelp_basename = "WAM-Serverdoc"
# -- Options for LaTeX output ------------------------------------------------
@@ -116,15 +116,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
-
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
-
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
-
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
@@ -134,8 +131,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
- (master_doc, 'WAM-Server.tex', 'WAM-Server Documentation',
- 'Hendrik Huyskens', 'manual'),
+ (
+ master_doc,
+ "WAM-Server.tex",
+ "WAM-Server Documentation",
+ "Hendrik Huyskens",
+ "manual",
+ ),
]
@@ -143,10 +145,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
-man_pages = [
- (master_doc, 'wam-server', 'WAM-Server Documentation',
- [author], 1)
-]
+man_pages = [(master_doc, "wam-server", "WAM-Server Documentation", [author], 1)]
# -- Options for Texinfo output ----------------------------------------------
@@ -155,9 +154,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- (master_doc, 'WAM-Server', 'WAM-Server Documentation',
- author, 'WAM-Server', 'One line description of project.',
- 'Miscellaneous'),
+ (
+ master_doc,
+ "WAM-Server",
+ "WAM-Server Documentation",
+ author,
+ "WAM-Server",
+ "One line description of project.",
+ "Miscellaneous",
+ ),
]
@@ -176,7 +181,7 @@
# epub_uid = ''
# A list of files that should not be packed into the epub file.
-epub_exclude_files = ['search.html']
+epub_exclude_files = ["search.html"]
# -- Extension configuration -------------------------------------------------
@@ -184,9 +189,9 @@
# -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library.
-intersphinx_mapping = {'https://docs.python.org/': None}
+intersphinx_mapping = {"https://docs.python.org/": None}
# -- Options for todo extension ----------------------------------------------
# If true, `todo` and `todoList` produce output, else they produce nothing.
-todo_include_todos = True
\ No newline at end of file
+todo_include_todos = True
diff --git a/install_requirements.py b/install_requirements.py
index 2854758..f2d00b4 100644
--- a/install_requirements.py
+++ b/install_requirements.py
@@ -2,11 +2,9 @@
import subprocess
base_dir = os.path.abspath(os.path.curdir)
-pip_path = subprocess.check_output(['which', 'pip']).decode().strip('\n')
-apps = os.environ['WAM_APPS'].split(',')
+pip_path = subprocess.check_output(["which", "pip"]).decode().strip("\n")
+apps = os.environ["WAM_APPS"].split(",")
for app in apps:
- req_file = os.path.join(base_dir, app, 'requirements.txt')
+ req_file = os.path.join(base_dir, app, "requirements.txt")
if os.path.isfile(req_file):
- subprocess.call(
- [pip_path, 'install', '-r', req_file]
- )
+ subprocess.call([pip_path, "install", "-r", req_file])
diff --git a/meta/admin.py b/meta/admin.py
index 457fab9..6527fa7 100644
--- a/meta/admin.py
+++ b/meta/admin.py
@@ -1,4 +1,3 @@
-
from wam.admin import wam_admin_site
from meta import models
diff --git a/meta/apps.py b/meta/apps.py
index 13f6832..1767574 100644
--- a/meta/apps.py
+++ b/meta/apps.py
@@ -2,4 +2,4 @@
class MetaConfig(AppConfig):
- name = 'meta'
+ name = "meta"
diff --git a/meta/migrations/0001_initial.py b/meta/migrations/0001_initial.py
index 1849d75..c53b444 100644
--- a/meta/migrations/0001_initial.py
+++ b/meta/migrations/0001_initial.py
@@ -8,49 +8,76 @@ class Migration(migrations.Migration):
initial = True
- dependencies = [
- ]
+ dependencies = []
operations = [
migrations.CreateModel(
- name='Assumption',
+ name="Assumption",
fields=[
- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=255)),
- ('description', models.TextField()),
- ('value', models.CharField(max_length=64)),
- ('value_type', models.CharField(max_length=32)),
- ('app_name', models.CharField(max_length=255)),
+ (
+ "id",
+ models.AutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ ("name", models.CharField(max_length=255)),
+ ("description", models.TextField()),
+ ("value", models.CharField(max_length=64)),
+ ("value_type", models.CharField(max_length=32)),
+ ("app_name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
- name='Source',
+ name="Source",
fields=[
- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('author', models.CharField(max_length=255)),
- ('url', models.URLField()),
- ('description', models.TextField()),
- ('year', models.IntegerField()),
- ('license', models.CharField(max_length=255)),
- ('app_name', models.CharField(max_length=255)),
+ (
+ "id",
+ models.AutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ ("author", models.CharField(max_length=255)),
+ ("url", models.URLField()),
+ ("description", models.TextField()),
+ ("year", models.IntegerField()),
+ ("license", models.CharField(max_length=255)),
+ ("app_name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
- name='SourceCategory',
+ name="SourceCategory",
fields=[
- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('name', models.CharField(max_length=255)),
- ('description', models.TextField()),
+ (
+ "id",
+ models.AutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ ("name", models.CharField(max_length=255)),
+ ("description", models.TextField()),
],
),
migrations.AddField(
- model_name='source',
- name='category',
- field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='meta.SourceCategory'),
+ model_name="source",
+ name="category",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.DO_NOTHING, to="meta.SourceCategory"
+ ),
),
migrations.AddField(
- model_name='assumption',
- name='source',
- field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='meta.Source'),
+ model_name="assumption",
+ name="source",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.DO_NOTHING, to="meta.Source"
+ ),
),
]
diff --git a/meta/migrations/0002_auto_20181130_1141.py b/meta/migrations/0002_auto_20181130_1141.py
index 67e61bd..251c35b 100644
--- a/meta/migrations/0002_auto_20181130_1141.py
+++ b/meta/migrations/0002_auto_20181130_1141.py
@@ -6,13 +6,11 @@
class Migration(migrations.Migration):
dependencies = [
- ('meta', '0001_initial'),
+ ("meta", "0001_initial"),
]
operations = [
migrations.RenameField(
- model_name='assumption',
- old_name='value_type',
- new_name='unit',
+ model_name="assumption", old_name="value_type", new_name="unit",
),
]
diff --git a/meta/migrations/0003_source_meta_data.py b/meta/migrations/0003_source_meta_data.py
index 1c9c5b2..d392e9b 100644
--- a/meta/migrations/0003_source_meta_data.py
+++ b/meta/migrations/0003_source_meta_data.py
@@ -7,13 +7,13 @@
class Migration(migrations.Migration):
dependencies = [
- ('meta', '0002_auto_20181130_1141'),
+ ("meta", "0002_auto_20181130_1141"),
]
operations = [
migrations.AddField(
- model_name='source',
- name='meta_data',
+ model_name="source",
+ name="meta_data",
field=django.contrib.postgres.fields.jsonb.JSONField(null=True),
),
]
diff --git a/meta/migrations/0004_auto_20190207_1139.py b/meta/migrations/0004_auto_20190207_1139.py
index 354a78a..7d048bc 100644
--- a/meta/migrations/0004_auto_20190207_1139.py
+++ b/meta/migrations/0004_auto_20190207_1139.py
@@ -7,18 +7,19 @@
class Migration(migrations.Migration):
dependencies = [
- ('meta', '0003_source_meta_data'),
+ ("meta", "0003_source_meta_data"),
]
operations = [
- migrations.RenameModel(
- old_name='SourceCategory',
- new_name='Category',
- ),
+ migrations.RenameModel(old_name="SourceCategory", new_name="Category",),
migrations.AddField(
- model_name='assumption',
- name='category',
- field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.DO_NOTHING, to='meta.Category'),
+ model_name="assumption",
+ name="category",
+ field=models.ForeignKey(
+ default=None,
+ on_delete=django.db.models.deletion.DO_NOTHING,
+ to="meta.Category",
+ ),
preserve_default=False,
),
]
diff --git a/meta/migrations/0005_auto_20190211_1125.py b/meta/migrations/0005_auto_20190211_1125.py
index 88ba2e8..128a367 100644
--- a/meta/migrations/0005_auto_20190211_1125.py
+++ b/meta/migrations/0005_auto_20190211_1125.py
@@ -6,28 +6,13 @@
class Migration(migrations.Migration):
dependencies = [
- ('meta', '0004_auto_20190207_1139'),
+ ("meta", "0004_auto_20190207_1139"),
]
operations = [
- migrations.RemoveField(
- model_name='source',
- name='author',
- ),
- migrations.RemoveField(
- model_name='source',
- name='description',
- ),
- migrations.RemoveField(
- model_name='source',
- name='license',
- ),
- migrations.RemoveField(
- model_name='source',
- name='url',
- ),
- migrations.RemoveField(
- model_name='source',
- name='year',
- ),
+ migrations.RemoveField(model_name="source", name="author",),
+ migrations.RemoveField(model_name="source", name="description",),
+ migrations.RemoveField(model_name="source", name="license",),
+ migrations.RemoveField(model_name="source", name="url",),
+ migrations.RemoveField(model_name="source", name="year",),
]
diff --git a/meta/migrations/0006_auto_20191212_1617.py b/meta/migrations/0006_auto_20191212_1617.py
index 9c221e5..9a79ab7 100644
--- a/meta/migrations/0006_auto_20191212_1617.py
+++ b/meta/migrations/0006_auto_20191212_1617.py
@@ -7,23 +7,29 @@
class Migration(migrations.Migration):
dependencies = [
- ('meta', '0005_auto_20190211_1125'),
+ ("meta", "0005_auto_20190211_1125"),
]
operations = [
migrations.AlterField(
- model_name='assumption',
- name='category',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='meta.Category'),
+ model_name="assumption",
+ name="category",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE, to="meta.Category"
+ ),
),
migrations.AlterField(
- model_name='assumption',
- name='source',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='meta.Source'),
+ model_name="assumption",
+ name="source",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE, to="meta.Source"
+ ),
),
migrations.AlterField(
- model_name='source',
- name='category',
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='meta.Category'),
+ model_name="source",
+ name="category",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE, to="meta.Category"
+ ),
),
]
diff --git a/meta/models.py b/meta/models.py
index 41c1188..283b865 100644
--- a/meta/models.py
+++ b/meta/models.py
@@ -1,4 +1,3 @@
-
import jmespath
from django.db import models
@@ -13,6 +12,7 @@ class Assumption(models.Model):
A source must be assigned to exactly one :class:`Source` defined in
`source`.
"""
+
name = models.CharField(max_length=255)
description = models.TextField()
value = models.CharField(max_length=64)
@@ -20,8 +20,8 @@ class Assumption(models.Model):
app_name = models.CharField(max_length=255)
- source = models.ForeignKey('Source', on_delete=models.CASCADE)
- category = models.ForeignKey('Category', on_delete=models.CASCADE)
+ source = models.ForeignKey("Source", on_delete=models.CASCADE)
+ category = models.ForeignKey("Category", on_delete=models.CASCADE)
def __str__(self):
return self.name
@@ -33,30 +33,31 @@ class Source(models.Model):
A source must be assigned to exactly one :class:`Category`
defined in `category`.
"""
+
meta_data = JSONField(null=True)
app_name = models.CharField(max_length=255)
- category = models.ForeignKey('Category', on_delete=models.CASCADE)
+ category = models.ForeignKey("Category", on_delete=models.CASCADE)
def json(self):
return JsonWidget(self.meta_data).render()
def infos(self):
infos = jmespath.search(
- '{'
- 'url: identifier, '
- 'title: title, '
- 'description: description, '
- 'licenses: licenses[*].name'
- '}',
- self.meta_data
+ "{"
+ "url: identifier, "
+ "title: title, "
+ "description: description, "
+ "licenses: licenses[*].name"
+ "}",
+ self.meta_data,
)
- if infos.get('url') is not None:
- if infos.get('url') == '':
- infos.pop('url')
+ if infos.get("url") is not None:
+ if infos.get("url") == "":
+ infos.pop("url")
else:
- infos.pop('url')
+ infos.pop("url")
return infos
@@ -65,6 +66,7 @@ class Category(models.Model):
A category subsumes one or multiple sources, see :class:`Source`.
"""
+
name = models.CharField(max_length=255)
description = models.TextField()
diff --git a/meta/views.py b/meta/views.py
index de52f23..61ff53c 100644
--- a/meta/views.py
+++ b/meta/views.py
@@ -36,56 +36,52 @@ class AppListView(ListView):
* The template displays all items of a model in a table, each row has a
unique id
"""
- default_template_name = 'meta/app_list.html'
+
+ default_template_name = "meta/app_list.html"
app_name = None
- ordering = ['category__name']
+ ordering = ["category__name"]
title = "Quellen"
def __init__(self, *args, **kwargs):
super(AppListView, self).__init__(*args, **kwargs)
if self.app_name is not None:
- self.queryset = self.model.objects.filter(
- app_name=self.app_name)
+ self.queryset = self.model.objects.filter(app_name=self.app_name)
else:
self.queryset = self.model.objects.all()
def get_context_data(self, *, object_list=None, **kwargs):
# pylint: disable=protected-access
context = super(AppListView, self).get_context_data(
- object_list=object_list, **kwargs)
+ object_list=object_list, **kwargs
+ )
- context['title'] = self.title
+ context["title"] = self.title
# Try to load base.html template from app:
- base_template = 'meta/base.html'
+ base_template = "meta/base.html"
if self.app_name is not None:
base_template_file = os.path.join(
- BASE_DIR,
- self.app_name,
- 'templates',
- self.app_name,
- 'base.html'
+ BASE_DIR, self.app_name, "templates", self.app_name, "base.html"
)
if os.path.exists(base_template_file):
- base_template = self.app_name + '/base.html'
- context['base_template'] = base_template
+ base_template = self.app_name + "/base.html"
+ context["base_template"] = base_template
# Highlight specific id:
highlight_id = self.request.GET.get(self.model._meta.model_name, None)
if (
- highlight_id is not None and
- context['object_list'].filter(pk=highlight_id).exists()
+ highlight_id is not None
+ and context["object_list"].filter(pk=highlight_id).exists()
):
- context['highlight'] = str(highlight_id)
+ context["highlight"] = str(highlight_id)
# Highlight category:
- category_id = self.request.GET.get('category', None)
+ category_id = self.request.GET.get("category", None)
if (
- category_id is not None and
- context['object_list'].filter(
- category__pk=category_id).exists()
+ category_id is not None
+ and context["object_list"].filter(category__pk=category_id).exists()
):
- context['category'] = str(category_id)
+ context["category"] = str(category_id)
return context
@@ -101,12 +97,13 @@ class AssumptionsView(AppListView):
def get_context_data(self, *, object_list=None, **kwargs):
context = super(AssumptionsView, self).get_context_data(
- object_list=object_list, **kwargs)
+ object_list=object_list, **kwargs
+ )
if self.source_url is not None:
- context['source_url'] = self.source_url
+ context["source_url"] = self.source_url
else:
if self.app_name is not None:
- context['source_url'] = self.app_name + ':sources'
+ context["source_url"] = self.app_name + ":sources"
else:
- context['source_url'] = 'sources'
+ context["source_url"] = "sources"
return context
diff --git a/meta/widgets.py b/meta/widgets.py
index 2b6bcfa..0acb118 100644
--- a/meta/widgets.py
+++ b/meta/widgets.py
@@ -1,32 +1,35 @@
from django.utils.safestring import mark_safe
-class JsonWidget():
+class JsonWidget:
def __init__(self, json):
self.json = json
def __convert_to_html(self, data, level=0):
- html = ''
+ html = ""
if isinstance(data, dict):
- html += f'
'\
- if level > 0 else '
'
+ html += (
+ f'
'
+ if level > 0
+ else "
"
+ )
for key, value in data.items():
- html += f'{key}: {self.__convert_to_html(value, level+1)}'
- html += '
'
+ html += f"
{key}: {self.__convert_to_html(value, level+1)}"
+ html += "
"
elif isinstance(data, list):
html += f'
'
for item in data:
- html += f'{self.__convert_to_html(item, level+1)}'
- html += '
'
+ html += f"{self.__convert_to_html(item, level+1)}"
+ html += "
"
else:
- html += f'{data}
'
+ html += f"{data}
"
return html
def render(self):
- header = ''
+ header = ""
if self.json["title"] != "":
header += f'
{self.json["title"]}
'
if self.json["description"] != "":
diff --git a/setup.py b/setup.py
index 90d7c39..89b81b8 100644
--- a/setup.py
+++ b/setup.py
@@ -2,22 +2,23 @@
from setuptools import setup, find_packages
-with open('requirements.txt') as f:
+with open("requirements.txt") as f:
requirements = f.read().splitlines()
git_requirements = [
f"{req.split('#egg=')[1]} @ {req}"
- for req in requirements if req.startswith('git')
+ for req in requirements
+ if req.startswith("git")
]
- normal_requirements = [req for req in requirements if not req.startswith('git')]
+ normal_requirements = [req for req in requirements if not req.startswith("git")]
setup(
- name='wam',
- version='0.1.3',
+ name="wam",
+ version="0.1.3",
packages=find_packages(),
- license='GNU Affero General Public License v3.0',
- author='henhuy, nesnoj, Bachibouzouk, christian-rli, 4lm',
- description='WAM - Web Applications & Maps',
- url='https://github.com/rl-institut/WAM',
+ license="GNU Affero General Public License v3.0",
+ author="henhuy, nesnoj, Bachibouzouk, christian-rli, 4lm",
+ description="WAM - Web Applications & Maps",
+ url="https://github.com/rl-institut/WAM",
install_requires=normal_requirements + git_requirements,
- scripts=['manage.py']
+ scripts=["manage.py"],
)
diff --git a/static/ionicons-2.0.1/builder/generate.py b/static/ionicons-2.0.1/builder/generate.py
index 8bfff53..39ae07c 100644
--- a/static/ionicons-2.0.1/builder/generate.py
+++ b/static/ionicons-2.0.1/builder/generate.py
@@ -4,315 +4,316 @@
BUILDER_PATH = os.path.dirname(os.path.abspath(__file__))
-ROOT_PATH = os.path.join(BUILDER_PATH, '..')
-FONTS_FOLDER_PATH = os.path.join(ROOT_PATH, 'fonts')
-CSS_FOLDER_PATH = os.path.join(ROOT_PATH, 'css')
-SCSS_FOLDER_PATH = os.path.join(ROOT_PATH, 'scss')
-LESS_FOLDER_PATH = os.path.join(ROOT_PATH, 'less')
+ROOT_PATH = os.path.join(BUILDER_PATH, "..")
+FONTS_FOLDER_PATH = os.path.join(ROOT_PATH, "fonts")
+CSS_FOLDER_PATH = os.path.join(ROOT_PATH, "css")
+SCSS_FOLDER_PATH = os.path.join(ROOT_PATH, "scss")
+LESS_FOLDER_PATH = os.path.join(ROOT_PATH, "less")
def main():
- generate_font_files()
+ generate_font_files()
- data = get_build_data()
+ data = get_build_data()
- rename_svg_glyph_names(data)
- generate_scss(data)
- generate_less(data)
- generate_cheatsheet(data)
- generate_component_json(data)
- generate_composer_json(data)
- generate_bower_json(data)
+ rename_svg_glyph_names(data)
+ generate_scss(data)
+ generate_less(data)
+ generate_cheatsheet(data)
+ generate_component_json(data)
+ generate_composer_json(data)
+ generate_bower_json(data)
def generate_font_files():
- print "Generate Fonts"
- cmd = "fontforge -script %s/scripts/generate_font.py" % (BUILDER_PATH)
- call(cmd, shell=True)
+ print "Generate Fonts"
+ cmd = "fontforge -script %s/scripts/generate_font.py" % (BUILDER_PATH)
+ call(cmd, shell=True)
def rename_svg_glyph_names(data):
- # hacky and slow (but safe) way to rename glyph-name attributes
- svg_path = os.path.join(FONTS_FOLDER_PATH, 'ionicons.svg')
- svg_file = open(svg_path, 'r+')
- svg_text = svg_file.read()
- svg_file.seek(0)
+ # hacky and slow (but safe) way to rename glyph-name attributes
+ svg_path = os.path.join(FONTS_FOLDER_PATH, "ionicons.svg")
+ svg_file = open(svg_path, "r+")
+ svg_text = svg_file.read()
+ svg_file.seek(0)
- for ionicon in data['icons']:
- # uniF2CA
- org_name = 'uni%s' % (ionicon['code'].replace('0x', '').upper())
- ion_name = 'ion-%s' % (ionicon['name'])
- svg_text = svg_text.replace(org_name, ion_name)
+ for ionicon in data["icons"]:
+ # uniF2CA
+ org_name = "uni%s" % (ionicon["code"].replace("0x", "").upper())
+ ion_name = "ion-%s" % (ionicon["name"])
+ svg_text = svg_text.replace(org_name, ion_name)
- svg_file.write(svg_text)
- svg_file.close()
+ svg_file.write(svg_text)
+ svg_file.close()
def generate_less(data):
- print "Generate LESS"
- font_name = data['name']
- font_version = data['version']
- css_prefix = data['prefix']
- variables_file_path = os.path.join(LESS_FOLDER_PATH, '_ionicons-variables.less')
- icons_file_path = os.path.join(LESS_FOLDER_PATH, '_ionicons-icons.less')
-
- d = []
- d.append('/*!');
- d.append('Ionicons, v%s' % (font_version) );
- d.append('Created by Ben Sperry for the Ionic Framework, http://ionicons.com/');
- d.append('https://twitter.com/benjsperry https://twitter.com/ionicframework');
- d.append('MIT License: https://github.com/driftyco/ionicons');
- d.append('*/');
- d.append('// Ionicons Variables')
- d.append('// --------------------------\n')
- d.append('@ionicons-font-path: "../fonts";')
- d.append('@ionicons-font-family: "%s";' % (font_name) )
- d.append('@ionicons-version: "%s";' % (font_version) )
- d.append('@ionicons-prefix: %s;' % (css_prefix) )
- d.append('')
- for ionicon in data['icons']:
- chr_code = ionicon['code'].replace('0x', '\\')
- d.append('@ionicon-var-%s: "%s";' % (ionicon['name'], chr_code) )
- f = open(variables_file_path, 'w')
- f.write( '\n'.join(d) )
- f.close()
-
- d = []
- d.append('// Ionicons Icons')
- d.append('// --------------------------\n')
-
- group = [ '.%s' % (data['name'].lower()) ]
- for ionicon in data['icons']:
- group.append('.@{ionicons-prefix}%s:before' % (ionicon['name']) )
-
- d.append( ',\n'.join(group) )
-
- d.append('{')
- d.append(' &:extend(.ion);')
- d.append('}')
-
- for ionicon in data['icons']:
- chr_code = ionicon['code'].replace('0x', '\\')
- d.append('.@{ionicons-prefix}%s:before { content: @ionicon-var-%s; }' % (ionicon['name'], ionicon['name']) )
-
- f = open(icons_file_path, 'w')
- f.write( '\n'.join(d) )
- f.close()
+ print "Generate LESS"
+ font_name = data["name"]
+ font_version = data["version"]
+ css_prefix = data["prefix"]
+ variables_file_path = os.path.join(LESS_FOLDER_PATH, "_ionicons-variables.less")
+ icons_file_path = os.path.join(LESS_FOLDER_PATH, "_ionicons-icons.less")
+
+ d = []
+ d.append("/*!")
+ d.append("Ionicons, v%s" % (font_version))
+ d.append("Created by Ben Sperry for the Ionic Framework, http://ionicons.com/")
+ d.append("https://twitter.com/benjsperry https://twitter.com/ionicframework")
+ d.append("MIT License: https://github.com/driftyco/ionicons")
+ d.append("*/")
+ d.append("// Ionicons Variables")
+ d.append("// --------------------------\n")
+ d.append('@ionicons-font-path: "../fonts";')
+ d.append('@ionicons-font-family: "%s";' % (font_name))
+ d.append('@ionicons-version: "%s";' % (font_version))
+ d.append("@ionicons-prefix: %s;" % (css_prefix))
+ d.append("")
+ for ionicon in data["icons"]:
+ chr_code = ionicon["code"].replace("0x", "\\")
+ d.append('@ionicon-var-%s: "%s";' % (ionicon["name"], chr_code))
+ f = open(variables_file_path, "w")
+ f.write("\n".join(d))
+ f.close()
+
+ d = []
+ d.append("// Ionicons Icons")
+ d.append("// --------------------------\n")
+
+ group = [".%s" % (data["name"].lower())]
+ for ionicon in data["icons"]:
+ group.append(".@{ionicons-prefix}%s:before" % (ionicon["name"]))
+
+ d.append(",\n".join(group))
+
+ d.append("{")
+ d.append(" &:extend(.ion);")
+ d.append("}")
+
+ for ionicon in data["icons"]:
+ chr_code = ionicon["code"].replace("0x", "\\")
+ d.append(
+ ".@{ionicons-prefix}%s:before { content: @ionicon-var-%s; }"
+ % (ionicon["name"], ionicon["name"])
+ )
+
+ f = open(icons_file_path, "w")
+ f.write("\n".join(d))
+ f.close()
def generate_scss(data):
- print "Generate SCSS"
- font_name = data['name']
- font_version = data['version']
- css_prefix = data['prefix']
- variables_file_path = os.path.join(SCSS_FOLDER_PATH, '_ionicons-variables.scss')
- icons_file_path = os.path.join(SCSS_FOLDER_PATH, '_ionicons-icons.scss')
-
- d = []
- d.append('// Ionicons Variables')
- d.append('// --------------------------\n')
- d.append('$ionicons-font-path: "../fonts" !default;')
- d.append('$ionicons-font-family: "%s" !default;' % (font_name) )
- d.append('$ionicons-version: "%s" !default;' % (font_version) )
- d.append('$ionicons-prefix: %s !default;' % (css_prefix) )
- d.append('')
- for ionicon in data['icons']:
- chr_code = ionicon['code'].replace('0x', '\\')
- d.append('$ionicon-var-%s: "%s";' % (ionicon['name'], chr_code) )
- f = open(variables_file_path, 'w')
- f.write( '\n'.join(d) )
- f.close()
-
- d = []
- d.append('// Ionicons Icons')
- d.append('// --------------------------\n')
-
- group = [ '.%s' % (data['name'].lower()) ]
- for ionicon in data['icons']:
- group.append('.#{$ionicons-prefix}%s:before' % (ionicon['name']) )
-
- d.append( ',\n'.join(group) )
-
- d.append('{')
- d.append(' @extend .ion;')
- d.append('}')
-
- for ionicon in data['icons']:
- chr_code = ionicon['code'].replace('0x', '\\')
- d.append('.#{$ionicons-prefix}%s:before { content: $ionicon-var-%s; }' % (ionicon['name'], ionicon['name']) )
-
- f = open(icons_file_path, 'w')
- f.write( '\n'.join(d) )
- f.close()
-
- generate_css_from_scss(data)
+ print "Generate SCSS"
+ font_name = data["name"]
+ font_version = data["version"]
+ css_prefix = data["prefix"]
+ variables_file_path = os.path.join(SCSS_FOLDER_PATH, "_ionicons-variables.scss")
+ icons_file_path = os.path.join(SCSS_FOLDER_PATH, "_ionicons-icons.scss")
+
+ d = []
+ d.append("// Ionicons Variables")
+ d.append("// --------------------------\n")
+ d.append('$ionicons-font-path: "../fonts" !default;')
+ d.append('$ionicons-font-family: "%s" !default;' % (font_name))
+ d.append('$ionicons-version: "%s" !default;' % (font_version))
+ d.append("$ionicons-prefix: %s !default;" % (css_prefix))
+ d.append("")
+ for ionicon in data["icons"]:
+ chr_code = ionicon["code"].replace("0x", "\\")
+ d.append('$ionicon-var-%s: "%s";' % (ionicon["name"], chr_code))
+ f = open(variables_file_path, "w")
+ f.write("\n".join(d))
+ f.close()
+
+ d = []
+ d.append("// Ionicons Icons")
+ d.append("// --------------------------\n")
+
+ group = [".%s" % (data["name"].lower())]
+ for ionicon in data["icons"]:
+ group.append(".#{$ionicons-prefix}%s:before" % (ionicon["name"]))
+
+ d.append(",\n".join(group))
+
+ d.append("{")
+ d.append(" @extend .ion;")
+ d.append("}")
+
+ for ionicon in data["icons"]:
+ chr_code = ionicon["code"].replace("0x", "\\")
+ d.append(
+ ".#{$ionicons-prefix}%s:before { content: $ionicon-var-%s; }"
+ % (ionicon["name"], ionicon["name"])
+ )
+
+ f = open(icons_file_path, "w")
+ f.write("\n".join(d))
+ f.close()
+
+ generate_css_from_scss(data)
def generate_css_from_scss(data):
- print "Generate CSS From SCSS"
+ print "Generate CSS From SCSS"
- scss_file_path = os.path.join(SCSS_FOLDER_PATH, 'ionicons.scss')
- css_file_path = os.path.join(CSS_FOLDER_PATH, 'ionicons.css')
- css_min_file_path = os.path.join(CSS_FOLDER_PATH, 'ionicons.min.css')
+ scss_file_path = os.path.join(SCSS_FOLDER_PATH, "ionicons.scss")
+ css_file_path = os.path.join(CSS_FOLDER_PATH, "ionicons.css")
+ css_min_file_path = os.path.join(CSS_FOLDER_PATH, "ionicons.min.css")
- cmd = "sass %s %s --style compact" % (scss_file_path, css_file_path)
- call(cmd, shell=True)
+ cmd = "sass %s %s --style compact" % (scss_file_path, css_file_path)
+ call(cmd, shell=True)
- print "Generate Minified CSS From SCSS"
- cmd = "sass %s %s --style compressed" % (scss_file_path, css_min_file_path)
- call(cmd, shell=True)
+ print "Generate Minified CSS From SCSS"
+ cmd = "sass %s %s --style compressed" % (scss_file_path, css_min_file_path)
+ call(cmd, shell=True)
def generate_cheatsheet(data):
- print "Generate Cheatsheet"
+ print "Generate Cheatsheet"
- cheatsheet_file_path = os.path.join(ROOT_PATH, 'cheatsheet.html')
- template_path = os.path.join(BUILDER_PATH, 'cheatsheet', 'template.html')
- icon_row_path = os.path.join(BUILDER_PATH, 'cheatsheet', 'icon-row.html')
+ cheatsheet_file_path = os.path.join(ROOT_PATH, "cheatsheet.html")
+ template_path = os.path.join(BUILDER_PATH, "cheatsheet", "template.html")
+ icon_row_path = os.path.join(BUILDER_PATH, "cheatsheet", "icon-row.html")
- f = open(template_path, 'r')
- template_html = f.read()
- f.close()
+ f = open(template_path, "r")
+ template_html = f.read()
+ f.close()
- f = open(icon_row_path, 'r')
- icon_row_template = f.read()
- f.close()
+ f = open(icon_row_path, "r")
+ icon_row_template = f.read()
+ f.close()
- content = []
+ content = []
- for ionicon in data['icons']:
- css_code = ionicon['code'].replace('0x', '\\')
- escaped_html_code = ionicon['code'].replace('0x', '&#x') + ';'
- html_code = ionicon['code'].replace('0x', '') + ';'
- item_row = icon_row_template
+ for ionicon in data["icons"]:
+ css_code = ionicon["code"].replace("0x", "\\")
+ escaped_html_code = ionicon["code"].replace("0x", "&#x") + ";"
+ html_code = ionicon["code"].replace("0x", "") + ";"
+ item_row = icon_row_template
- item_row = item_row.replace('{{name}}', ionicon['name'])
- item_row = item_row.replace('{{prefix}}', data['prefix'])
- item_row = item_row.replace('{{css_code}}', css_code)
- item_row = item_row.replace('{{escaped_html_code}}', escaped_html_code)
- item_row = item_row.replace('{{html_code}}', html_code)
+ item_row = item_row.replace("{{name}}", ionicon["name"])
+ item_row = item_row.replace("{{prefix}}", data["prefix"])
+ item_row = item_row.replace("{{css_code}}", css_code)
+ item_row = item_row.replace("{{escaped_html_code}}", escaped_html_code)
+ item_row = item_row.replace("{{html_code}}", html_code)
- content.append(item_row)
+ content.append(item_row)
- template_html = template_html.replace("{{font_name}}", data["name"])
- template_html = template_html.replace("{{font_version}}", data["version"])
- template_html = template_html.replace("{{icon_count}}", str(len(data["icons"])) )
- template_html = template_html.replace("{{content}}", '\n'.join(content) )
+ template_html = template_html.replace("{{font_name}}", data["name"])
+ template_html = template_html.replace("{{font_version}}", data["version"])
+ template_html = template_html.replace("{{icon_count}}", str(len(data["icons"])))
+ template_html = template_html.replace("{{content}}", "\n".join(content))
- f = open(cheatsheet_file_path, 'w')
- f.write(template_html)
- f.close()
+ f = open(cheatsheet_file_path, "w")
+ f.write(template_html)
+ f.close()
def generate_component_json(data):
- print "Generate component.json"
- d = {
- "name": data['name'],
- "repo": "driftyco/ionicons",
- "description": "The premium icon font for Ionic Framework.",
- "version": data['version'],
- "keywords": [],
- "dependencies": {},
- "development": {},
- "license": "MIT",
- "styles": [
- "css/%s.css" % (data['name'].lower())
- ],
- "fonts": [
- "fonts/%s.eot" % (data['name'].lower()),
- "fonts/%s.svg" % (data['name'].lower()),
- "fonts/%s.ttf" % (data['name'].lower()),
- "fonts/%s.woff" % (data['name'].lower())
- ]
- }
- txt = json.dumps(d, indent=4, separators=(',', ': '))
-
- component_file_path = os.path.join(ROOT_PATH, 'component.json')
- f = open(component_file_path, 'w')
- f.write(txt)
- f.close()
+ print "Generate component.json"
+ d = {
+ "name": data["name"],
+ "repo": "driftyco/ionicons",
+ "description": "The premium icon font for Ionic Framework.",
+ "version": data["version"],
+ "keywords": [],
+ "dependencies": {},
+ "development": {},
+ "license": "MIT",
+ "styles": ["css/%s.css" % (data["name"].lower())],
+ "fonts": [
+ "fonts/%s.eot" % (data["name"].lower()),
+ "fonts/%s.svg" % (data["name"].lower()),
+ "fonts/%s.ttf" % (data["name"].lower()),
+ "fonts/%s.woff" % (data["name"].lower()),
+ ],
+ }
+ txt = json.dumps(d, indent=4, separators=(",", ": "))
+
+ component_file_path = os.path.join(ROOT_PATH, "component.json")
+ f = open(component_file_path, "w")
+ f.write(txt)
+ f.close()
def generate_composer_json(data):
- print "Generate composer.json"
- d = {
- "name": "driftyco/ionicons",
- "description": "The premium icon font for Ionic Framework.",
- "keywords": [ "fonts", "icon font", "icons", "ionic", "web font"],
- "homepage": "http://ionicons.com/",
- "authors": [
- {
- "name": "Ben Sperry",
- "email": "ben@drifty.com",
- "role": "Designer",
- "homepage": "https://twitter.com/benjsperry"
- },
- {
- "name": "Adam Bradley",
- "email": "adam@drifty.com",
- "role": "Developer",
- "homepage": "https://twitter.com/adamdbradley"
- },
- {
- "name": "Max Lynch",
- "email": "max@drifty.com",
- "role": "Developer",
- "homepage": "https://twitter.com/maxlynch"
- }
- ],
- "extra": {},
- "license": [ "MIT" ]
- }
- txt = json.dumps(d, indent=4, separators=(',', ': '))
-
- composer_file_path = os.path.join(ROOT_PATH, 'composer.json')
- f = open(composer_file_path, 'w')
- f.write(txt)
- f.close()
+ print "Generate composer.json"
+ d = {
+ "name": "driftyco/ionicons",
+ "description": "The premium icon font for Ionic Framework.",
+ "keywords": ["fonts", "icon font", "icons", "ionic", "web font"],
+ "homepage": "http://ionicons.com/",
+ "authors": [
+ {
+ "name": "Ben Sperry",
+ "email": "ben@drifty.com",
+ "role": "Designer",
+ "homepage": "https://twitter.com/benjsperry",
+ },
+ {
+ "name": "Adam Bradley",
+ "email": "adam@drifty.com",
+ "role": "Developer",
+ "homepage": "https://twitter.com/adamdbradley",
+ },
+ {
+ "name": "Max Lynch",
+ "email": "max@drifty.com",
+ "role": "Developer",
+ "homepage": "https://twitter.com/maxlynch",
+ },
+ ],
+ "extra": {},
+ "license": ["MIT"],
+ }
+ txt = json.dumps(d, indent=4, separators=(",", ": "))
+
+ composer_file_path = os.path.join(ROOT_PATH, "composer.json")
+ f = open(composer_file_path, "w")
+ f.write(txt)
+ f.close()
def generate_bower_json(data):
- print "Generate bower.json"
- d = {
- "name": data['name'],
- "version": data['version'],
- "homepage": "https://github.com/driftyco/ionicons",
- "authors": [
- "Ben Sperry
",
- "Adam Bradley ",
- "Max Lynch "
- ],
- "description": "Ionicons - free and beautiful icons from the creators of Ionic Framework",
- "main": [
- "css/%s.css" % (data['name'].lower()),
- "fonts/*"
- ],
- "keywords": [ "fonts", "icon font", "icons", "ionic", "web font"],
- "license": "MIT",
- "ignore": [
- "**/.*",
- "builder",
- "node_modules",
- "bower_components",
- "test",
- "tests"
- ]
- }
- txt = json.dumps(d, indent=4, separators=(',', ': '))
-
- bower_file_path = os.path.join(ROOT_PATH, 'bower.json')
- f = open(bower_file_path, 'w')
- f.write(txt)
- f.close()
+ print "Generate bower.json"
+ d = {
+ "name": data["name"],
+ "version": data["version"],
+ "homepage": "https://github.com/driftyco/ionicons",
+ "authors": [
+ "Ben Sperry ",
+ "Adam Bradley ",
+ "Max Lynch ",
+ ],
+ "description": "Ionicons - free and beautiful icons from the creators of Ionic Framework",
+ "main": ["css/%s.css" % (data["name"].lower()), "fonts/*"],
+ "keywords": ["fonts", "icon font", "icons", "ionic", "web font"],
+ "license": "MIT",
+ "ignore": [
+ "**/.*",
+ "builder",
+ "node_modules",
+ "bower_components",
+ "test",
+ "tests",
+ ],
+ }
+ txt = json.dumps(d, indent=4, separators=(",", ": "))
+
+ bower_file_path = os.path.join(ROOT_PATH, "bower.json")
+ f = open(bower_file_path, "w")
+ f.write(txt)
+ f.close()
def get_build_data():
- build_data_path = os.path.join(BUILDER_PATH, 'build_data.json')
- f = open(build_data_path, 'r')
- data = json.loads(f.read())
- f.close()
- return data
+ build_data_path = os.path.join(BUILDER_PATH, "build_data.json")
+ f = open(build_data_path, "r")
+ data = json.loads(f.read())
+ f.close()
+ return data
if __name__ == "__main__":
- main()
+ main()
diff --git a/static/ionicons-2.0.1/builder/scripts/eotlitetool.py b/static/ionicons-2.0.1/builder/scripts/eotlitetool.py
index d3e253b..1898312 100644
--- a/static/ionicons-2.0.1/builder/scripts/eotlitetool.py
+++ b/static/ionicons-2.0.1/builder/scripts/eotlitetool.py
@@ -42,9 +42,9 @@
# OpenType file structure
# http://www.microsoft.com/typography/otspec/otff.htm
-#
+#
# Types:
-#
+#
# BYTE 8-bit unsigned integer.
# CHAR 8-bit signed integer.
# USHORT 16-bit unsigned integer.
@@ -52,111 +52,111 @@
# ULONG 32-bit unsigned integer.
# Fixed 32-bit signed fixed-point number (16.16)
# LONGDATETIME Date represented in number of seconds since 12:00 midnight, January 1, 1904. The value is represented as a signed 64-bit integer.
-#
+#
# SFNT Header
-#
+#
# Fixed sfnt version // 0x00010000 for version 1.0.
# USHORT numTables // Number of tables.
# USHORT searchRange // (Maximum power of 2 <= numTables) x 16.
# USHORT entrySelector // Log2(maximum power of 2 <= numTables).
# USHORT rangeShift // NumTables x 16-searchRange.
-#
+#
# Table Directory
-#
+#
# ULONG tag // 4-byte identifier.
# ULONG checkSum // CheckSum for this table.
# ULONG offset // Offset from beginning of TrueType font file.
# ULONG length // Length of this table.
-#
+#
# OS/2 Table (Version 4)
-#
+#
# USHORT version // 0x0004
-# SHORT xAvgCharWidth
-# USHORT usWeightClass
-# USHORT usWidthClass
-# USHORT fsType
-# SHORT ySubscriptXSize
-# SHORT ySubscriptYSize
-# SHORT ySubscriptXOffset
-# SHORT ySubscriptYOffset
-# SHORT ySuperscriptXSize
-# SHORT ySuperscriptYSize
-# SHORT ySuperscriptXOffset
-# SHORT ySuperscriptYOffset
-# SHORT yStrikeoutSize
-# SHORT yStrikeoutPosition
-# SHORT sFamilyClass
-# BYTE panose[10]
+# SHORT xAvgCharWidth
+# USHORT usWeightClass
+# USHORT usWidthClass
+# USHORT fsType
+# SHORT ySubscriptXSize
+# SHORT ySubscriptYSize
+# SHORT ySubscriptXOffset
+# SHORT ySubscriptYOffset
+# SHORT ySuperscriptXSize
+# SHORT ySuperscriptYSize
+# SHORT ySuperscriptXOffset
+# SHORT ySuperscriptYOffset
+# SHORT yStrikeoutSize
+# SHORT yStrikeoutPosition
+# SHORT sFamilyClass
+# BYTE panose[10]
# ULONG ulUnicodeRange1 // Bits 0-31
# ULONG ulUnicodeRange2 // Bits 32-63
# ULONG ulUnicodeRange3 // Bits 64-95
# ULONG ulUnicodeRange4 // Bits 96-127
-# CHAR achVendID[4]
-# USHORT fsSelection
-# USHORT usFirstCharIndex
-# USHORT usLastCharIndex
-# SHORT sTypoAscender
-# SHORT sTypoDescender
-# SHORT sTypoLineGap
-# USHORT usWinAscent
-# USHORT usWinDescent
+# CHAR achVendID[4]
+# USHORT fsSelection
+# USHORT usFirstCharIndex
+# USHORT usLastCharIndex
+# SHORT sTypoAscender
+# SHORT sTypoDescender
+# SHORT sTypoLineGap
+# USHORT usWinAscent
+# USHORT usWinDescent
# ULONG ulCodePageRange1 // Bits 0-31
# ULONG ulCodePageRange2 // Bits 32-63
-# SHORT sxHeight
-# SHORT sCapHeight
-# USHORT usDefaultChar
-# USHORT usBreakChar
-# USHORT usMaxContext
-#
-#
+# SHORT sxHeight
+# SHORT sCapHeight
+# USHORT usDefaultChar
+# USHORT usBreakChar
+# USHORT usMaxContext
+#
+#
# The Naming Table is organized as follows:
-#
+#
# [name table header]
# [name records]
# [string data]
-#
+#
# Name Table Header
-#
+#
# USHORT format // Format selector (=0).
# USHORT count // Number of name records.
# USHORT stringOffset // Offset to start of string storage (from start of table).
-#
+#
# Name Record
-#
+#
# USHORT platformID // Platform ID.
# USHORT encodingID // Platform-specific encoding ID.
# USHORT languageID // Language ID.
# USHORT nameID // Name ID.
# USHORT length // String length (in bytes).
# USHORT offset // String offset from start of storage area (in bytes).
-#
+#
# head Table
-#
+#
# Fixed tableVersion // Table version number 0x00010000 for version 1.0.
# Fixed fontRevision // Set by font manufacturer.
# ULONG checkSumAdjustment // To compute: set it to 0, sum the entire font as ULONG, then store 0xB1B0AFBA - sum.
# ULONG magicNumber // Set to 0x5F0F3CF5.
-# USHORT flags
+# USHORT flags
# USHORT unitsPerEm // Valid range is from 16 to 16384. This value should be a power of 2 for fonts that have TrueType outlines.
# LONGDATETIME created // Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer
# LONGDATETIME modified // Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer
# SHORT xMin // For all glyph bounding boxes.
-# SHORT yMin
-# SHORT xMax
-# SHORT yMax
+# SHORT yMin
+# SHORT xMax
+# SHORT yMax
# USHORT macStyle
# USHORT lowestRecPPEM // Smallest readable size in pixels.
# SHORT fontDirectionHint
# SHORT indexToLocFormat // 0 for short offsets, 1 for long.
# SHORT glyphDataFormat // 0 for current format.
-#
-#
-#
+#
+#
+#
# Embedded OpenType (EOT) file format
# http://www.w3.org/Submission/EOT/
-#
+#
# EOT version 0x00020001
-#
+#
# An EOT font consists of a header with the original OpenType font
# appended at the end. Most of the data in the EOT header is simply a
# copy of data from specific tables within the font data. The exceptions
@@ -165,15 +165,15 @@
# used. A null root string implies the font data can be used anywhere.
# The EOT header is in little-endian byte order but the font data remains
# in big-endian order as specified by the OpenType spec.
-#
+#
# Overall structure:
-#
+#
# [EOT header]
# [EOT name records]
# [font data]
-#
+#
# EOT header
-#
+#
# ULONG eotSize // Total structure length in bytes (including string and font data)
# ULONG fontDataSize // Length of the OpenType font (FontData) in bytes
# ULONG version // Version number of this format - 0x00020001
@@ -193,274 +193,318 @@
# ULONG checkSumAdjustment // head Table CheckSumAdjustment
# ULONG reserved[4] // Reserved - must be 0
# USHORT padding1 // Padding - must be 0
-#
+#
# EOT name records
-#
+#
# USHORT FamilyNameSize // Font family name size in bytes
# BYTE FamilyName[FamilyNameSize] // Font family name (name ID = 1), little-endian UTF-16
# USHORT Padding2 // Padding - must be 0
-#
+#
# USHORT StyleNameSize // Style name size in bytes
# BYTE StyleName[StyleNameSize] // Style name (name ID = 2), little-endian UTF-16
# USHORT Padding3 // Padding - must be 0
-#
+#
# USHORT VersionNameSize // Version name size in bytes
# bytes VersionName[VersionNameSize] // Version name (name ID = 5), little-endian UTF-16
# USHORT Padding4 // Padding - must be 0
-#
+#
# USHORT FullNameSize // Full name size in bytes
# BYTE FullName[FullNameSize] // Full name (name ID = 4), little-endian UTF-16
# USHORT Padding5 // Padding - must be 0
-#
+#
# USHORT RootStringSize // Root string size in bytes
# BYTE RootString[RootStringSize] // Root string, little-endian UTF-16
-
import optparse
import struct
+
class FontError(Exception):
"""Error related to font handling"""
+
pass
+
def multichar(str):
- vals = struct.unpack('4B', str[:4])
+ vals = struct.unpack("4B", str[:4])
return (vals[0] << 24) + (vals[1] << 16) + (vals[2] << 8) + vals[3]
+
def multicharval(v):
- return struct.pack('4B', (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
+ return struct.pack(
+ "4B", (v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF
+ )
+
class EOT:
EOT_VERSION = 0x00020001
- EOT_MAGIC_NUMBER = 0x504c
+ EOT_MAGIC_NUMBER = 0x504C
EOT_DEFAULT_CHARSET = 0x01
- EOT_FAMILY_NAME_INDEX = 0 # order of names in variable portion of EOT header
+ EOT_FAMILY_NAME_INDEX = 0 # order of names in variable portion of EOT header
EOT_STYLE_NAME_INDEX = 1
EOT_VERSION_NAME_INDEX = 2
EOT_FULL_NAME_INDEX = 3
EOT_NUM_NAMES = 4
-
- EOT_HEADER_PACK = '<4L10B2BL2H7L18x'
+
+ EOT_HEADER_PACK = "<4L10B2BL2H7L18x"
+
class OpenType:
- SFNT_CFF = multichar('OTTO') # Postscript CFF SFNT version
- SFNT_TRUE = 0x10000 # Standard TrueType version
- SFNT_APPLE = multichar('true') # Apple TrueType version
-
- SFNT_UNPACK = '>I4H'
- TABLE_DIR_UNPACK = '>4I'
-
- TABLE_HEAD = multichar('head') # TrueType table tags
- TABLE_NAME = multichar('name')
- TABLE_OS2 = multichar('OS/2')
- TABLE_GLYF = multichar('glyf')
- TABLE_CFF = multichar('CFF ')
-
+ SFNT_CFF = multichar("OTTO") # Postscript CFF SFNT version
+ SFNT_TRUE = 0x10000 # Standard TrueType version
+ SFNT_APPLE = multichar("true") # Apple TrueType version
+
+ SFNT_UNPACK = ">I4H"
+ TABLE_DIR_UNPACK = ">4I"
+
+ TABLE_HEAD = multichar("head") # TrueType table tags
+ TABLE_NAME = multichar("name")
+ TABLE_OS2 = multichar("OS/2")
+ TABLE_GLYF = multichar("glyf")
+ TABLE_CFF = multichar("CFF ")
+
OS2_FSSELECTION_ITALIC = 0x1
- OS2_UNPACK = '>4xH2xH22x10B4L4xH14x2L'
-
- HEAD_UNPACK = '>8xL'
-
- NAME_RECORD_UNPACK = '>6H'
+ OS2_UNPACK = ">4xH2xH22x10B4L4xH14x2L"
+
+ HEAD_UNPACK = ">8xL"
+
+ NAME_RECORD_UNPACK = ">6H"
NAME_ID_FAMILY = 1
NAME_ID_STYLE = 2
NAME_ID_UNIQUE = 3
NAME_ID_FULL = 4
NAME_ID_VERSION = 5
NAME_ID_POSTSCRIPT = 6
- PLATFORM_ID_UNICODE = 0 # Mac OS uses this typically
+ PLATFORM_ID_UNICODE = 0 # Mac OS uses this typically
PLATFORM_ID_MICROSOFT = 3
- ENCODING_ID_MICROSOFT_UNICODEBMP = 1 # with Microsoft platformID BMP-only Unicode encoding
- LANG_ID_MICROSOFT_EN_US = 0x0409 # with Microsoft platformID EN US lang code
+ ENCODING_ID_MICROSOFT_UNICODEBMP = (
+ 1 # with Microsoft platformID BMP-only Unicode encoding
+ )
+ LANG_ID_MICROSOFT_EN_US = 0x0409 # with Microsoft platformID EN US lang code
+
def eotname(ttf):
- i = ttf.rfind('.')
+ i = ttf.rfind(".")
if i != -1:
ttf = ttf[:i]
- return ttf + '.eotlite'
+ return ttf + ".eotlite"
+
def readfont(f):
- data = open(f, 'rb').read()
+ data = open(f, "rb").read()
return data
+
def get_table_directory(data):
"""read the SFNT header and table directory"""
datalen = len(data)
sfntsize = struct.calcsize(OpenType.SFNT_UNPACK)
if sfntsize > datalen:
- raise FontError, 'truncated font data'
+ raise FontError, "truncated font data"
sfntvers, numTables = struct.unpack(OpenType.SFNT_UNPACK, data[:sfntsize])[:2]
if sfntvers != OpenType.SFNT_CFF and sfntvers != OpenType.SFNT_TRUE:
- raise FontError, 'invalid font type';
-
+ raise FontError, "invalid font type"
+
font = {}
- font['version'] = sfntvers
- font['numTables'] = numTables
-
+ font["version"] = sfntvers
+ font["numTables"] = numTables
+
# create set of offsets, lengths for tables
table_dir_size = struct.calcsize(OpenType.TABLE_DIR_UNPACK)
if sfntsize + table_dir_size * numTables > datalen:
- raise FontError, 'truncated font data, table directory extends past end of data'
+ raise FontError, "truncated font data, table directory extends past end of data"
table_dir = {}
for i in range(0, numTables):
start = sfntsize + i * table_dir_size
end = start + table_dir_size
- tag, check, bongo, dirlen = struct.unpack(OpenType.TABLE_DIR_UNPACK, data[start:end])
- table_dir[tag] = {'offset': bongo, 'length': dirlen, 'checksum': check}
-
- font['tableDir'] = table_dir
-
+ tag, check, bongo, dirlen = struct.unpack(
+ OpenType.TABLE_DIR_UNPACK, data[start:end]
+ )
+ table_dir[tag] = {"offset": bongo, "length": dirlen, "checksum": check}
+
+ font["tableDir"] = table_dir
+
return font
+
def get_name_records(nametable):
"""reads through the name records within name table"""
name = {}
# read the header
headersize = 6
- count, strOffset = struct.unpack('>2H', nametable[2:6])
+ count, strOffset = struct.unpack(">2H", nametable[2:6])
namerecsize = struct.calcsize(OpenType.NAME_RECORD_UNPACK)
if count * namerecsize + headersize > len(nametable):
- raise FontError, 'names exceed size of name table'
- name['count'] = count
- name['strOffset'] = strOffset
-
+ raise FontError, "names exceed size of name table"
+ name["count"] = count
+ name["strOffset"] = strOffset
+
# read through the name records
namerecs = {}
for i in range(0, count):
start = headersize + i * namerecsize
end = start + namerecsize
- platformID, encodingID, languageID, nameID, namelen, offset = struct.unpack(OpenType.NAME_RECORD_UNPACK, nametable[start:end])
- if platformID != OpenType.PLATFORM_ID_MICROSOFT or \
- encodingID != OpenType.ENCODING_ID_MICROSOFT_UNICODEBMP or \
- languageID != OpenType.LANG_ID_MICROSOFT_EN_US:
+ platformID, encodingID, languageID, nameID, namelen, offset = struct.unpack(
+ OpenType.NAME_RECORD_UNPACK, nametable[start:end]
+ )
+ if (
+ platformID != OpenType.PLATFORM_ID_MICROSOFT
+ or encodingID != OpenType.ENCODING_ID_MICROSOFT_UNICODEBMP
+ or languageID != OpenType.LANG_ID_MICROSOFT_EN_US
+ ):
continue
- namerecs[nameID] = {'offset': offset, 'length': namelen}
-
- name['namerecords'] = namerecs
+ namerecs[nameID] = {"offset": offset, "length": namelen}
+
+ name["namerecords"] = namerecs
return name
+
def make_eot_name_headers(fontdata, nameTableDir):
"""extracts names from the name table and generates the names header portion of the EOT header"""
- nameoffset = nameTableDir['offset']
- namelen = nameTableDir['length']
+ nameoffset = nameTableDir["offset"]
+ namelen = nameTableDir["length"]
name = get_name_records(fontdata[nameoffset : nameoffset + namelen])
- namestroffset = name['strOffset']
- namerecs = name['namerecords']
-
- eotnames = (OpenType.NAME_ID_FAMILY, OpenType.NAME_ID_STYLE, OpenType.NAME_ID_VERSION, OpenType.NAME_ID_FULL)
+ namestroffset = name["strOffset"]
+ namerecs = name["namerecords"]
+
+ eotnames = (
+ OpenType.NAME_ID_FAMILY,
+ OpenType.NAME_ID_STYLE,
+ OpenType.NAME_ID_VERSION,
+ OpenType.NAME_ID_FULL,
+ )
nameheaders = []
for nameid in eotnames:
if nameid in namerecs:
namerecord = namerecs[nameid]
- noffset = namerecord['offset']
- nlen = namerecord['length']
- nformat = '%dH' % (nlen / 2) # length is in number of bytes
+ noffset = namerecord["offset"]
+ nlen = namerecord["length"]
+ nformat = "%dH" % (nlen / 2) # length is in number of bytes
start = nameoffset + namestroffset + noffset
end = start + nlen
- nstr = struct.unpack('>' + nformat, fontdata[start:end])
- nameheaders.append(struct.pack('" + nformat, fontdata[start:end])
+ nameheaders.append(struct.pack(" os2Dir['length']:
- raise FontError, 'OS/2 table invalid length'
-
- os2fields = struct.unpack(OpenType.OS2_UNPACK, fontdata[os2offset : os2offset + os2size])
-
+
+ if os2size > os2Dir["length"]:
+ raise FontError, "OS/2 table invalid length"
+
+ os2fields = struct.unpack(
+ OpenType.OS2_UNPACK, fontdata[os2offset : os2offset + os2size]
+ )
+
panose = []
urange = []
codepage = []
-
+
weight, fsType = os2fields[:2]
panose[:10] = os2fields[2:12]
urange[:4] = os2fields[12:16]
fsSelection = os2fields[16]
codepage[:2] = os2fields[17:19]
-
+
italic = fsSelection & OpenType.OS2_FSSELECTION_ITALIC
-
+
# read in values from head table
headDir = tableDir[OpenType.TABLE_HEAD]
- headoffset = headDir['offset']
+ headoffset = headDir["offset"]
headsize = struct.calcsize(OpenType.HEAD_UNPACK)
-
- if headsize > headDir['length']:
- raise FontError, 'head table invalid length'
-
- headfields = struct.unpack(OpenType.HEAD_UNPACK, fontdata[headoffset : headoffset + headsize])
+
+ if headsize > headDir["length"]:
+ raise FontError, "head table invalid length"
+
+ headfields = struct.unpack(
+ OpenType.HEAD_UNPACK, fontdata[headoffset : headoffset + headsize]
+ )
checkSumAdjustment = headfields[0]
-
+
# make name headers
nameheaders = make_eot_name_headers(fontdata, tableDir[OpenType.TABLE_NAME])
rootstring = make_root_string()
-
+
# calculate the total eot size
- eotSize = struct.calcsize(EOT.EOT_HEADER_PACK) + len(nameheaders) + len(rootstring) + fontDataSize
- fixed = struct.pack(EOT.EOT_HEADER_PACK,
- *([eotSize, fontDataSize, version, flags] + panose + [charset, italic] +
- [weight, fsType, magicNumber] + urange + codepage + [checkSumAdjustment]))
-
- return ''.join((fixed, nameheaders, rootstring))
-
-
+ eotSize = (
+ struct.calcsize(EOT.EOT_HEADER_PACK)
+ + len(nameheaders)
+ + len(rootstring)
+ + fontDataSize
+ )
+ fixed = struct.pack(
+ EOT.EOT_HEADER_PACK,
+ *(
+ [eotSize, fontDataSize, version, flags]
+ + panose
+ + [charset, italic]
+ + [weight, fsType, magicNumber]
+ + urange
+ + codepage
+ + [checkSumAdjustment]
+ )
+ )
+
+ return "".join((fixed, nameheaders, rootstring))
+
+
def write_eot_font(eot, header, data):
- open(eot,'wb').write(''.join((header, data)))
+ open(eot, "wb").write("".join((header, data)))
return
+
def main():
# deal with options
p = optparse.OptionParser()
- p.add_option('--output', '-o', default="world")
+ p.add_option("--output", "-o", default="world")
options, args = p.parse_args()
-
+
# iterate over font files
for f in args:
data = readfont(f)
if len(data) == 0:
- print 'Error reading %s' % f
+ print "Error reading %s" % f
else:
eot = eotname(f)
header = make_eot_header(data)
write_eot_font(eot, header, data)
-
-if __name__ == '__main__':
+
+if __name__ == "__main__":
main()
-
-
\ No newline at end of file
diff --git a/static/ionicons-2.0.1/builder/scripts/generate_font.py b/static/ionicons-2.0.1/builder/scripts/generate_font.py
index 8e0bed2..2987942 100755
--- a/static/ionicons-2.0.1/builder/scripts/generate_font.py
+++ b/static/ionicons-2.0.1/builder/scripts/generate_font.py
@@ -11,163 +11,180 @@
import copy
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
-INPUT_SVG_DIR = os.path.join(SCRIPT_PATH, '..', '..', 'src')
-OUTPUT_FONT_DIR = os.path.join(SCRIPT_PATH, '..', '..', 'fonts')
-MANIFEST_PATH = os.path.join(SCRIPT_PATH, '..', 'manifest.json')
-BUILD_DATA_PATH = os.path.join(SCRIPT_PATH, '..', 'build_data.json')
+INPUT_SVG_DIR = os.path.join(SCRIPT_PATH, "..", "..", "src")
+OUTPUT_FONT_DIR = os.path.join(SCRIPT_PATH, "..", "..", "fonts")
+MANIFEST_PATH = os.path.join(SCRIPT_PATH, "..", "manifest.json")
+BUILD_DATA_PATH = os.path.join(SCRIPT_PATH, "..", "build_data.json")
AUTO_WIDTH = True
KERNING = 15
-cp = 0xf100
+cp = 0xF100
m = md5.new()
f = fontforge.font()
-f.encoding = 'UnicodeFull'
+f.encoding = "UnicodeFull"
f.design_size = 16
f.em = 512
f.ascent = 448
f.descent = 64
-manifest_file = open(MANIFEST_PATH, 'r')
+manifest_file = open(MANIFEST_PATH, "r")
manifest_data = json.loads(manifest_file.read())
manifest_file.close()
-print "Load Manifest, Icons: %s" % ( len(manifest_data['icons']) )
+print "Load Manifest, Icons: %s" % (len(manifest_data["icons"]))
build_data = copy.deepcopy(manifest_data)
-build_data['icons'] = []
+build_data["icons"] = []
-font_name = manifest_data['name']
-m.update(font_name + ';')
-m.update(manifest_data['prefix'] + ';')
+font_name = manifest_data["name"]
+m.update(font_name + ";")
+m.update(manifest_data["prefix"] + ";")
for dirname, dirnames, filenames in os.walk(INPUT_SVG_DIR):
- for filename in filenames:
- name, ext = os.path.splitext(filename)
- filePath = os.path.join(dirname, filename)
- size = os.path.getsize(filePath)
-
- if ext in ['.svg', '.eps']:
-
- # see if this file is already in the manifest
- chr_code = None
- for ionicon in manifest_data['icons']:
- if ionicon['name'] == name:
- chr_code = ionicon['code']
- break
-
- if chr_code is None:
- # this is a new src icon
- print 'New Icon: \n - %s' % (name)
-
- while True:
- chr_code = '0x%x' % (cp)
- already_exists = False
- for ionicon in manifest_data['icons']:
- if ionicon.get('code') == chr_code:
- already_exists = True
- cp += 1
- chr_code = '0x%x' % (cp)
- continue
- if not already_exists:
- break
-
- print ' - %s' % chr_code
- manifest_data['icons'].append({
- 'name': name,
- 'code': chr_code
- })
-
- build_data['icons'].append({
- 'name': name,
- 'code': chr_code
- })
-
- if ext in ['.svg']:
- # hack removal of tags
- svgfile = open(filePath, 'r+')
- tmpsvgfile = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
- svgtext = svgfile.read()
- svgfile.seek(0)
-
- # replace the tags with 'nothing'
- svgtext = svgtext.replace('', '')
- svgtext = svgtext.replace('', '')
-
- tmpsvgfile.file.write(svgtext)
-
- svgfile.close()
- tmpsvgfile.file.close()
-
- filePath = tmpsvgfile.name
- # end hack
-
- m.update(name + str(size) + ';')
- glyph = f.createChar( int(chr_code, 16) )
- glyph.importOutlines(filePath)
-
- # if we created a temporary file, let's clean it up
- if tmpsvgfile:
- os.unlink(tmpsvgfile.name)
-
- # set glyph size explicitly or automatically depending on autowidth
- if AUTO_WIDTH:
- glyph.left_side_bearing = glyph.right_side_bearing = 0
- glyph.round()
-
- # resize glyphs if autowidth is enabled
- if AUTO_WIDTH:
- f.autoWidth(0, 0, 512)
-
- fontfile = '%s/ionicons' % (OUTPUT_FONT_DIR)
+ for filename in filenames:
+ name, ext = os.path.splitext(filename)
+ filePath = os.path.join(dirname, filename)
+ size = os.path.getsize(filePath)
+
+ if ext in [".svg", ".eps"]:
+
+ # see if this file is already in the manifest
+ chr_code = None
+ for ionicon in manifest_data["icons"]:
+ if ionicon["name"] == name:
+ chr_code = ionicon["code"]
+ break
+
+ if chr_code is None:
+ # this is a new src icon
+ print "New Icon: \n - %s" % (name)
+
+ while True:
+ chr_code = "0x%x" % (cp)
+ already_exists = False
+ for ionicon in manifest_data["icons"]:
+ if ionicon.get("code") == chr_code:
+ already_exists = True
+ cp += 1
+ chr_code = "0x%x" % (cp)
+ continue
+ if not already_exists:
+ break
+
+ print " - %s" % chr_code
+ manifest_data["icons"].append({"name": name, "code": chr_code})
+
+ build_data["icons"].append({"name": name, "code": chr_code})
+
+ if ext in [".svg"]:
+ # hack removal of tags
+ svgfile = open(filePath, "r+")
+ tmpsvgfile = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
+ svgtext = svgfile.read()
+ svgfile.seek(0)
+
+ # replace the tags with 'nothing'
+ svgtext = svgtext.replace("", "")
+ svgtext = svgtext.replace("", "")
+
+ tmpsvgfile.file.write(svgtext)
+
+ svgfile.close()
+ tmpsvgfile.file.close()
+
+ filePath = tmpsvgfile.name
+ # end hack
+
+ m.update(name + str(size) + ";")
+ glyph = f.createChar(int(chr_code, 16))
+ glyph.importOutlines(filePath)
+
+ # if we created a temporary file, let's clean it up
+ if tmpsvgfile:
+ os.unlink(tmpsvgfile.name)
+
+ # set glyph size explicitly or automatically depending on autowidth
+ if AUTO_WIDTH:
+ glyph.left_side_bearing = glyph.right_side_bearing = 0
+ glyph.round()
+
+ # resize glyphs if autowidth is enabled
+ if AUTO_WIDTH:
+ f.autoWidth(0, 0, 512)
+
+ fontfile = "%s/ionicons" % (OUTPUT_FONT_DIR)
build_hash = m.hexdigest()
-if build_hash == manifest_data.get('build_hash'):
- print "Source files unchanged, did not rebuild fonts"
+if build_hash == manifest_data.get("build_hash"):
+ print "Source files unchanged, did not rebuild fonts"
else:
- manifest_data['build_hash'] = build_hash
-
- f.fontname = font_name
- f.familyname = font_name
- f.fullname = font_name
- f.generate(fontfile + '.ttf')
- f.generate(fontfile + '.svg')
-
- # Fix SVG header for webkit
- # from: https://github.com/fontello/font-builder/blob/master/bin/fontconvert.py
- svgfile = open(fontfile + '.svg', 'r+')
- svgtext = svgfile.read()
- svgfile.seek(0)
- svgfile.write(svgtext.replace('''