Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61104505
checker_handler.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 4, 13:54
Size
2 KB
Mime Type
text/x-python
Expires
Mon, May 6, 13:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17465794
Attached To
rNIETZSCHEPYTHON nietzsche-python
checker_handler.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This program can be used to handle the manual check status of xml files.
"""
# Copyright (C) University of Basel 2021 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
from
datetime
import
datetime
import
lxml.etree
as
ET
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.page
import
Page
__author__
=
"Christian Steiner"
__maintainer__
=
__author__
__copyright__
=
'University of Basel'
__email__
=
"christian.steiner@unibas.ch"
__status__
=
"Development"
__license__
=
"GPL v3"
__version__
=
"0.0.1"
UNITTESTING
=
False
class
CheckerHandler
:
"""This class can be used to handle the manual check status of xml files.
"""
XML_TAG
=
'manual-checks'
CHECKS
=
[
'transkription positions'
,
'line assignement'
,
'hyphenation'
,
'boxes/correction history'
,
\
'mark foreign hands'
,
'deletion paths'
,
'faksimile/transkription word correspondance'
]
def
__init__
(
self
,
page
:
Page
):
self
.
page
=
page
def
get_todos
(
self
)
->
list
:
"""Return todos as a list
"""
todos
=
self
.
page
.
page_tree
.
xpath
(
f
'//metadata/{self.XML_TAG}/todo/text()'
)
if
len
(
todos
)
>
0
\
or
len
(
self
.
page
.
page_tree
.
xpath
(
f
'//metadata/{self.XML_TAG}/done/text()'
))
==
len
(
self
.
CHECKS
):
return
todos
return
self
.
CHECKS
def
set_task_done
(
self
,
task
:
str
):
"""Set task as done.
"""
date
=
datetime
.
now
()
.
strftime
(
'%Y-%m-
%d
%H:%M:%S'
)
checks
=
self
.
page
.
page_tree
.
xpath
(
f
'//metadata/{self.XML_TAG}'
)[
0
]
\
if
len
(
self
.
page
.
page_tree
.
xpath
(
f
'//metadata/{self.XML_TAG}'
))
>
0
\
else
ET
.
SubElement
(
self
.
page
.
page_tree
.
xpath
(
'//metadata'
)[
0
],
self
.
XML_TAG
)
if
len
(
checks
.
xpath
(
'./todo'
))
==
0
:
for
todo
in
self
.
CHECKS
:
if
todo
!=
task
:
ET
.
SubElement
(
checks
,
'todo'
)
.
text
=
todo
else
:
ET
.
SubElement
(
checks
,
'done'
,
attrib
=
{
'date'
:
date
})
.
text
=
task
elif
len
(
checks
.
xpath
(
f
'./todo[text()="{task}"]'
))
>
0
:
done
=
checks
.
xpath
(
f
'./todo[text()="{task}"]'
)[
0
]
done
.
tag
=
'done'
done
.
set
(
'date'
,
date
)
else
:
ET
.
SubElement
(
checks
,
'done'
,
attrib
=
{
'date'
:
date
})
.
text
=
task
Event Timeline
Log In to Comment