Changeset View
Changeset View
Standalone View
Standalone View
contrib/buildbot/shieldio.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# | # | ||||
# Copyright (c) 2020 The Bitcoin ABC developers | # Copyright (c) 2020 The Bitcoin ABC developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from urllib.parse import quote, unquote, urlencode, urlsplit, urlunsplit | from urllib.parse import quote, unquote, urlencode, urlsplit, urlunsplit | ||||
class Badge: | class Badge: | ||||
def __init__(self, **kwargs): | def __init__(self, **kwargs): | ||||
self.base_url = 'https://img.shields.io/static/v1' | self.base_url = "https://img.shields.io/static/v1" | ||||
# Provide some defaults, potentially updated by kwargs | # Provide some defaults, potentially updated by kwargs | ||||
self.query = { | self.query = { | ||||
'label': 'shieldio', | "label": "shieldio", | ||||
'message': 'unknown', | "message": "unknown", | ||||
'color': 'inactive', | "color": "inactive", | ||||
} | } | ||||
self.query.update(kwargs) | self.query.update(kwargs) | ||||
def get_badge_url(self, **kwargs): | def get_badge_url(self, **kwargs): | ||||
scheme, netloc, path = urlsplit(self.base_url)[0:3] | scheme, netloc, path = urlsplit(self.base_url)[0:3] | ||||
return urlunsplit(( | return urlunsplit( | ||||
( | |||||
scheme, | scheme, | ||||
netloc, | netloc, | ||||
path, | path, | ||||
unquote(urlencode({**self.query, **kwargs}, | unquote( | ||||
doseq=True, quote_via=quote)), | urlencode({**self.query, **kwargs}, doseq=True, quote_via=quote) | ||||
'' | ), | ||||
)) | "", | ||||
) | |||||
) | |||||
class RasterBadge(Badge): | class RasterBadge(Badge): | ||||
def __init__(self, **kwargs): | def __init__(self, **kwargs): | ||||
super().__init__(**kwargs) | super().__init__(**kwargs) | ||||
self.base_url = 'https://raster.shields.io/static/v1' | self.base_url = "https://raster.shields.io/static/v1" |