1 | import os |
---|
2 | import urlparse |
---|
3 | |
---|
4 | from RepSys import config |
---|
5 | from RepSys.svn import SVN |
---|
6 | |
---|
7 | def relocate_path(oldparent, newparent, url): |
---|
8 | subpath = url[len(oldparent)-1:] |
---|
9 | newurl = newparent + "/" + subpath # subpath usually gets / at begining |
---|
10 | return newurl |
---|
11 | |
---|
12 | def enabled(): |
---|
13 | mirror = config.get("global", "mirror") |
---|
14 | default_parent = config.get("global", "default_parent") |
---|
15 | return (mirror is not None and |
---|
16 | default_parent is not None) |
---|
17 | |
---|
18 | def mirror_relocate(oldparent, newparent, url, wcpath): |
---|
19 | svn = SVN(noauth=True) |
---|
20 | newurl = relocate_path(oldparent, newparent, url) |
---|
21 | svn.switch(newurl, url, path=wcpath, relocate="True") |
---|
22 | return newurl |
---|
23 | |
---|
24 | def switchto_parent(svn, url, path): |
---|
25 | """Relocates the working copy to default_parent""" |
---|
26 | mirror = config.get("global", "mirror") |
---|
27 | default_parent = config.get("global", "default_parent") |
---|
28 | newurl = mirror_relocate(mirror, default_parent, url, path) |
---|
29 | return newurl |
---|
30 | |
---|
31 | def switchto_mirror(svn, url, path): |
---|
32 | mirror = config.get("global", "mirror") |
---|
33 | default_parent = config.get("global", "default_parent") |
---|
34 | newurl = mirror_relocate(default_parent, mirror, url, path) |
---|
35 | return newurl |
---|
36 | |
---|
37 | def checkout_url(url): |
---|
38 | mirror = config.get("global", "mirror") |
---|
39 | default_parent = config.get("global", "default_parent") |
---|
40 | if mirror is not None and default_parent is not None: |
---|
41 | return relocate_path(default_parent, mirror, url) |
---|
42 | return url |
---|