Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P691
random-swhid
Active
Public
Actions
Authored by
zack
on Jun 9 2020, 10:31 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
#!/usr/bin/env python3
"""Generate a feed of random (hence bogus, but syntactically correct!) SWHIDs
"""
__copyright__
=
"Copyright (C) 2020 Stefano Zacchiroli"
__license__
=
"GPL-3.0-or-later"
import
random
HEX_DIGITS
=
"0123456789abcdef"
SWHID_HEX_LEN
=
40
SWHID_PREFIX
=
"swh"
SWHID_SEP
=
":"
SWHID_TYPES
=
[
"cnt"
,
"dir"
,
"rev"
,
"rel"
,
"snp"
]
SWHID_VERSION
=
"1"
def
random_swhid
()
->
str
:
return
SWHID_SEP
.
join
(
[
SWHID_PREFIX
,
SWHID_VERSION
,
random
.
choice
(
SWHID_TYPES
),
""
.
join
(
random
.
choices
(
HEX_DIGITS
,
k
=
SWHID_HEX_LEN
)),
]
)
def
main
():
try
:
while
True
:
print
(
random_swhid
())
except
(
BrokenPipeError
,
KeyboardInterrupt
):
pass
if
__name__
==
"__main__"
:
main
()
Event Timeline
zack
edited the content of this paste.
(Show Details)
Jun 9 2020, 10:31 AM
2020-06-09 10:31:15 (UTC+2)
zack
changed the title of this paste from untitled to
random-swhid
.
zack
edited the content of this paste.
(Show Details)
Jun 9 2020, 10:34 AM
2020-06-09 10:34:22 (UTC+2)
zack
edited the content of this paste.
(Show Details)
Jun 9 2020, 10:47 AM
2020-06-09 10:47:15 (UTC+2)
Log In to Comment