From 2e0c7def5895fea29177718abb690b75bc21695e Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Wed, 2 May 2007 19:41:47 +0000 Subject: 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. --- RepSys/commands/ci.py | 29 +++++++++++++++++++++++++++++ RepSys/mirror.py | 42 ++++++++++++++++++++++++++++++++++++++++++ RepSys/rpmutil.py | 24 ++++++++++++++++++++++++ RepSys/svn.py | 19 +++++++++++++++++++ repsys | 1 + repsys.conf | 1 + 6 files changed, 116 insertions(+) create mode 100644 RepSys/commands/ci.py create mode 100644 RepSys/mirror.py 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) diff --git a/repsys b/repsys index c83e04d..2157308 100755 --- a/repsys +++ b/repsys @@ -11,6 +11,7 @@ Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co + ci submit create getspec diff --git a/repsys.conf b/repsys.conf index dce1fe3..87013b0 100644 --- a/repsys.conf +++ b/repsys.conf @@ -2,6 +2,7 @@ verbose = no default_parent = svn+ssh://svn.mandriva.com/svn/packages/cooker url-map = svn\+ssh://svn\.mandriva\.com/(.*) file:///\1 +#mirror = http://svn.mandriva.com/svn/packages/cooker/ #tempdir = /tmp [log] -- cgit v1.2.1