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/mirror.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 RepSys/mirror.py (limited to 'RepSys/mirror.py') 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 -- cgit v1.2.1 From 5f1a15b9c7b253c0267d05613683ac1fb5f88e6c Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Tue, 5 Jun 2007 19:17:27 +0000 Subject: Improved (and fixed) the support to mirrors and "switch" subcommand - added the switch subcommand to quickly switch between the default and the mirrored repositories - fixed bug of generating bogus mirror URLs - make "ci" smarter by only relocation if something has been changed in the working copy and it is not already relocated. --- RepSys/mirror.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 5 deletions(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index a24f594..6acc839 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -4,16 +4,46 @@ import urlparse from RepSys import config from RepSys.svn import SVN +def _normdirurl(url): + """normalize url for relocate_path needs""" + parsed = urlparse.urlparse(url) + path = os.path.normpath(parsed.path) + path += "/" # assuming we always deal with directories + newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, path, + parsed.params, parsed.query, parsed.fragment)) + return newurl + +def _joinurl(url, relpath): + parsed = urlparse.urlparse(url) + newpath = os.path.join(parsed.path, relpath) + newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, newpath, + parsed.params, parsed.query, parsed.fragment)) + return newurl + +def same_base(parent, url): + """returns true if parent is parent of url""" + parent = _normdirurl(parent) + url = _normdirurl(url) + #FIXME handle paths with/without username/password + return url.startswith(parent) + def relocate_path(oldparent, newparent, url): - subpath = url[len(oldparent)-1:] - newurl = newparent + "/" + subpath # subpath usually gets / at begining + oldparent = _normdirurl(oldparent) + newparent = _normdirurl(newparent) + url = _normdirurl(url) + subpath = url[len(oldparent):] + newurl = _joinurl(newparent, subpath) # subpath usually gets / at begining return newurl -def enabled(): +def enabled(wcurl=None): mirror = config.get("global", "mirror") default_parent = config.get("global", "default_parent") - return (mirror is not None and - default_parent is not None) + enabled = False + if mirror and default_parent: + enabled = True + if wcurl and (not same_base(mirror, wcurl)): + enabled = False + return enabled def mirror_relocate(oldparent, newparent, url, wcpath): svn = SVN(noauth=True) @@ -40,3 +70,39 @@ def checkout_url(url): if mirror is not None and default_parent is not None: return relocate_path(default_parent, mirror, url) return url + +def autoswitch(svn, wcpath, wcurl, newbaseurl=None): + """Switches between mirror, default_parent, or newbaseurl""" + nobase = False + mirror = config.get("global", "mirror") + default_parent = config.get("global", "default_parent") + current = default_parent + if default_parent is None: + raise Error, "the option default_parent from repsys.conf is "\ + "required" + indefault = same_base(default_parent, wcurl) + if not newbaseurl: + if not mirror: + raise Error, "an URL is needed when the option mirror "\ + "from repsys.conf is not set" + if indefault: + chosen = mirror + elif same_base(mirror, wcurl): + current = mirror + chosen = default_parent + else: + nobase = True + else: + if mirror and same_base(mirror, wcurl): + current = mirror + elif indefault: + pass # !!!! + else: + nobase = True + chosen = newbaseurl + if nobase: + raise Error, "the URL of this working copy is not based in "\ + "default_parent nor mirror URLs" + assert current != chosen + newurl = mirror_relocate(current, chosen, wcurl, wcpath) + return newurl -- cgit v1.2.1 From a2a73182ccef6b7e986e475d2b2a314061fbbd78 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Wed, 6 Jun 2007 06:27:06 +0000 Subject: Import "Error" before use it --- RepSys/mirror.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index 6acc839..29b8bf5 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -1,7 +1,7 @@ import os import urlparse -from RepSys import config +from RepSys import Error, config from RepSys.svn import SVN def _normdirurl(url): -- cgit v1.2.1 From 01674a4621a88b56c91ca3ad430a441cf6226c64 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Tue, 12 Jun 2007 18:36:37 +0000 Subject: Don't force "/" at the end of URLs --- RepSys/mirror.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index 29b8bf5..0c45c9e 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -8,7 +8,6 @@ def _normdirurl(url): """normalize url for relocate_path needs""" parsed = urlparse.urlparse(url) path = os.path.normpath(parsed.path) - path += "/" # assuming we always deal with directories newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, path, parsed.params, parsed.query, parsed.fragment)) return newurl @@ -31,7 +30,7 @@ def relocate_path(oldparent, newparent, url): oldparent = _normdirurl(oldparent) newparent = _normdirurl(newparent) url = _normdirurl(url) - subpath = url[len(oldparent):] + subpath = url[len(oldparent)+1:] newurl = _joinurl(newparent, subpath) # subpath usually gets / at begining return newurl -- cgit v1.2.1 From e196e676aa302cd3a1f7b37f259491a8b03cc483 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Thu, 15 Nov 2007 05:30:56 +0000 Subject: Dropped all authenticated access support Subversion authentication has been broken for a long time and the workarounds weren't decent. It will be back in 1.7.x. Also added configuration option svn-command in the global section, allowing to replace the default svn command. And use svn+ssh:// URLs to be in BatchMode, in order to not have any interactivity at all with ssh --- RepSys/mirror.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index 0c45c9e..4fb40ce 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -45,7 +45,7 @@ def enabled(wcurl=None): return enabled def mirror_relocate(oldparent, newparent, url, wcpath): - svn = SVN(noauth=True) + svn = SVN() newurl = relocate_path(oldparent, newparent, url) svn.switch(newurl, url, path=wcpath, relocate="True") return newurl -- cgit v1.2.1 From 05810ef9f0e1dc761317f909146f1a201c876a64 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Wed, 6 Feb 2008 01:34:08 +0000 Subject: Fixed URL normalization to make it compatible with py2.4 In py2.4 the function urlparse doesn't return a "named" tuple. --- RepSys/mirror.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'RepSys/mirror.py') diff --git a/RepSys/mirror.py b/RepSys/mirror.py index 4fb40ce..5b114df 100644 --- a/RepSys/mirror.py +++ b/RepSys/mirror.py @@ -7,16 +7,16 @@ from RepSys.svn import SVN def _normdirurl(url): """normalize url for relocate_path needs""" parsed = urlparse.urlparse(url) - path = os.path.normpath(parsed.path) - newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, path, - parsed.params, parsed.query, parsed.fragment)) + path = os.path.normpath(parsed[2]) + newurl = urlparse.urlunparse((parsed[0], parsed[1], path, + parsed[3], parsed[4], parsed[5])) return newurl def _joinurl(url, relpath): parsed = urlparse.urlparse(url) - newpath = os.path.join(parsed.path, relpath) - newurl = urlparse.urlunparse((parsed.scheme, parsed.netloc, newpath, - parsed.params, parsed.query, parsed.fragment)) + newpath = os.path.join(parsed[2], relpath) + newurl = urlparse.urlunparse((parsed[0], parsed[1], newpath, + parsed[3], parsed[4], parsed[5])) return newurl def same_base(parent, url): -- cgit v1.2.1