Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8392914
client.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
client.py
View Options
#!/usr/bin/env python3
# Copyright (C) 2015 Stefano Zacchiroli <zack@upsilon.cc>,
# Antoine R. Dumont <antoine.romain.dumont@gmail.com>
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
requests
from
swh.storage
import
models
from
retrying
import
retry
from
swh.retry
import
policy
_api_url
=
{
models
.
Type
.
blob
:
'/git/blobs/'
,
models
.
Type
.
commit
:
'/git/commits/'
,
models
.
Type
.
tree
:
'/git/trees/'
}
def
compute_url
(
baseurl
,
type
,
sha1hex
):
"""Compute the api url.
"""
return
'
%s%s%s
'
%
(
baseurl
,
_api_url
[
type
],
sha1hex
)
@retry
(
retry_on_exception
=
policy
.
retry_if_connection_error
,
wrap_exception
=
True
)
def
get
(
baseurl
,
type
,
sha1hex
):
"""Retrieve the objects of type type with sha1 sha1hex.
"""
r
=
requests
.
get
(
compute_url
(
baseurl
,
type
,
sha1hex
))
return
r
.
ok
@retry
(
retry_on_exception
=
policy
.
retry_if_connection_error
,
wrap_exception
=
True
)
def
put
(
baseurl
,
type
,
sha1hex
,
data
=
None
):
"""Retrieve the objects of type type with sha1 sha1hex.
"""
r
=
requests
.
put
(
compute_url
(
baseurl
,
type
,
sha1hex
),
[]
if
data
is
None
else
data
)
return
r
.
ok
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Jun 4 2025, 7:04 PM (10 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3241090
Attached To
rDLDG Git loader
Event Timeline
Log In to Comment