1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from translate.storage.versioncontrol import GenericRevisionControlSystem
24 from translate.storage.versioncontrol import run_command
25
26
28 """check if svn is installed"""
29 exitcode, output, error = run_command(["svn", "--version"])
30 return exitcode == 0
31
32
34 """return a tuple of (major, minor) for the installed subversion client"""
35 command = ["svn", "--version", "--quiet"]
36 exitcode, output, error = run_command(command)
37 if exitcode == 0:
38 major, minor = output.strip().split(".")[0:2]
39 if (major.isdigit() and minor.isdigit()):
40 return (int(major), int(minor))
41
42 return (0, 0)
43
44
45 -class svn(GenericRevisionControlSystem):
46 """Class to manage items under revision control of Subversion."""
47
48 RCS_METADIR = ".svn"
49 SCAN_PARENTS = False
50
51 - def update(self, revision=None):
52 """update the working copy - remove local modifications if necessary"""
53
54 command = ["svn", "revert", self.location_abs]
55 exitcode, output_revert, error = run_command(command)
56
57 if exitcode != 0:
58 raise IOError("[SVN] Subversion error running '%s': %s" \
59 % (command, error))
60
61 command = ["svn", "update"]
62 if not revision is None:
63 command.extend(["-r", revision])
64
65 command.append(self.location_abs)
66 exitcode, output_update, error = run_command(command)
67 if exitcode != 0:
68 raise IOError("[SVN] Subversion error running '%s': %s" \
69 % (command, error))
70 return output_revert + output_update
71
72 - def commit(self, message=None, author=None):
73 """commit the file and return the given message if present
74
75 the 'author' parameter is used for revision property 'translate:author'
76 """
77 command = ["svn", "-q", "--non-interactive", "commit"]
78 if message:
79 command.extend(["-m", message])
80
81 if author and (get_version() >= (1, 5)):
82 command.extend(["--with-revprop", "translate:author=%s" % author])
83
84 command.append(self.location_abs)
85 exitcode, output, error = run_command(command)
86 if exitcode != 0:
87 raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error))
88 return output
89
91 """return the content of the 'head' revision of the file"""
92 command = ["svn", "cat"]
93 if not revision is None:
94 command.extend(["-r", revision])
95
96 command.append(self.location_abs)
97 exitcode, output, error = run_command(command)
98 if exitcode != 0:
99 raise IOError("[SVN] Subversion error running '%s': %s" % (command, error))
100 return output
101