aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/mirror.py
blob: a24f59468cb413dfc9595675c1bcd949926a3215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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