diff options
Diffstat (limited to 'pomu/repo/remote/remote.py')
-rw-r--r-- | pomu/repo/remote/remote.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/pomu/repo/remote/remote.py b/pomu/repo/remote/remote.py index d057e6f..133c645 100644 --- a/pomu/repo/remote/remote.py +++ b/pomu/repo/remote/remote.py @@ -1,11 +1,38 @@ """A template class for remote repos""" - +from urllib.parse import urlparse class RemoteRepo(): """A class responsible for remotes""" def __init__(self, url): raise NotImplementedError() + @classmethod + def from_url(cls, uri, type_=None): + tp = RemoteRepo.type_for_name(type_) + if not tp: + try: + scheme, *_ = urlparse(uri) + except: + tp = RemoteGitRepo + if (scheme.startswith('http') or scheme.startswith('git') + scheme.startswith('ssh')): + tp = RemoteGitRepo + elif scheme.startswith('svn'): + tp = RemoteSvnRepo + elif scheme.startswith('rsync'): + tp = RemoteRsyncRepo + return tp(uri) + + @classmethod + def type_for_name(type_): + from pomu.repo.remote.git import RemoteGitRepo + from pomu.repo.remote.hg import RemoteHgRepo + from pomu.repo.remote.rsync import RemoteRsyncRepo + from pomu.repo.remote.svn import RemoteSvnRepo + res = {'git': RemoteGitRepo, 'mercurial': RemoteHgRepo, + 'rsync': RemoteRsyncRepo, 'svn': RemoteSvnRepo} + return res.get(type_) + def fetch_package(self, name, category=None, version=None): """Fetches a package, determined by the parametres""" cat, n, ver = get_full_cpv(self.fetch_tree(), name, category, version).unwrap() |