Skip to content

Commit

Permalink
generateDS PAGE API: allow custom filenames in _add_method
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Jun 6, 2020
1 parent 6b29645 commit 93f8a00
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions ocrd_models/ocrd_models/ocrd_page_generateds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

#
# Generated Fri May 29 23:29:23 2020 by generateDS.py version 2.35.20.
# Generated Sat Jun 6 14:44:44 2020 by generateDS.py version 2.35.20.
# Python 3.6.9 (default, Apr 18 2020, 01:56:04) [GCC 8.4.0]
#
# Command line options:
Expand All @@ -16,7 +16,7 @@
# repo/assets/data/schema/data/2019.xsd
#
# Command line:
# /home/kba/ocrd_all/venv/bin/generateDS -f --root-element="PcGts" -o "ocrd_models/ocrd_models/ocrd_page_generateds.py" --disable-generatedssuper-lookup --user-methods="ocrd_models/ocrd_page_user_methods.py" repo/assets/data/schema/data/2019.xsd
# /home/kba/env/py3-disht/bin/generateDS -f --root-element="PcGts" -o "ocrd_models/ocrd_models/ocrd_page_generateds.py" --disable-generatedssuper-lookup --user-methods="ocrd_models/ocrd_page_user_methods.py" repo/assets/data/schema/data/2019.xsd
#
# Current working directory (os.getcwd()):
# core
Expand Down Expand Up @@ -5461,6 +5461,9 @@ def clear_AllIndexed(self):
def extend_AllIndexed(self, elements, validate_continuity=False):
"""
Add all elements in list ``elements``, respecting ``@index`` order.
With ``validate_continuity``, check that all new elements come after all old elements
(or raise an exception).
Otherwise, ensure this condition silently (by increasing ``@index`` accordingly).
"""
if not isinstance(elements, list):
elements = [elements]
Expand All @@ -5483,7 +5486,6 @@ def extend_AllIndexed(self, elements, validate_continuity=False):
elif isinstance(element, UnorderedGroupIndexedType): # pylint: disable=undefined-variable
self.add_UnorderedGroupIndexed(element)
return self.get_AllIndexed()

# pylint: disable=line-too-long,invalid-name,missing-module-docstring
def sort_AllIndexed(self, validate_uniqueness=True):
"""
Expand Down Expand Up @@ -6307,6 +6309,9 @@ def clear_AllIndexed(self):
def extend_AllIndexed(self, elements, validate_continuity=False):
"""
Add all elements in list ``elements``, respecting ``@index`` order.
With ``validate_continuity``, check that all new elements come after all old elements
(or raise an exception).
Otherwise, ensure this condition silently (by increasing ``@index`` accordingly).
"""
if not isinstance(elements, list):
elements = [elements]
Expand All @@ -6329,7 +6334,6 @@ def extend_AllIndexed(self, elements, validate_continuity=False):
elif isinstance(element, UnorderedGroupIndexedType): # pylint: disable=undefined-variable
self.add_UnorderedGroupIndexed(element)
return self.get_AllIndexed()

# pylint: disable=line-too-long,invalid-name,missing-module-docstring
def sort_AllIndexed(self, validate_uniqueness=True):
"""
Expand Down
8 changes: 5 additions & 3 deletions ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def show(self):
# generated superclass file and also section "User Methods" in
# the documentation, as well as the examples below.

def _add_method(class_re, method_name):
def _add_method(class_re, method_name, file_name=None):
"""
Loads a file ./ocrd_page_user_methods/{{ method_name }}.py and defines a MethodSpec applying to class_re
"""
source = []
with codecs.open(join(dirname(__file__), 'ocrd_page_user_methods', '%s.py' % method_name)) as f:
if not file_name:
file_name = method_name
with codecs.open(join(dirname(__file__), 'ocrd_page_user_methods', '%s.py' % file_name)) as f:
for line in f.readlines():
source.append(' %s' % line if line else line)
return MethodSpec(name=method_name, class_names=class_re, source=''.join(source))
Expand All @@ -102,7 +104,7 @@ def _add_method(class_re, method_name):
_add_method(r'^(OrderedGroupType|OrderedGroupIndexedType)$', 'clear_AllIndexed'),
_add_method(r'^(OrderedGroupType|OrderedGroupIndexedType)$', 'extend_AllIndexed'),
_add_method(r'^(OrderedGroupType|OrderedGroupIndexedType)$', 'sort_AllIndexed'),
_add_method(r'^(OrderedGroupType|OrderedGroupIndexedType)$', 'exportChildren'),
_add_method(r'^(OrderedGroupType|OrderedGroupIndexedType)$', 'exportChildren', 'exportChildren_GroupType'),
_add_method(r'^(UnorderedGroupType|UnorderedGroupIndexedType)$', 'get_UnorderedGroupChildren'),
_add_method(r'^(PageType)$', 'get_AllRegions'),
)
Expand Down

0 comments on commit 93f8a00

Please sign in to comment.