aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/mirror.py
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2008-07-17 12:24:21 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2008-07-17 12:24:21 +0000
commit5c7f585c08c8ffb944095ae031fbf82a54ba13bc (patch)
treec3b1eaad57b0518416b5adb59ac51576716ebf1e /RepSys/mirror.py
parent0af96a9eb0e69191d5fb5d5dcfa35a287bcc31b4 (diff)
downloadmgarepo-5c7f585c08c8ffb944095ae031fbf82a54ba13bc.tar
mgarepo-5c7f585c08c8ffb944095ae031fbf82a54ba13bc.tar.gz
mgarepo-5c7f585c08c8ffb944095ae031fbf82a54ba13bc.tar.bz2
mgarepo-5c7f585c08c8ffb944095ae031fbf82a54ba13bc.tar.xz
mgarepo-5c7f585c08c8ffb944095ae031fbf82a54ba13bc.zip
Allow specifying distro branches without using complete URLs
Added the configuration option "repository", which will have the URL to the root of the repository. The change also allowed using mirrors in all the read-only commands.
Diffstat (limited to 'RepSys/mirror.py')
-rw-r--r--RepSys/mirror.py81
1 files changed, 48 insertions, 33 deletions
diff --git a/RepSys/mirror.py b/RepSys/mirror.py
index 20570d5..09d72de 100644
--- a/RepSys/mirror.py
+++ b/RepSys/mirror.py
@@ -1,10 +1,16 @@
+import sys
import os
import urlparse
+import urllib
-from RepSys import Error, config
+from RepSys import Error, config, layout
from RepSys.svn import SVN
-def _normdirurl(url):
+def mirror_url():
+ mirror = config.get("global", "mirror")
+ return mirror
+
+def normalize_path(url):
"""normalize url for relocate_path needs"""
parsed = urlparse.urlparse(url)
path = os.path.normpath(parsed[2])
@@ -19,31 +25,51 @@ def _joinurl(url, relpath):
parsed[3], parsed[4], parsed[5]))
return newurl
+
+def strip_username(url):
+ parsed = list(urlparse.urlparse(url))
+ _, parsed[1] = urllib.splituser(parsed[1])
+ newurl = urlparse.urlunparse(parsed)
+ 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
+ parent = normalize_path(parent)
+ url = normalize_path(url)
+ url = strip_username(url)
return url.startswith(parent)
def relocate_path(oldparent, newparent, url):
- oldparent = _normdirurl(oldparent)
- newparent = _normdirurl(newparent)
- url = _normdirurl(url)
+ oldparent = normalize_path(oldparent)
+ newparent = normalize_path(newparent)
+ url = normalize_path(url)
subpath = url[len(oldparent)+1:]
newurl = _joinurl(newparent, subpath) # subpath usually gets / at begining
return newurl
def enabled(wcurl=None):
- mirror = config.get("global", "mirror")
- default_parent = config.get("global", "default_parent")
+ mirror = mirror_url()
+ repository = layout.repository_url()
enabled = False
- if mirror and default_parent:
+ if mirror and repository:
enabled = True
- if wcurl and (not same_base(mirror, wcurl)):
+ if wcurl and not same_base(mirror, wcurl):
enabled = False
return enabled
+def using_on(url):
+ """returnes True if the URL points to the mirror repository"""
+ mirror = mirror_url()
+ if mirror:
+ using = same_base(mirror, url)
+ else:
+ using = False
+ return using
+
+def info(url, stream=sys.stderr):
+ if using_on(url):
+ stream.write("using mirror\n")
+
def mirror_relocate(oldparent, newparent, url, wcpath):
svn = SVN()
newurl = relocate_path(oldparent, newparent, url)
@@ -52,34 +78,23 @@ def mirror_relocate(oldparent, newparent, url, wcpath):
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)
+ newurl = mirror_relocate(mirror_url(), layout.repository_url(), 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)
+ newurl = mirror_relocate(layout.repository_url(), mirror_url(), 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
-
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 "\
+ mirror = mirror_url()
+ repository = layout.repository_url()
+ current = repository
+ if repository is None:
+ raise Error, "the option repository from repsys.conf is "\
"required"
- indefault = same_base(default_parent, wcurl)
+ indefault = same_base(repository, wcurl)
if not newbaseurl:
if not mirror:
raise Error, "an URL is needed when the option mirror "\
@@ -88,7 +103,7 @@ def autoswitch(svn, wcpath, wcurl, newbaseurl=None):
chosen = mirror
elif same_base(mirror, wcurl):
current = mirror
- chosen = default_parent
+ chosen = repository
else:
nobase = True
else:
@@ -101,7 +116,7 @@ def autoswitch(svn, wcpath, wcurl, newbaseurl=None):
chosen = newbaseurl
if nobase:
raise Error, "the URL of this working copy is not based in "\
- "default_parent nor mirror URLs"
+ "repository nor mirror URLs"
assert current != chosen
newurl = mirror_relocate(current, chosen, wcurl, wcpath)
return newurl