Mercurial > treepkg > treepkg
annotate treepkg/subversion.py @ 208:1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
checkout and update
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 06 Nov 2008 15:59:50 +0000 |
parents | 570ac81865be |
children | 6bac65dcf258 |
rev | line source |
---|---|
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
1 # Copyright (C) 2007, 2008 by Intevation GmbH |
0 | 2 # Authors: |
3 # Bernhard Herzog <bh@intevation.de> | |
4 # | |
5 # This program is free software under the GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 """Collection of subversion utility functions""" | |
9 | |
10 import os | |
11 | |
12 import run | |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
13 from cmdexpand import cmdexpand |
0 | 14 from util import extract_value_for_key |
15 | |
16 | |
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
17 def checkout(url, localdir, revision=None, recurse=True): |
0 | 18 """Runs svn to checkout the repository at url into the localdir""" |
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
19 args = [] |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
20 if revision: |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
21 args.extend(["--revision", revision]) |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
22 if not recurse: |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
23 args.append("-N") |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
24 run.call(cmdexpand("svn checkout -q @args $url $localdir", **locals())) |
0 | 25 |
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
26 def update(localdir, revision=None, recurse=True): |
79
570ac81865be
Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents:
45
diff
changeset
|
27 """Runs svn update on the localdir. |
570ac81865be
Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents:
45
diff
changeset
|
28 The parameter revision, if given, is passed to svn as the value of |
570ac81865be
Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents:
45
diff
changeset
|
29 the --revision option. |
570ac81865be
Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents:
45
diff
changeset
|
30 """ |
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
31 args = [] |
79
570ac81865be
Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents:
45
diff
changeset
|
32 if revision: |
208
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
33 args.extend(["--revision", revision]) |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
34 if not recurse: |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
35 args.append("-N") |
1527c37bd7aa
Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents:
79
diff
changeset
|
36 run.call(cmdexpand("svn update -q @args $localdir", **locals())) |
0 | 37 |
38 def export(src, dest): | |
39 """Runs svn export src dest""" | |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
40 run.call(cmdexpand("svn export -q $src $dest", **locals())) |
0 | 41 |
42 def last_changed_revision(svn_working_copy): | |
43 """return the last changed revision of an SVN working copy as an int""" | |
44 # Make sure we run svn under the C locale to avoid localized | |
45 # messages | |
46 env = os.environ.copy() | |
47 env["LANG"] = "C" | |
48 | |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
49 output = run.capture_output(cmdexpand("svn info $svn_working_copy", |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
50 **locals()), |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
51 env=env) |
0 | 52 return int(extract_value_for_key(output.splitlines(), |
53 "Last Changed Rev:")) |