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