aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <proyvind@moondrake.org>2016-06-28 21:47:50 +0200
committerPer Øyvind Karlsen <proyvind@moondrake.org>2016-06-28 21:47:50 +0200
commit919de84e24d9fc8d4a2fda6cb46cac79744522a8 (patch)
treeef9319f5d7041b748bfa5552ce541641c1e18d7c /MgaRepo
parentdb101fdddb6f631a342fedc0ef2560edbef580b5 (diff)
downloadmgarepo-919de84e24d9fc8d4a2fda6cb46cac79744522a8.tar
mgarepo-919de84e24d9fc8d4a2fda6cb46cac79744522a8.tar.gz
mgarepo-919de84e24d9fc8d4a2fda6cb46cac79744522a8.tar.bz2
mgarepo-919de84e24d9fc8d4a2fda6cb46cac79744522a8.tar.xz
mgarepo-919de84e24d9fc8d4a2fda6cb46cac79744522a8.zip
store repo topdir in VCS class
Diffstat (limited to 'MgaRepo')
-rw-r--r--MgaRepo/VCS.py10
-rw-r--r--MgaRepo/git.py4
-rw-r--r--MgaRepo/rpmutil.py34
-rw-r--r--MgaRepo/svn.py4
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}