Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-deposit
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Antoine R. Dumont
swh-deposit
Commits
0138edca
Unverified
Commit
0138edca
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
deposit_read: Refactor to clarify intents and docstring
parent
37b48717
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/deposit/api/private/deposit_read.py
+24
-10
24 additions, 10 deletions
swh/deposit/api/private/deposit_read.py
with
24 additions
and
10 deletions
swh/deposit/api/private/deposit_read.py
+
24
−
10
View file @
0138edca
...
...
@@ -140,6 +140,18 @@ class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView,
def
_prepare_date
(
self
,
date
):
"""
Prepare date fields as normalized swh date
If date is a list, elect arbitrarily the first element of that
list
If date is (then) a string, parse it through
dateutil.parser.parse to extract a datetime.
Then normalize it through
swh.model.identifiers.normalize_timestamp.
Returns
The swh date object
"""
if
isinstance
(
date
,
list
):
date
=
date
[
0
]
...
...
@@ -148,9 +160,9 @@ class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView,
return
identifiers
.
normalize_timestamp
(
date
)
def
_
comput
e_date
(
self
,
deposit
,
metadata
):
"""
Comput
e the date to use as a tuple of author date, committer date
.
Each of those date are swh normalized immediately
.
def
_
normaliz
e_date
s
(
self
,
deposit
,
metadata
):
"""
Normaliz
e the date to use as a tuple of author date, committer date
from the incoming metadata
.
Args:
deposit (Deposit): Deposit model representation
...
...
@@ -165,16 +177,18 @@ class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView,
author_date
=
metadata
.
get
(
'
codemeta:dateCreated
'
)
if
author_date
and
commit_date
:
t
=
(
author_date
,
commit_date
)
pass
elif
commit_date
:
t
=
(
commit
_date
,
commit_date
)
author
_date
=
commit_date
elif
author_date
:
t
=
(
author
_date
,
author_date
)
commit
_date
=
author_date
else
:
date
=
deposit
.
complete_date
t
=
(
date
,
date
)
author_
date
=
deposit
.
complete_date
commit_date
=
deposit
.
complete_
date
return
(
self
.
_prepare_date
(
t
[
0
]),
self
.
_prepare_date
(
t
[
1
]))
self
.
_prepare_date
(
author_date
),
self
.
_prepare_date
(
commit_date
)
)
def
metadata_read
(
self
,
deposit
):
"""
Read and aggregate multiple data on deposit into one unified data
...
...
@@ -210,7 +224,7 @@ class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView,
revision_msg
=
'
%s: Deposit %s in collection %s
'
%
(
fullname
,
deposit
.
id
,
deposit
.
collection
.
name
)
author_date
,
commit_date
=
self
.
_
comput
e_date
(
deposit
,
metadata
)
author_date
,
commit_date
=
self
.
_
normaliz
e_date
s
(
deposit
,
metadata
)
data
[
'
revision
'
]
=
{
'
synthetic
'
:
True
,
...
...
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