Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import logging as log # for verbose output
from .BitBucketRepoSession import BitBucketRepoSession
from .GitHubRepoSession import GitHubRepoSession
from .GitLabRepoSession import GitLabRepoSession
from .LocalVersionSession import LocalVersionSession
from .MercurialRepoSession import MercurialRepoSession
from .SourceForgeRepoSession import SourceForgeRepoSession
class HolderFactory:
HOLDERS = {
'github': GitHubRepoSession,
'gitlab': GitLabRepoSession,
'bitbucket': BitBucketRepoSession,
'hg': MercurialRepoSession,
'sf': SourceForgeRepoSession,
'local': LocalVersionSession
}
@staticmethod
# go through subclasses in order to find the one that is hodling a given project
# repo is either complete URL or a name allowing to identify a single project
def get_instance_for_repo(repo):
holder_class = HolderFactory.HOLDERS['github']
hostname = None
known_repo = None
for k, sc in HolderFactory.HOLDERS.items():
known_repo = sc.is_official_for_repo(repo)
if known_repo:
holder_class = sc
log.info('Using {} adapter'.format(k))
break