Package translate :: Package storage :: Package versioncontrol :: Module svn
[hide private]
[frames] | no frames]

Source Code for Module translate.storage.versioncontrol.svn

  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. 
  7  # 
  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. 
 12  # 
 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. 
 17  # 
 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 
 21   
 22   
 23  from translate.storage.versioncontrol import GenericRevisionControlSystem 
 24  from translate.storage.versioncontrol import run_command 
 25   
 26   
27 -def is_available():
28 """check if svn is installed""" 29 exitcode, output, error = run_command(["svn", "--version"]) 30 return exitcode == 0
31 32
33 -def get_version():
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 # something went wrong above 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 # revert the local copy (remove local changes) 54 command = ["svn", "revert", self.location_abs] 55 exitcode, output_revert, error = run_command(command) 56 # any errors? 57 if exitcode != 0: 58 raise IOError("[SVN] Subversion error running '%s': %s" \ 59 % (command, error)) 60 # update the working copy to the given revision 61 command = ["svn", "update"] 62 if not revision is None: 63 command.extend(["-r", revision]) 64 # the filename is the last argument 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 # the "--with-revprop" argument is support since svn v1.5 81 if author and (get_version() >= (1, 5)): 82 command.extend(["--with-revprop", "translate:author=%s" % author]) 83 # the location is the last argument 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
90 - def getcleanfile(self, revision=None):
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 # the filename is the last argument 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