Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Textgrid Repository WebDAV Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DARIAH-DE
TextGridRep
Textgrid Repository WebDAV Server
Commits
44cf94a2
Verified
Commit
44cf94a2
authored
3 years ago
by
Stefan Hynek
Browse files
Options
Downloads
Patches
Plain Diff
refactor(named_dav_provider): format, lint, add comments
parent
005abd2e
No related branches found
No related tags found
1 merge request
!14
Resolve "Show titles and format in repdav listing"
Pipeline
#278346
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/repdav/textgrid_named_dav_provider.py
+36
-17
36 additions, 17 deletions
src/repdav/textgrid_named_dav_provider.py
with
36 additions
and
17 deletions
src/repdav/textgrid_named_dav_provider.py
+
36
−
17
View file @
44cf94a2
...
...
@@ -10,10 +10,13 @@ from tgclients.auth import TextgridAuth
from
wsgidav.util
import
join_uri
from
repdav.stream_tools
import
FileLikeQueue
from
repdav.textgrid_dav_provider
import
(
TextgridAggregation
,
TextgridProject
,
TextgridResource
,
TextgridResourceProvider
,
TextgridRoot
)
from
repdav.textgrid_dav_provider
import
(
TextgridAggregation
,
TextgridProject
,
TextgridResource
,
TextgridResourceProvider
,
TextgridRoot
,
)
_logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -42,6 +45,7 @@ class TextgridNamedRoot(TextgridRoot):
"""
def
__init__
(
self
,
path
,
environ
):
# TODO: do not overwrite but move to parent class
super
().
__init__
(
path
,
environ
)
config
=
TextgridConfig
()
self
.
_auth
=
TextgridAuth
(
config
)
...
...
@@ -50,7 +54,9 @@ class TextgridNamedRoot(TextgridRoot):
_logger
.
debug
(
"
Called TextgridNamedRoot.get_member_names(self).
"
)
projects
=
[]
for
project
in
tuple
(
self
.
_auth
.
list_assigned_projects
(
self
.
_sid
)):
projects
.
append
(
self
.
_auth
.
get_project_description
(
project
).
name
+
'
[
'
+
project
+
'
]
'
)
projects
.
append
(
self
.
_auth
.
get_project_description
(
project
).
name
+
"
[
"
+
project
+
"
]
"
)
_logger
.
debug
(
"
MY PROJECTS: %s
"
,
projects
)
return
projects
...
...
@@ -58,6 +64,7 @@ class TextgridNamedRoot(TextgridRoot):
_logger
.
debug
(
"
Called TextgridRoot.get_member(self, %s).
"
,
name
)
return
TextgridNamedProject
(
join_uri
(
self
.
path
,
name
),
self
.
environ
)
class
TextgridNamedProject
(
TextgridProject
):
def
__init__
(
self
,
path
,
environ
):
_logger
.
debug
(
"
Called TextgridNamedProject.__init__(self, %s, environ).
"
,
path
)
...
...
@@ -74,7 +81,7 @@ class TextgridNamedProject(TextgridProject):
#
# path resolution has to be rewritten before we can work with resource titles
name
=
self
.
path
.
split
(
"
/
"
)[
-
1
]
project_id
=
name
[
name
.
rfind
(
'
[
'
)
+
1
:
name
.
rfind
(
'
]
'
)]
project_id
=
name
[
name
.
rfind
(
"
[
"
)
+
1
:
name
.
rfind
(
"
]
"
)]
response
=
self
.
_tgsearch
.
list_project_root
(
project_id
,
self
.
_sid
)
names
=
[]
for
result
in
response
.
result
:
...
...
@@ -83,7 +90,7 @@ class TextgridNamedProject(TextgridProject):
def
get_member
(
self
,
name
):
_logger
.
debug
(
"
Called TextgridNamedProject.get_member(self, %s).
"
,
name
)
tguri
=
'
textgrid:
'
+
self
.
_tgmeta
.
id_from_filename
(
name
)
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
name
)
response
=
self
.
_tgsearch
.
info
(
tguri
,
self
.
_sid
)
info
=
{
name
:
{
...
...
@@ -94,8 +101,13 @@ class TextgridNamedProject(TextgridProject):
}
_logger
.
info
(
"
INFO: %s
"
,
info
)
if
"
aggregation
"
in
info
[
name
][
"
format
"
]:
return
TextgridNamedAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
class
TextgridNamedAggregation
(
TextgridAggregation
):
def
__init__
(
self
,
path
,
environ
,
info
,
tgmeta
):
...
...
@@ -107,7 +119,7 @@ class TextgridNamedAggregation(TextgridAggregation):
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridNamedAggregation.get_member_names(self).
"
)
tguri
=
'
textgrid:
'
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
response
=
self
.
_tgsearch
.
list_aggregation
(
tguri
,
self
.
_sid
)
names
=
[]
for
result
in
response
.
result
:
...
...
@@ -116,7 +128,7 @@ class TextgridNamedAggregation(TextgridAggregation):
def
get_member
(
self
,
name
):
_logger
.
debug
(
"
Called TextgridNamedAggregation.get_member(self, %s).
"
,
name
)
tguri
=
'
textgrid:
'
+
self
.
_tgmeta
.
id_from_filename
(
name
)
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
name
)
response
=
self
.
_tgsearch
.
info
(
tguri
,
self
.
_sid
)
info
=
{
name
:
{
...
...
@@ -127,8 +139,13 @@ class TextgridNamedAggregation(TextgridAggregation):
}
_logger
.
info
(
"
INFO: %s
"
,
info
)
if
"
aggregation
"
in
info
[
name
][
"
format
"
]:
return
TextgridNamedAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
return
TextgridNamedResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
,
self
.
_tgmeta
)
class
TextgridNamedResource
(
TextgridResource
):
"""
Non-Aggregation resources.
"""
...
...
@@ -141,10 +158,12 @@ class TextgridNamedResource(TextgridResource):
self
.
_crud
=
TextgridCRUD
(
config
.
crud
)
def
get_content
(
self
):
_logger
.
debug
(
"
Called TextgridNamedResource.get_content(self) with path:
"
,
self
.
path
)
tguri
=
'
textgrid:
'
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
_logger
.
debug
(
"
Called TextgridNamedResource.get_content(self) with path: %s
"
,
self
.
path
)
# TODO: make tguri (super!) class member
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
_logger
.
debug
(
"
crud-read:
"
+
tguri
)
return
io
.
BytesIO
(
self
.
_crud
.
read_data
(
tguri
,
self
.
_sid
).
content
)
def
begin_write
(
self
,
content_type
=
None
):
...
...
@@ -153,7 +172,7 @@ class TextgridNamedResource(TextgridResource):
)
queue
=
FileLikeQueue
(
int
(
self
.
_size
))
tguri
=
'
textgrid:
'
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
metadata
=
self
.
_crud
.
read_metadata
(
tguri
,
self
.
_sid
).
content
def
worker
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment