fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / versioncontrol / svn.py
blobb454c0c5a3ce8c9fdd9078379dd59b745728ad00
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2004-2007 Zuza Software Foundation
5 #
6 # This file is part of translate.
8 # translate is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # translate is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 from translate.storage.versioncontrol import run_command
24 from translate.storage.versioncontrol import GenericRevisionControlSystem
26 class svn(GenericRevisionControlSystem):
27 """Class to manage items under revision control of Subversion."""
29 RCS_METADIR = ".svn"
30 SCAN_PARENTS = False
32 def update(self, revision=None):
33 """update the working copy - remove local modifications if necessary"""
34 # revert the local copy (remove local changes)
35 command = ["svn", "revert", self.location_abs]
36 exitcode, output_revert, error = run_command(command)
37 # any errors?
38 if exitcode != 0:
39 raise IOError("[SVN] Subversion error running '%s': %s" \
40 % (command, error))
41 # update the working copy to the given revision
42 command = ["svn", "update"]
43 if not revision is None:
44 command.extend(["-r", revision])
45 # the filename is the last argument
46 command.append(self.location_abs)
47 exitcode, output_update, error = run_command(command)
48 if exitcode != 0:
49 raise IOError("[SVN] Subversion error running '%s': %s" \
50 % (command, error))
51 return output_revert + output_update
53 def commit(self, message=None):
54 """commit the file and return the given message if present"""
55 command = ["svn", "-q", "--non-interactive", "commit"]
56 if message:
57 command.extend(["-m", message])
58 # the location is the last argument
59 command.append(self.location_abs)
60 exitcode, output, error = run_command(command)
61 if exitcode != 0:
62 raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error))
63 return output
65 def getcleanfile(self, revision=None):
66 """return the content of the 'head' revision of the file"""
67 command = ["svn", "cat"]
68 if not revision is None:
69 command.extend(["-r", revision])
70 # the filename is the last argument
71 command.append(self.location_abs)
72 exitcode, output, error = run_command(command)
73 if exitcode != 0:
74 raise IOError("[SVN] Subversion error running '%s': %s" % (command, error))
75 return output