Module ogr.factory
Functions
def get_instances_from_dict(instances: dict) ‑> set[GitService]
-
Load the service instances from the dictionary in the following form:
key
: hostname, url or name that can be mapped to the service-typevalue
: dictionary with arguments used when creating a new instance of the service (passed to the__init__
method)
e.g.:
get_instances_from_dict({ "github.com": {"token": "abcd"}, "pagure": { "token": "abcd", "instance_url": "https://src.fedoraproject.org", }, }) == { GithubService(token="abcd"), PagureService(token="abcd", instance_url="https://src.fedoraproject.org") }
When the mapping
key->service-type
is not recognised, you can add atype
key to the dictionary and specify the type of the instance. (It can be either name, hostname or url. The used mapping is same as for key->service-type.)The provided
key
is used as aninstance_url
and passed to the__init__
method as well.e.g.:
get_instances_from_dict({ "https://my.gtlb": {"token": "abcd", "type": "gitlab"}, }) == {GitlabService(token="abcd", instance_url="https://my.gtlb")}
Args
instances
- Mapping from service name/url/hostname to attributes for the service creation.
Returns
Set of the service instances.
def get_project(url,
service_mapping_update: dict[str, type[GitService]] | None = None,
custom_instances: Iterable[GitService] | None = None,
force_custom_instance: bool = True,
**kwargs) ‑> GitProject-
Return the project for the given URL.
Args
url
- URL of the project, e.g.
"https://github.com/packit/ogr"
. service_mapping_update
-
Custom mapping from service url/hostname (
str
) to service class.Defaults to no mapping.
custom_instances
-
List of instances that will be used when creating a project instance.
Defaults to
None
. force_custom_instance
-
Force picking a Git service from the
custom_instances
list, if there is any provided, raise an error if that is not possible.Defaults to
True
. **kwargs
- Arguments forwarded to init of the matching service.
Returns
GitProject
using the matching implementation. def get_service_class(url: str,
service_mapping_update: dict[str, type[GitService]] | None = None) ‑> type[GitService]-
Get the matching service class from the URL.
Args
url
- URL of the project, e.g.
"https://github.com/packit/ogr"
. service_mapping_update
-
Custom mapping from service url/hostname (str) to service class.
Defaults to
None
.
Returns
Matched class (subclass of
GitService
). def get_service_class_or_none(url: str,
service_mapping_update: dict[str, type[GitService]] | None = None) ‑> type[GitService] | None-
Get the matching service class from the URL.
Args
url
- URL of the project, e.g.
"https://github.com/packit/ogr"
. service_mapping_update
-
Custom mapping from service url/hostname (
str
) to service class.Defaults to
None
.
Returns
Matched class (subclass of
GitService
) orNone
. def use_for_service(service: str)
-
Class decorator that adds the class to the service mapping.
When the project url contains the
service
as a substring, this implementation will be used to initialize the project.When using this decorator, be sure that your class is initialized. (Add the import to
ogr/__init__.py
)Usage:
@use_for_service("github.com") class GithubService(BaseGitService): pass @use_for_service("pagure.io") @use_for_service("src.fedoraproject.org") class PagureService(BaseGitService): pass
Args
service
- URL of the service.
Returns
Decorator.