for git v1.5.2 (and below): chdir to the directory of the target file before executin...
[translate_toolkit.git] / storage / versioncontrol / svn.py
blobaa8f13d337b39ea52e96e645782af332786b18a6
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
27 def is_available():
28 """check if svn is installed"""
29 exitcode, output, error = run_command(["svn", "--version"])
30 return exitcode == 0
33 class svn(GenericRevisionControlSystem):
34 """Class to manage items under revision control of Subversion."""
36 RCS_METADIR = ".svn"
37 SCAN_PARENTS = False
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)
44 # any errors?
45 if exitcode != 0:
46 raise IOError("[SVN] Subversion error running '%s': %s" \
47 % (command, error))
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)
55 if exitcode != 0:
56 raise IOError("[SVN] Subversion error running '%s': %s" \
57 % (command, error))
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"]
63 if message:
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)
68 if exitcode != 0:
69 raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error))
70 return output
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)
80 if exitcode != 0:
81 raise IOError("[SVN] Subversion error running '%s': %s" % (command, error))
82 return output