aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2007-05-02 19:41:47 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2007-05-02 19:41:47 +0000
commit2e0c7def5895fea29177718abb690b75bc21695e (patch)
treeb07f8b5bb67d29037656ed7a2341b202dfcfb0a3 /RepSys
parenta0db56024d803cbe112ce31d8de2aa2701a5d79c (diff)
downloadmgarepo-2e0c7def5895fea29177718abb690b75bc21695e.tar
mgarepo-2e0c7def5895fea29177718abb690b75bc21695e.tar.gz
mgarepo-2e0c7def5895fea29177718abb690b75bc21695e.tar.bz2
mgarepo-2e0c7def5895fea29177718abb690b75bc21695e.tar.xz
mgarepo-2e0c7def5895fea29177718abb690b75bc21695e.zip
Added initial support to mirrors, as requested by mrl.
It was added an option "mirror" to repsys.conf, that will contain an URL to the mirror repository. Also added the subcommand "ci", which will relocate one working copy to the master repository before effectively commiting.
Diffstat (limited to 'RepSys')
-rw-r--r--RepSys/commands/ci.py29
-rw-r--r--RepSys/mirror.py42
-rw-r--r--RepSys/rpmutil.py24
-rw-r--r--RepSys/svn.py19
4 files changed, 114 insertions, 0 deletions
diff --git a/RepSys/commands/ci.py b/RepSys/commands/ci.py
new file mode 100644
index 0000000..9ffa3bd
--- /dev/null
+++ b/RepSys/commands/ci.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+from RepSys.command import *
+from RepSys.rpmutil import commit
+
+HELP = """\
+Usage: repsys ci [TARGET]
+
+Will commit a change. The difference between an ordinary "svn ci" and
+"repsys ci" is that it relocates the working copy to the default repository
+in case the option "mirror" is set in repsys.conf.
+
+Options:
+ -h Show this message
+
+Examples:
+ repsys ci
+ repsys ci SPECS/package.spec SPECS/package-patch.patch
+"""
+
+def parse_options():
+ parser = OptionParser(help=HELP)
+ parser.add_option("-m", dest="message", default=None)
+ opts, args = parser.parse_args()
+ if len(args):
+ opts.target = args[0]
+ return opts
+
+def main():
+ do_command(parse_options, commit)
diff --git a/RepSys/mirror.py b/RepSys/mirror.py
new file mode 100644
index 0000000..a24f594
--- /dev/null
+++ b/RepSys/mirror.py
@@ -0,0 +1,42 @@
+import os
+import urlparse
+
+from RepSys import config
+from RepSys.svn import SVN
+
+def relocate_path(oldparent, newparent, url):
+ subpath = url[len(oldparent)-1:]
+ newurl = newparent + "/" + subpath # subpath usually gets / at begining
+ return newurl
+
+def enabled():
+ mirror = config.get("global", "mirror")
+ default_parent = config.get("global", "default_parent")
+ return (mirror is not None and
+ default_parent is not None)
+
+def mirror_relocate(oldparent, newparent, url, wcpath):
+ svn = SVN(noauth=True)
+ newurl = relocate_path(oldparent, newparent, url)
+ svn.switch(newurl, url, path=wcpath, relocate="True")
+ return newurl
+
+def switchto_parent(svn, url, path):
+ """Relocates the working copy to default_parent"""
+ mirror = config.get("global", "mirror")
+ default_parent = config.get("global", "default_parent")
+ newurl = mirror_relocate(mirror, default_parent, url, path)
+ return newurl
+
+def switchto_mirror(svn, url, path):
+ mirror = config.get("global", "mirror")
+ default_parent = config.get("global", "default_parent")
+ newurl = mirror_relocate(default_parent, mirror, url, path)
+ return newurl
+
+def checkout_url(url):
+ mirror = config.get("global", "mirror")
+ default_parent = config.get("global", "default_parent")
+ if mirror is not None and default_parent is not None:
+ return relocate_path(default_parent, mirror, url)
+ return url
diff --git a/RepSys/rpmutil.py b/RepSys/rpmutil.py
index 367fd45..12a8226 100644
--- a/RepSys/rpmutil.py
+++ b/RepSys/rpmutil.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
from RepSys import Error, config, RepSysTree
+from RepSys import mirror
from RepSys.svn import SVN
from RepSys.rpm import SRPM
from RepSys.log import specfile_svn2rpm
@@ -357,8 +358,31 @@ def checkout(pkgdirurl, path=None, revision=None):
current = os.path.join(pkgdirurl, "current")
if path is None:
_, path = os.path.split(pkgdirurl)
+ if mirror.enabled():
+ current = mirror.checkout_url(current)
+ print "checking out from mirror", current
svn.checkout(current, path, rev=revision, show=1)
+def commit(target=".", message=None):
+ svn = SVN(noauth=True)
+ info = svn.info2(target)
+ url = info.get("URL")
+ if url is None:
+ raise Error, "working copy URL not provided by svn info"
+ if mirror.enabled():
+ newurl = mirror.switchto_parent(svn, url, target)
+ print "relocated to", newurl
+ try:
+ # we can't use the svn object here because pexpect hides VISUAL
+ mopt = ""
+ if message is not None:
+ mopt = "-m \"%s\"" % message
+ os.system("svn ci %s %s" % (mopt, target))
+ finally:
+ if mirror.enabled():
+ mirror.switchto_mirror(svn, newurl, target)
+ print "relocated back to", url
+
def get_submit_info(path):
path = os.path.abspath(path)
diff --git a/RepSys/svn.py b/RepSys/svn.py
index 4e073dc..a13db8b 100644
--- a/RepSys/svn.py
+++ b/RepSys/svn.py
@@ -169,6 +169,12 @@ class SVN:
if status == 0:
return output.splitlines()
return None
+
+ def info2(self, *args, **kwargs):
+ lines = self.info(*args, **kwargs)
+ pairs = [[w.strip() for w in line.split(":", 1)] for line in lines]
+ info = dict(pairs)
+ return info
def ls(self, path, **kwargs):
cmd = ["ls", path]
@@ -197,6 +203,19 @@ class SVN:
return [x.split() for x in output.split()]
return None
+ def switch(self, url, oldurl=None, path=None, relocate=False, **kwargs):
+ cmd = ["switch"]
+ if relocate:
+ if oldurl is None:
+ raise Error, "You must supply the old URL when "\
+ "relocating working copies"
+ cmd.append("--relocate")
+ cmd.append(oldurl)
+ cmd.append(url)
+ if path is not None:
+ cmd.append(path)
+ return self._execsvn_success(*cmd, **kwargs)
+
def update(self, path, **kwargs):
cmd = ["update", path]
self._add_revision(cmd, kwargs, optional=1)