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

Generateds gdscollector #576

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ generate-page: repo/assets
-f \
--root-element='PcGts' \
-o $(GDS_PAGE) \
--disable-generatedssuper-lookup \
--export="write etree validate" \
--user-methods=$(GDS_PAGE_USER) \
ocrd_validators/ocrd_validators/page.xsd
# hack to prevent #451: enum keys will be strings
sed -i 's/(Enum):$$/(str, Enum):/' $(GDS_PAGE)
# hack to ensure output has pc: prefix
@#sed -i "s/namespaceprefix_=''/namespaceprefix_='pc:'/" $(GDS_PAGE)
sed -i 's/_nsprefix_ = None/_nsprefix_ = "pc"/' $(GDS_PAGE)
# hack to ensure child nodes also have pc: prefix...
sed -i 's/.*_nsprefix_ = child_.prefix$$//' $(GDS_PAGE)
#
# hack to replace parse, parseString and error collection logic
sed -i \
-e '/def parse(/,/return rootObj/ d' \
-e '/def parseString(/,/return rootObj/ d' \
$(GDS_PAGE)
cat ocrd_models/ocrd_page_parse.py >> $(GDS_PAGE)
sed -i 's,from generatedscollector import,from .generatedscollector import,' $(GDS_PAGE)


#
# Repos
Expand Down
31 changes: 31 additions & 0 deletions ocrd_models/ocrd_models/generatedscollector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from .report import ValidationReport

class OcrdGdsCollector(ValidationReport):

def __init__(self, filename=None, messages=None):
super().__init__()
self.filename = filename
if messages is None:
self.warnings = []
else:
self.warnings = messages

def add_message(self, msg):
self.add_warning(msg)

def get_messages(self):
return self.warnings

def clear_messages(self):
self.warnings = []

def print_messages(self):
for msg in self.warnings:
print("Warning: {}".format(msg))

def write_messages(self, outstream):
for msg in self.warnings:
outstream.write("Warning: {}\n".format(msg))

class GdsCollector(OcrdGdsCollector):
pass
Loading