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
5bef02de
Verified
Commit
5bef02de
authored
3 years ago
by
Ubbo Veentjer
Browse files
Options
Downloads
Patches
Plain Diff
refactor: refactor dav providers to duplicate less code
parent
a1fac5fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!17
Resolve "refactor dav and named_dav providers to duplicate less code"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/repdav/textgrid_dav_provider.py
+8
-8
8 additions, 8 deletions
src/repdav/textgrid_dav_provider.py
src/repdav/textgrid_named_dav_provider.py
+4
-41
4 additions, 41 deletions
src/repdav/textgrid_named_dav_provider.py
with
12 additions
and
49 deletions
src/repdav/textgrid_dav_provider.py
+
8
−
8
View file @
5bef02de
...
@@ -172,6 +172,7 @@ class TextgridAggregation(DAVCollection):
...
@@ -172,6 +172,7 @@ class TextgridAggregation(DAVCollection):
self
.
_info
=
info
self
.
_info
=
info
self
.
_tgconfig
=
TextgridConfig
()
self
.
_tgconfig
=
TextgridConfig
()
self
.
_tgsearch
=
TextgridSearch
(
self
.
_tgconfig
.
search
)
self
.
_tgsearch
=
TextgridSearch
(
self
.
_tgconfig
.
search
)
self
.
_tguri
=
self
.
path
.
split
(
"
/
"
)[
-
1
]
def
create_empty_resource
(
self
,
name
):
def
create_empty_resource
(
self
,
name
):
pass
pass
...
@@ -184,7 +185,7 @@ class TextgridAggregation(DAVCollection):
...
@@ -184,7 +185,7 @@ class TextgridAggregation(DAVCollection):
def
get_member_names
(
self
):
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridAggregation.get_member_names(self).
"
)
_logger
.
debug
(
"
Called TextgridAggregation.get_member_names(self).
"
)
response
=
self
.
_tgsearch
.
list_aggregation
(
self
.
path
.
split
(
"
/
"
)[
-
1
]
,
self
.
_sid
)
response
=
self
.
_tgsearch
.
list_aggregation
(
self
.
_tguri
,
self
.
_sid
)
names
=
[]
names
=
[]
for
result
in
response
.
result
:
for
result
in
response
.
result
:
names
.
append
(
result
.
object_value
.
generic
.
generated
.
textgrid_uri
.
value
)
names
.
append
(
result
.
object_value
.
generic
.
generated
.
textgrid_uri
.
value
)
...
@@ -252,8 +253,11 @@ class TextgridResource(DAVNonCollection):
...
@@ -252,8 +253,11 @@ class TextgridResource(DAVNonCollection):
DAVNonCollection
.
__init__
(
self
,
path
,
environ
)
DAVNonCollection
.
__init__
(
self
,
path
,
environ
)
self
.
_size
=
environ
.
get
(
"
CONTENT_LENGTH
"
)
self
.
_size
=
environ
.
get
(
"
CONTENT_LENGTH
"
)
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
self
.
_sid
=
environ
[
"
wsgidav.auth.user_name
"
]
self
.
_tguri
=
self
.
path
.
split
(
"
/
"
)[
-
1
]
self
.
_info
=
info
self
.
_info
=
info
self
.
upload_thread
=
None
self
.
upload_thread
=
None
config
=
TextgridConfig
()
self
.
_crud
=
TextgridCRUD
(
config
.
crud
)
def
get_content_length
(
self
):
def
get_content_length
(
self
):
_logger
.
debug
(
"
Called TextgridResource.get_content_length(self).
"
)
_logger
.
debug
(
"
Called TextgridResource.get_content_length(self).
"
)
...
@@ -265,9 +269,7 @@ class TextgridResource(DAVNonCollection):
...
@@ -265,9 +269,7 @@ class TextgridResource(DAVNonCollection):
def
get_content
(
self
):
def
get_content
(
self
):
_logger
.
debug
(
"
Called TextgridResource.get_content(self) with path: %s
"
,
self
.
path
)
_logger
.
debug
(
"
Called TextgridResource.get_content(self) with path: %s
"
,
self
.
path
)
config
=
TextgridConfig
()
return
io
.
BytesIO
(
self
.
_crud
.
read_data
(
self
.
_tguri
,
self
.
_sid
).
content
)
crud
=
TextgridCRUD
(
config
.
crud
)
return
io
.
BytesIO
(
crud
.
read_data
(
self
.
path
.
split
(
"
/
"
)[
-
1
],
self
.
_sid
).
content
)
def
get_content_title
(
self
):
def
get_content_title
(
self
):
_logger
.
debug
(
"
Called TextgridResource.get_content_title(self).
"
)
_logger
.
debug
(
"
Called TextgridResource.get_content_title(self).
"
)
...
@@ -279,13 +281,11 @@ class TextgridResource(DAVNonCollection):
...
@@ -279,13 +281,11 @@ class TextgridResource(DAVNonCollection):
)
)
queue
=
FileLikeQueue
(
int
(
self
.
_size
))
queue
=
FileLikeQueue
(
int
(
self
.
_size
))
config
=
TextgridConfig
()
metadata
=
self
.
_crud
.
read_metadata
(
self
.
_tguri
,
self
.
_sid
).
content
crud
=
TextgridCRUD
(
config
.
crud
)
metadata
=
crud
.
read_metadata
(
self
.
path
.
split
(
"
/
"
)[
-
1
],
self
.
_sid
).
content
def
worker
():
def
worker
():
_logger
.
debug
(
"
Called TextgridResource.begin_write.worker().
"
)
_logger
.
debug
(
"
Called TextgridResource.begin_write.worker().
"
)
crud
.
update_resource
(
self
.
_sid
,
self
.
path
.
split
(
"
/
"
)[
-
1
]
,
queue
,
metadata
)
self
.
_
crud
.
update_resource
(
self
.
_sid
,
self
.
_tguri
,
queue
,
metadata
)
thread
=
threading
.
Thread
(
target
=
worker
)
thread
=
threading
.
Thread
(
target
=
worker
)
thread
.
setDaemon
(
True
)
thread
.
setDaemon
(
True
)
...
...
This diff is collapsed.
Click to expand it.
src/repdav/textgrid_named_dav_provider.py
+
4
−
41
View file @
5bef02de
import
io
import
logging
import
logging
import
threading
from
pprint
import
pformat
from
pprint
import
pformat
from
tgclients.config
import
TextgridConfig
from
tgclients.config
import
TextgridConfig
...
@@ -73,14 +71,8 @@ class TextgridNamedProject(TextgridProject):
...
@@ -73,14 +71,8 @@ class TextgridNamedProject(TextgridProject):
def
get_member_names
(
self
):
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridNamedProject.get_member_names(self).
"
)
_logger
.
debug
(
"
Called TextgridNamedProject.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
name
=
self
.
path
.
split
(
"
/
"
)[
-
1
]
name
=
self
.
path
.
split
(
"
/
"
)[
-
1
]
# the projectID is found between square brackets at the end of the name string
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
)
response
=
self
.
_tgsearch
.
list_project_root
(
project_id
,
self
.
_sid
)
names
=
[]
names
=
[]
...
@@ -116,11 +108,11 @@ class TextgridNamedAggregation(TextgridAggregation):
...
@@ -116,11 +108,11 @@ class TextgridNamedAggregation(TextgridAggregation):
)
)
super
().
__init__
(
path
,
environ
,
info
)
super
().
__init__
(
path
,
environ
,
info
)
self
.
_tgmeta
=
tgmeta
self
.
_tgmeta
=
tgmeta
self
.
_tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
def
get_member_names
(
self
):
def
get_member_names
(
self
):
_logger
.
debug
(
"
Called TextgridNamedAggregation.get_member_names(self).
"
)
_logger
.
debug
(
"
Called TextgridNamedAggregation.get_member_names(self).
"
)
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
response
=
self
.
_tgsearch
.
list_aggregation
(
self
.
_tguri
,
self
.
_sid
)
response
=
self
.
_tgsearch
.
list_aggregation
(
tguri
,
self
.
_sid
)
names
=
[]
names
=
[]
for
result
in
response
.
result
:
for
result
in
response
.
result
:
names
.
append
(
self
.
_tgmeta
.
filename_from_metadata
(
result
))
names
.
append
(
self
.
_tgmeta
.
filename_from_metadata
(
result
))
...
@@ -154,33 +146,4 @@ class TextgridNamedResource(TextgridResource):
...
@@ -154,33 +146,4 @@ class TextgridNamedResource(TextgridResource):
_logger
.
debug
(
"
Called TextgridNamedResource.__init__(self, %s, environ).
"
,
path
)
_logger
.
debug
(
"
Called TextgridNamedResource.__init__(self, %s, environ).
"
,
path
)
super
().
__init__
(
path
,
environ
,
info
)
super
().
__init__
(
path
,
environ
,
info
)
self
.
_tgmeta
=
tgmeta
self
.
_tgmeta
=
tgmeta
config
=
TextgridConfig
()
self
.
_tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
self
.
_crud
=
TextgridCRUD
(
config
.
crud
)
def
get_content
(
self
):
_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
])
return
io
.
BytesIO
(
self
.
_crud
.
read_data
(
tguri
,
self
.
_sid
).
content
)
def
begin_write
(
self
,
content_type
=
None
):
_logger
.
debug
(
"
Called TextgridResource.begin_write(self, content_type=%s).
"
,
content_type
)
queue
=
FileLikeQueue
(
int
(
self
.
_size
))
tguri
=
"
textgrid:
"
+
self
.
_tgmeta
.
id_from_filename
(
self
.
path
.
split
(
"
/
"
)[
-
1
])
metadata
=
self
.
_crud
.
read_metadata
(
tguri
,
self
.
_sid
).
content
def
worker
():
_logger
.
debug
(
"
Called TextgridResource.begin_write.worker().
"
)
self
.
_crud
.
update_resource
(
self
.
_sid
,
tguri
,
queue
,
metadata
)
thread
=
threading
.
Thread
(
target
=
worker
)
thread
.
setDaemon
(
True
)
thread
.
start
()
self
.
upload_thread
=
thread
return
queue
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