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
bd80a81b
Verified
Commit
bd80a81b
authored
3 years ago
by
Stefan Hynek
Browse files
Options
Downloads
Patches
Plain Diff
feat(dav_provider): provide access to Textgrid projects, aggregations and resources
parent
61ce9f7a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/repdav/textgrid_dav_provider.py
+165
-29
165 additions, 29 deletions
src/repdav/textgrid_dav_provider.py
with
165 additions
and
29 deletions
src/repdav/textgrid_dav_provider.py
+
165
−
29
View file @
bd80a81b
"""
The DAV resource provider and its resources.
"""
import
io
import
logging
from
wsgidav.dav_provider
import
DAVCollection
,
DAVNonCollection
,
DAVProvider
from
wsgidav.util
import
join_uri
from
wsgidav.util
import
join_uri
,
pop_path
from
.tgapi
import
TextgridAuth
from
.tgapi
import
TextgridAuth
,
TextgridCRUD
,
TextgridSearch
_logger
=
logging
.
getLogger
(
__name__
)
class
TextgridRootCollection
(
DAVCollection
):
"""
top level collection that incorporates so called
"
projects
"
# TODO think about caching with the session ID as key
class
TextgridRoot
(
DAVCollection
):
"""
Top level collection that incorporates Textgrid projects.
t
his is implemented as READ-ONLY as project may not be created with webDAV
T
his is implemented as READ-ONLY as project
s
may not be created with webDAV
.
"""
def
__init__
(
self
,
environ
):
DAVCollection
.
__init__
(
self
,
"
/
"
,
environ
)
def
__init__
(
self
,
path
,
environ
):
DAVCollection
.
__init__
(
self
,
path
,
environ
)
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
_logger
.
debug
(
"
MY SID: %s
"
,
self
.
_sid
)
self
.
_tg_auth
=
TextgridAuth
()
self
.
_projects
=
tuple
(
self
.
_tg_auth
.
assigned_projects
(
self
.
_sid
))
_logger
.
debug
(
"
MY PROJECTS: %s
"
,
self
.
_projects
)
def
get_display_info
(
self
):
return
{
"
type
"
:
"
Textgrid root collection
"
}
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called get_member_names(self).
"
)
return
self
.
_projects
_logger
.
debug
(
"
Called TextgridRoot.get_member_names(self).
"
)
projects
=
tuple
(
TextgridAuth
().
assigned_projects
(
self
.
_sid
))
_logger
.
debug
(
"
MY PROJECTS: %s
"
,
projects
)
return
projects
def
get_member
(
self
,
name
):
_logger
.
debug
(
"
Called get_member(self, name).
"
)
if
name
in
self
.
_projects
:
return
TextgridCollection
(
join_uri
(
self
.
path
,
name
),
self
.
environ
)
return
None
class
TextgridCollection
(
DAVCollection
):
_logger
.
debug
(
"
Called TextgridRoot.get_member(self, %s).
"
,
name
)
return
TextgridProject
(
join_uri
(
self
.
path
,
name
),
self
.
environ
)
# temporary override for debugging
def
resolve
(
self
,
script_name
,
path_info
):
"""
Return a _DAVResource object for the path (None, if not found).
`path_info`: is a URL relative to this object.
"""
_logger
.
debug
(
"
Called TextgridRoot.resolve(self, %s, %s).
"
,
script_name
,
path_info
)
if
path_info
in
(
""
,
"
/
"
):
return
self
assert
path_info
.
startswith
(
"
/
"
)
name
,
rest
=
pop_path
(
path_info
)
res
=
self
.
get_member
(
name
)
_logger
.
debug
(
"
TextgridRoot_NAME: %s, REST: %s, RES: %s
"
,
name
,
rest
,
res
)
if
res
is
None
or
rest
in
(
""
,
"
/
"
):
return
res
_logger
.
debug
(
"
RES: %s
"
,
res
)
return
res
.
resolve
(
join_uri
(
script_name
,
name
),
rest
)
class
TextgridProject
(
DAVCollection
):
def
__init__
(
self
,
path
,
environ
):
_logger
.
debug
(
"
Called TextgridProject.__init__(self, %s, environ).
"
,
path
)
DAVCollection
.
__init__
(
self
,
path
,
environ
)
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
def
create_empty_resource
(
self
,
name
):
pass
...
...
@@ -43,28 +71,137 @@ class TextgridCollection(DAVCollection):
def
create_collection
(
self
,
name
):
pass
def
get_display_info
(
self
):
return
{
"
type
"
:
"
Textgrid project
"
}
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridProject.get_member_names(self).
"
)
# names = []
# the item keys are textgrid uris but we want the resource titles only
# for _, member_dict in self._resources.items():
# names.append(member_dict.get("title"))
# return names
#
# path resolution has to be rewritten before we can work with resource titles
resources
=
TextgridSearch
().
get_project_contents
(
self
.
_sid
,
self
.
path
.
split
(
"
/
"
)[
-
1
])
_logger
.
debug
(
"
RESOURCES: %s
"
,
resources
)
return
resources
.
keys
()
def
get_member
(
self
,
name
):
_logger
.
debug
(
"
Called TextgridProject.get_member(self, %s).
"
,
name
)
info
=
TextgridSearch
().
info
(
self
.
_sid
,
name
)
_logger
.
info
(
"
INFO: %s
"
,
info
)
if
"
aggregation
"
in
info
[
name
][
"
format
"
]:
return
TextgridAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
)
return
TextgridResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
)
def
delete
(
self
):
pass
def
copy_move_single
(
self
,
dest_path
,
is_move
):
pass
# temporary override for debugging
def
resolve
(
self
,
script_name
,
path_info
):
"""
Return a _DAVResource object for the path (None, if not found).
`path_info`: is a URL relative to this object.
"""
_logger
.
debug
(
"
Called TextgridProject.resolve(self, %s, %s).
"
,
script_name
,
path_info
)
if
path_info
in
(
""
,
"
/
"
):
return
self
assert
path_info
.
startswith
(
"
/
"
)
name
,
rest
=
pop_path
(
path_info
)
res
=
self
.
get_member
(
name
)
_logger
.
debug
(
"
TextgridProject_NAME: %s, REST: %s, RES: %s
"
,
name
,
rest
,
res
)
if
res
is
None
or
rest
in
(
""
,
"
/
"
):
return
res
return
res
.
resolve
(
join_uri
(
script_name
,
name
),
rest
)
# TODO: merge TextgridProject with TextgridAggregation and/or derive from a common base class.
class
TextgridAggregation
(
DAVCollection
):
def
__init__
(
self
,
path
,
environ
,
info
):
_logger
.
debug
(
"
Called TextgridAggregation.__init__(self, %s, environ).
"
,
path
)
DAVCollection
.
__init__
(
self
,
path
,
environ
)
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
self
.
_info
=
info
def
create_empty_resource
(
self
,
name
):
pass
def
create_collection
(
self
,
name
):
pass
def
get_display_info
(
self
):
return
{
"
type
"
:
"
Textgrid aggregation
"
}
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridAggregation.get_member_names(self).
"
)
resources
=
TextgridSearch
().
get_aggregation_contents
(
self
.
_sid
,
self
.
path
.
split
(
"
/
"
)[
-
1
])
#_logger.debug("RESOURCES: %s", resources)
return
resources
.
keys
()
def
get_member
(
self
,
name
):
_logger
.
debug
(
"
Called TextgridAggregation.get_member(self, %s).
"
,
name
)
info
=
TextgridSearch
().
info
(
self
.
_sid
,
name
)
_logger
.
info
(
"
INFO: %s
"
,
info
)
if
"
aggregation
"
in
info
[
name
][
"
format
"
]:
return
TextgridAggregation
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
)
return
TextgridResource
(
join_uri
(
self
.
path
,
name
),
self
.
environ
,
info
)
def
delete
(
self
):
pass
def
copy_move_single
(
self
,
dest_path
,
is_move
):
pass
# temporary override for debugging
def
resolve
(
self
,
script_name
,
path_info
):
"""
Return a _DAVResource object for the path (None, if not found).
`path_info`: is a URL relative to this object.
"""
_logger
.
debug
(
"
Called TextgridAggregation.resolve(self, %s, %s).
"
,
script_name
,
path_info
)
if
path_info
in
(
""
,
"
/
"
):
return
self
assert
path_info
.
startswith
(
"
/
"
)
name
,
rest
=
pop_path
(
path_info
)
res
=
self
.
get_member
(
name
)
_logger
.
debug
(
"
TextgridAggregation_NAME: %s, REST: %s, RES: %s
"
,
name
,
rest
,
res
)
if
res
is
None
or
rest
in
(
""
,
"
/
"
):
return
res
return
res
.
resolve
(
join_uri
(
script_name
,
name
),
rest
)
class
TextgridResource
(
DAVNonCollection
):
def
__init__
(
self
,
path
,
environ
):
"""
Non-Aggregation resources.
"""
def
__init__
(
self
,
path
,
environ
,
info
):
_logger
.
debug
(
"
Called TextgridResource.__init__(self, %s, environ).
"
,
path
)
DAVNonCollection
.
__init__
(
self
,
path
,
environ
)
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
self
.
_info
=
info
def
get_content_length
(
self
):
pass
_logger
.
debug
(
"
Called TextgridResource.get_content_length(self).
"
)
# return TextgridCRUD().get_metadata(self._sid, self.path.split("/")[-1])["content-length"]
return
self
.
_info
[
self
.
name
][
"
extent
"
]
def
get_content_type
(
self
):
pass
_logger
.
debug
(
"
Called TextgridResource.get_content_type(self).
"
)
# return TextgridCRUD().get_metadata(self._sid, self.path.split("/")[-1])["content-type"]
return
self
.
_info
[
self
.
name
][
"
format
"
]
def
get_content
(
self
):
pass
return
io
.
BytesIO
(
TextgridCRUD
().
get_data
(
self
.
_sid
,
self
.
path
.
split
(
"
/
"
)[
-
1
]))
def
begin_write
(
self
,
content_type
=
None
):
pass
...
...
@@ -74,17 +211,16 @@ class TextgridResource(DAVNonCollection):
# TextgridResourceProvider
# ============================================================================
class
TextgridResourceProvider
(
DAVProvider
):
"""
DAV provider that serves Textgrid resources
"""
DAV provider that serves Textgrid resources.
"""
def
__init__
(
self
):
super
(
TextgridResourceProvider
,
self
).
__init__
()
def
get_resource_inst
(
self
,
path
,
environ
):
_logger
.
debug
(
"
PATH: %s
"
,
path
)
_logger
.
debug
(
"
ENVIRON: %s
"
,
environ
)
_logger
.
debug
(
"
Called TextgridResourceProvider.get_resource_inst(self, %s, %s).
"
,
path
,
environ
)
self
.
_count_get_resource_inst
+=
1
root
=
TextgridRoot
Collection
(
environ
)
root
=
TextgridRoot
(
"
/
"
,
environ
)
# an instance of _DAVResource (i.e. either DAVCollection or DAVNonCollection)
return
root
.
resolve
(
""
,
path
)
return
root
.
resolve
(
"
/
"
,
path
)
This diff is collapsed.
Click to expand it.
Stefan Hynek
@hynek
mentioned in commit
eab3502a
·
3 years ago
mentioned in commit
eab3502a
mentioned in commit eab3502a1317d3865691e0d79c2f72e0ccd8e341
Toggle commit list
Stefan Hynek
@hynek
mentioned in commit
61644a05
·
3 years ago
mentioned in commit
61644a05
mentioned in commit 61644a0511ab3ae6a939d6d3d42107c87ed6072c
Toggle commit list
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