Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/cgit/lister.py
Show All 29 Lines | class CGitLister(StatelessLister[Repositories]): | ||||
URL for that git repo. | URL for that git repo. | ||||
If several "Clone" urls are provided, prefer the http/https one, if | If several "Clone" urls are provided, prefer the http/https one, if | ||||
any, otherwise fallback to the first one. | any, otherwise fallback to the first one. | ||||
""" | """ | ||||
LISTER_NAME = "cgit" | LISTER_NAME = "cgit" | ||||
def __init__(self, scheduler: SchedulerInterface, url=None, instance=None): | def __init__( | ||||
self, scheduler: SchedulerInterface, url: str, instance: Optional[str] = None | |||||
): | |||||
"""Lister class for CGit repositories. | """Lister class for CGit repositories. | ||||
Args: | Args: | ||||
url (str): main URL of the CGit instance, i.e. url of the index | url (str): main URL of the CGit instance, i.e. url of the index | ||||
of published git repositories on this instance. | of published git repositories on this instance. | ||||
instance (str): Name of cgit instance. Defaults to url's hostname | instance (str): Name of cgit instance. Defaults to url's hostname | ||||
if unset. | if unset. | ||||
""" | """ | ||||
if not instance: | if not instance: | ||||
instance = urlparse(url).hostname | instance = urlparse(url).hostname | ||||
assert instance is not None # Make mypy happy | |||||
super().__init__( | super().__init__( | ||||
scheduler=scheduler, credentials=None, url=url, instance=instance, | scheduler=scheduler, credentials=None, url=url, instance=instance, | ||||
) | ) | ||||
self.session = requests.Session() | self.session = requests.Session() | ||||
self.session.headers.update( | self.session.headers.update( | ||||
{"Accept": "application/html", "User-Agent": USER_AGENT} | {"Accept": "application/html", "User-Agent": USER_AGENT} | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |