Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
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
Renaud Boyer
swh-model
Commits
45a1f7db
Commit
45a1f7db
authored
9 years ago
by
Nicolas Dandrimont
Browse files
Options
Downloads
Patches
Plain Diff
identifiers: move dates to the root of the objects
parent
56891b94
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/identifiers.py
+39
-10
39 additions, 10 deletions
swh/model/identifiers.py
swh/model/tests/test_identifiers.py
+16
-17
16 additions, 17 deletions
swh/model/tests/test_identifiers.py
with
55 additions
and
27 deletions
swh/model/identifiers.py
+
39
−
10
View file @
45a1f7db
...
...
@@ -208,14 +208,40 @@ def format_offset(offset):
return
t
.
encode
()
def
format_author
(
author
):
components
=
[
author
[
'
name
'
],
b
'
<
'
,
author
[
'
email
'
],
b
'
>
'
,
format_date
(
author
[
'
date
'
]),
b
'
'
,
format_offset
(
author
[
'
date_offset
'
]),
]
def
format_date_offset
(
date_offset
):
"""
Format a date-compatible object with its timezone offset.
A date-compatible object is either:
- a dict with two members
timestamp: floating point number of seconds since the unix epoch
offset: (int) number of minutes representing the offset from UTC
- a datetime.datetime object with a timezone
- a numeric value (in which case the offset is hardcoded to 0)
"""
return
b
''
.
join
(
components
)
# FIXME: move normalization to another module
if
isinstance
(
date_offset
,
dict
):
date
=
date_offset
[
'
timestamp
'
]
offset
=
date_offset
[
'
offset
'
]
elif
isinstance
(
date_offset
,
datetime
.
datetime
):
date
=
date_offset
utcoffset
=
date_offset
.
utcoffset
()
if
utcoffset
is
None
:
raise
ValueError
(
'
Received a datetime without a timezone
'
)
seconds_offset
=
utcoffset
.
total_seconds
()
if
seconds_offset
-
int
(
seconds_offset
)
!=
0
or
seconds_offset
%
60
:
raise
ValueError
(
'
Offset is not an integer number of minutes
'
)
offset
=
int
(
seconds_offset
)
//
60
else
:
date
=
date_offset
offset
=
0
return
b
''
.
join
([
format_date
(
date
),
b
'
'
,
format_offset
(
offset
)])
def
format_author
(
author
):
return
b
''
.
join
([
author
[
'
name
'
],
b
'
<
'
,
author
[
'
email
'
],
b
'
>
'
])
def
revision_identifier
(
revision
):
...
...
@@ -231,8 +257,10 @@ def revision_identifier(revision):
])
components
.
extend
([
b
'
author
'
,
format_author
(
revision
[
'
author
'
]),
b
'
\n
'
,
b
'
committer
'
,
format_author
(
revision
[
'
committer
'
]),
b
'
\n
'
,
b
'
author
'
,
format_author
(
revision
[
'
author
'
]),
b
'
'
,
format_date_offset
(
revision
[
'
date
'
]),
b
'
\n
'
,
b
'
committer
'
,
format_author
(
revision
[
'
committer
'
]),
b
'
'
,
format_date_offset
(
revision
[
'
committer_date
'
]),
b
'
\n
'
,
b
'
\n
'
,
revision
[
'
message
'
],
])
...
...
@@ -251,7 +279,8 @@ def release_identifier(release):
if
'
author
'
in
release
and
release
[
'
author
'
]:
components
.
extend
([
b
'
tagger
'
,
format_author
(
release
[
'
author
'
]),
b
'
\n
'
,
b
'
tagger
'
,
format_author
(
release
[
'
author
'
]),
b
'
'
,
format_date_offset
(
release
[
'
date
'
]),
b
'
\n
'
,
])
components
.
extend
([
b
'
\n
'
,
release
[
'
comment
'
]])
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_identifiers.py
+
16
−
17
View file @
45a1f7db
...
...
@@ -216,6 +216,9 @@ class DirectoryIdentifier(unittest.TestCase):
class
RevisionIdentifier
(
unittest
.
TestCase
):
def
setUp
(
self
):
linus_tz
=
datetime
.
timezone
(
datetime
.
timedelta
(
minutes
=-
420
))
self
.
revision
=
{
'
id
'
:
'
bc0195aad0daa2ad5b0d76cce22b167bc3435590
'
,
'
directory
'
:
'
85a74718d377195e1efd0843ba4f3260bad4fe07
'
,
...
...
@@ -223,19 +226,15 @@ class RevisionIdentifier(unittest.TestCase):
'
author
'
:
{
'
name
'
:
b
'
Linus Torvalds
'
,
'
email
'
:
b
'
torvalds@linux-foundation.org
'
,
'
date
'
:
datetime
.
datetime
(
2015
,
7
,
12
,
22
,
10
,
30
,
tzinfo
=
datetime
.
timezone
.
utc
),
'
date_offset
'
:
-
420
,
},
'
date
'
:
datetime
.
datetime
(
2015
,
7
,
12
,
15
,
10
,
30
,
tzinfo
=
linus_tz
),
'
committer
'
:
{
'
name
'
:
b
'
Linus Torvalds
'
,
'
email
'
:
b
'
torvalds@linux-foundation.org
'
,
'
date
'
:
datetime
.
datetime
(
2015
,
7
,
12
,
22
,
10
,
30
,
tzinfo
=
datetime
.
timezone
.
utc
),
'
date_offset
'
:
-
420
,
},
'
committer_date
'
:
datetime
.
datetime
(
2015
,
7
,
12
,
15
,
10
,
30
,
tzinfo
=
linus_tz
),
'
message
'
:
b
'
Linux 4.2-rc2
\n
'
,
}
...
...
@@ -245,18 +244,17 @@ class RevisionIdentifier(unittest.TestCase):
'
author
'
:
{
'
name
'
:
b
'
Software Heritage
'
,
'
email
'
:
b
'
robot@softwareheritage.org
'
,
'
date
'
:
datetime
.
datetime
(
2015
,
7
,
16
,
11
,
51
,
35
,
tzinfo
=
datetime
.
timezone
.
utc
),
'
date_offset
'
:
0
,
},
'
date
'
:
{
'
timestamp
'
:
1437047495.0
,
'
offset
'
:
0
,
},
'
type
'
:
'
tar
'
,
'
committer
'
:
{
'
name
'
:
b
'
Software Heritage
'
,
'
date
'
:
datetime
.
datetime
(
2015
,
7
,
16
,
11
,
51
,
35
,
tzinfo
=
datetime
.
timezone
.
utc
),
'
email
'
:
b
'
robot@softwareheritage.org
'
,
'
date_offset
'
:
0
,
},
'
committer_date
'
:
1437047495
,
'
synthetic
'
:
True
,
'
parents
'
:
[
None
],
'
message
'
:
b
'
synthetic revision message
\n
'
,
...
...
@@ -289,6 +287,8 @@ class RevisionIdentifier(unittest.TestCase):
class
ReleaseIdentifier
(
unittest
.
TestCase
):
def
setUp
(
self
):
linus_tz
=
datetime
.
timezone
(
datetime
.
timedelta
(
minutes
=-
420
))
self
.
release
=
{
'
id
'
:
'
2b10839e32c4c476e9d94492756bb1a3e1ec4aa8
'
,
'
revision
'
:
b
'
t
\x1b
"
R
\xa5\xe1
Ml`
\xa9\x13\xc7
z`
\x99\xab\xe7
:
\x85
J
'
,
...
...
@@ -296,10 +296,9 @@ class ReleaseIdentifier(unittest.TestCase):
'
author
'
:
{
'
name
'
:
b
'
Linus Torvalds
'
,
'
email
'
:
b
'
torvalds@g5.osdl.org
'
,
'
date
'
:
datetime
.
datetime
(
2005
,
10
,
28
,
0
,
2
,
33
,
tzinfo
=
datetime
.
timezone
.
utc
),
'
date_offset
'
:
-
420
,
},
'
date
'
:
datetime
.
datetime
(
2005
,
10
,
27
,
17
,
2
,
33
,
tzinfo
=
linus_tz
),
'
comment
'
:
b
'''
\
Linux 2.6.14 release
-----BEGIN PGP SIGNATURE-----
...
...
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