Package translate :: Package storage :: Package versioncontrol :: Module darcs

[hide private]
[frames] | no frames]

# Source Code for Module translate.storage.versioncontrol.darcs

     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 darcs is installed"""
    29      exitcode, output, error = run_command(["darcs", "--version"])
    30      return exitcode == 0
    31
    32
    33 -class darcs(GenericRevisionControlSystem):
    34      """Class to manage items under revision control of darcs."""
    35
    36      RCS_METADIR = "_darcs"
    37      SCAN_PARENTS = True
    38
    39 -    def update(self, revision=None):
    40          """Does a clean update of the given path
    41
    42          @param revision: ignored for darcs
    43          """
    44          # revert local changes (avoids conflicts)
    45          command = ["darcs", "revert", "--repodir", self.root_dir,
    46                  "-a", self.location_rel]
    47          exitcode, output_revert, error = run_command(command)
    48          if exitcode != 0:
    49              raise IOError("[Darcs] error running '%s': %s" % (command, error))
    50          # pull new patches
    51          command = ["darcs", "pull", "--repodir", self.root_dir, "-a"]
    52          exitcode, output_pull, error = run_command(command)
    53          if exitcode != 0:
    54              raise IOError("[Darcs] error running '%s': %s" % (command, error))
    55          return output_revert + output_pull
    56
    57 -    def commit(self, message=None, author=None):
    58          """Commits the file and supplies the given commit message if present"""
    59          if message is None:
    60              message = ""
    61          # set change message
    62          command = ["darcs", "record", "-a", "--repodir", self.root_dir,
    63                  "--skip-long-comment", "-m", message]
    64          # add the 'author' to the list of arguments if it was given
    65          if author:
    66              command.extend(["--author", author])
    67          # the location of the file is the last argument
    68          command.append(self.location_rel)
    69          exitcode, output_record, error = run_command(command)
    70          if exitcode != 0:
    71              raise IOError("[Darcs] Error running darcs command '%s': %s" \
    72                      % (command, error))
    73          # push changes
    74          command = ["darcs", "push", "-a", "--repodir", self.root_dir]
    75          exitcode, output_push, error = run_command(command)
    76          if exitcode != 0:
    77              raise IOError("[Darcs] Error running darcs command '%s': %s" \
    78                      % (command, error))
    79          return output_record + output_push
    80
    81 -    def getcleanfile(self, revision=None):
    82          """Get a clean version of a file from the darcs repository
    83
    84          @param revision: ignored for darcs
    85          """
    86          import os
    87          filename = os.path.join(self.root_dir, self.RCS_METADIR, 'pristine',
    88                  self.location_rel)
    89          try:
    90              darcs_file = open(filename)
    91              output = darcs_file.read()
    92              darcs_file.close()
    93          except IOError, error:
    94              raise IOError("[Darcs] error reading original file '%s': %s" % \
    95                      (filename, error))
    96          return output
    97