From 919de84e24d9fc8d4a2fda6cb46cac79744522a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Tue, 28 Jun 2016 21:47:50 +0200 Subject: store repo topdir in VCS class --- MgaRepo/VCS.py | 10 +++++++++- MgaRepo/git.py | 4 ++-- MgaRepo/rpmutil.py | 34 +++++++++++++++++++++------------- MgaRepo/svn.py | 4 ++-- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/MgaRepo/VCS.py b/MgaRepo/VCS.py index 46058a2..7a9170b 100644 --- a/MgaRepo/VCS.py +++ b/MgaRepo/VCS.py @@ -23,12 +23,13 @@ class VCSLogEntry(object): class VCS(object): vcs_dirname = None vcs_name = None - def __init__(self): + def __init__(self, path): 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 def _execVcs(self, *args, **kwargs): localcmds = ("add", "revert", "cleanup", "mv") @@ -385,6 +386,13 @@ class VCS(object): self._add_log(cmd, kwargs) return self._execVcs_success(*cmd, **kwargs) + def get_topdir(self): + vcsdir = os.path.join(self._path, self.vcs_dirname) + if os.path.exists(vcsdir) and os.path.isdir(vcsdir): + return self._path + else: + return None + 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 07d57ac..08cccf6 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): - VCS.__init__(self) + def __init__(self, path=os.path.curdir): + VCS.__init__(self, path) 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 c541fc9..8a463d4 100644 --- a/MgaRepo/rpmutil.py +++ b/MgaRepo/rpmutil.py @@ -29,10 +29,15 @@ def detectVCS(url): return SVN() raise Error("Unknown protocol %s for %s" % (protocol, url)) elif os.path.exists(url) and os.path.isdir(url): - if os.path.exists(os.path.join(url,".svn")) and os.path.isdir(os.path.join(url,".svn")): - return SVN() - if os.path.exists(os.path.join(url,".git")) and os.path.isdir(os.path.join(url,".git")): - return GIT() + while True: + url = os.path.abspath(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) + url = os.path.dirname(url) + if url == "/": + break raise Error("No supported repository found at path: %s" % url) def get_spec(pkgdirurl, targetdir=".", submit=False): @@ -626,18 +631,21 @@ def clone(pkgdirurl, path=None, revision=None, branch=None, distro=None, backpor binrepo.download_binaries(path) def getpkgtopdir(basedir=os.path.curdir): - while not ispkgtopdir(basedir): - if os.path.abspath(basedir) == "/": - raise Error("can't find top package directories SOURCES and SPECS") - basedir = os.path.join(basedir, os.path.pardir) - return os.path.normpath(basedir) - -def ispkgtopdir(path=None): + vcs = detectVCS(basedir) + if vcs: + basedir = os.path.relpath(vcs.get_topdir()) + if ispkgtopdir(basedir, vcs_dirname=vcs.vcs_dirname): + return basedir + raise Error("can't find top package directories SOURCES and SPECS") + +def ispkgtopdir(path=None, vcs_dirname=None): if path is None: path = os.getcwd() names = os.listdir(path) - vcs = detectVCS(path) - return (vcs.vcs_dirname in names and "SPECS" in names and "SOURCES" in names) + if not vcs_dirname: + vcs = detectVCS(path) + vcs_dirname = vcs.vcs_dirname + return (vcs_dirname in names and "SPECS" in names and "SOURCES" in names) def sync(dryrun=False, commit=False, download=False): topdir = getpkgtopdir() diff --git a/MgaRepo/svn.py b/MgaRepo/svn.py index a9038df..15d1cbc 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): - VCS.__init__(self) + def __init__(self, path=os.path.curdir): + VCS.__init__(self, path) self.vcs_command = config.get("global", "svn-command", ["svn"]) self.env_defaults = {"SVN_SSH": self.vcs_wrapper} -- cgit v1.2.1