translate.storage.versioncontrol.svn

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 run_command
     24  from translate.storage.versioncontrol import GenericRevisionControlSystem
     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 -def get_version():
     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      # something went wrong above
     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          # revert the local copy (remove local changes)
     53          command = ["svn", "revert", self.location_abs]
     54          exitcode, output_revert, error = run_command(command)
     55          # any errors?
     56          if exitcode != 0:
     57              raise IOError("[SVN] Subversion error running '%s': %s" \
     58                      % (command, error))
     59          # update the working copy to the given revision
     60          command = ["svn", "update"]
     61          if not revision is None:
     62              command.extend(["-r", revision])
     63          # the filename is the last argument
     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          # the "--with-revprop" argument is support since svn v1.5
     80          if author and (get_version() >= (1, 5)):
     81              command.extend(["--with-revprop", "translate:author=%s" % author])
     82          # the location is the last argument
     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
     89 -    def getcleanfile(self, revision=None):
     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          # the filename is the last argument
     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