From 125d343b51691109745cecd6660c6e0d259ab929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Thu, 30 Jun 2016 22:48:20 +0200 Subject: add url to VCS class --- MgaRepo/VCS.py | 21 +++++++++++++++++++-- MgaRepo/git.py | 4 ++-- MgaRepo/rpmutil.py | 10 +++++----- MgaRepo/svn.py | 4 ++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/MgaRepo/VCS.py b/MgaRepo/VCS.py index 7a9170b..ee419f4 100644 --- a/MgaRepo/VCS.py +++ b/MgaRepo/VCS.py @@ -1,5 +1,6 @@ from MgaRepo import Error, SilentError, config from MgaRepo.util import execcmd, get_auth +from MgaRepo import layout from xml.etree import ElementTree import sys import os @@ -23,13 +24,19 @@ class VCSLogEntry(object): class VCS(object): vcs_dirname = None vcs_name = None - def __init__(self, path): + def __init__(self, path, url): self.vcs_command = None self.vcs_wrapper = "mga-ssh" self.vcs_supports = {'clone' : False} self.vcs_type = None self.env_defaults = None - self._path = path + if not path and not url: + self._path = os.path.curdir + elif not path and url: + self._path = layout.package_name(layout.remove_current(url)) + else: + self._path = path + self._url = url def _execVcs(self, *args, **kwargs): localcmds = ("add", "revert", "cleanup", "mv") @@ -393,6 +400,16 @@ class VCS(object): else: return None + @property + def path(self): + return self._path + + @property + def url(self): + if not self._url: + self._url = self.info2(self._path)["URL"] + return self._url + class VCSLook(object): def __init__(self, repospath, txn=None, rev=None): self.repospath = repospath diff --git a/MgaRepo/git.py b/MgaRepo/git.py index 01f21f0..3576893 100644 --- a/MgaRepo/git.py +++ b/MgaRepo/git.py @@ -19,8 +19,8 @@ class GITLogEntry(VCSLogEntry): class GIT(VCS): vcs_dirname = ".git" vcs_name = "git" - def __init__(self, path=os.path.curdir): - VCS.__init__(self, path) + def __init__(self, path=None, url=None): + VCS.__init__(self, path, url) self.vcs_command = config.get("global", "git-command", ["git"]) self.vcs_supports['clone'] = True self.env_defaults = {"GIT_SSH": self.vcs_wrapper} diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py index 2b78d68..9cfbef2 100644 --- a/MgaRepo/rpmutil.py +++ b/MgaRepo/rpmutil.py @@ -19,14 +19,14 @@ def detectVCS(url): if ':' in url: protocol,uri = url.split(":") if "svn" in protocol: - return SVN() + return SVN(url=url) elif "git" in protocol: - return GIT() + return GIT(url=url) elif "http" in protocol: if uri.endswith(".git"): - return GIT() + return GIT(url=url) elif "svn" in uri: - return SVN() + return SVN(url=url) raise Error("Unknown protocol %s for %s" % (protocol, url)) elif os.path.exists(url) and os.path.isdir(url): while True: @@ -34,7 +34,7 @@ def detectVCS(url): for vcs in (SVN, GIT): vcsdir = os.path.join(url, vcs.vcs_dirname) if os.path.exists(vcsdir) and os.path.isdir(vcsdir): - return vcs(url) + return vcs(path=url) url = os.path.dirname(url) if url == "/": break diff --git a/MgaRepo/svn.py b/MgaRepo/svn.py index 15d1cbc..5f8851c 100644 --- a/MgaRepo/svn.py +++ b/MgaRepo/svn.py @@ -14,8 +14,8 @@ class SVNLogEntry(VCSLogEntry): class SVN(VCS): vcs_dirname = ".svn" vcs_name = "svn" - def __init__(self, path=os.path.curdir): - VCS.__init__(self, path) + def __init__(self, path=None, url=None): + VCS.__init__(self, path, url) self.vcs_command = config.get("global", "svn-command", ["svn"]) self.env_defaults = {"SVN_SSH": self.vcs_wrapper} -- cgit v1.2.1