2 # -*- coding: utf-8 -*-
4 # Copyright 2004-2007 Zuza Software Foundation
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
28 """check if svn is installed"""
29 exitcode
, output
, error
= run_command(["svn", "--version"])
33 class svn(GenericRevisionControlSystem
):
34 """Class to manage items under revision control of Subversion."""
39 def update(self
, revision
=None):
40 """update the working copy - remove local modifications if necessary"""
41 # revert the local copy (remove local changes)
42 command
= ["svn", "revert", self
.location_abs
]
43 exitcode
, output_revert
, error
= run_command(command
)
46 raise IOError("[SVN] Subversion error running '%s': %s" \
48 # update the working copy to the given revision
49 command
= ["svn", "update"]
50 if not revision
is None:
51 command
.extend(["-r", revision
])
52 # the filename is the last argument
53 command
.append(self
.location_abs
)
54 exitcode
, output_update
, error
= run_command(command
)
56 raise IOError("[SVN] Subversion error running '%s': %s" \
58 return output_revert
+ output_update
60 def commit(self
, message
=None):
61 """commit the file and return the given message if present"""
62 command
= ["svn", "-q", "--non-interactive", "commit"]
64 command
.extend(["-m", message
])
65 # the location is the last argument
66 command
.append(self
.location_abs
)
67 exitcode
, output
, error
= run_command(command
)
69 raise IOError("[SVN] Error running SVN command '%s': %s" % (command
, error
))
72 def getcleanfile(self
, revision
=None):
73 """return the content of the 'head' revision of the file"""
74 command
= ["svn", "cat"]
75 if not revision
is None:
76 command
.extend(["-r", revision
])
77 # the filename is the last argument
78 command
.append(self
.location_abs
)
79 exitcode
, output
, error
= run_command(command
)
81 raise IOError("[SVN] Subversion error running '%s': %s" % (command
, error
))