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
26 class darcs(GenericRevisionControlSystem
):
27 """Class to manage items under revision control of darcs."""
29 RCS_METADIR
= "_darcs"
32 def update(self
, revision
=None):
33 """Does a clean update of the given path
35 @param revision: ignored for darcs
37 # revert local changes (avoids conflicts)
38 command
= ["darcs", "revert", "--repodir", self
.root_dir
,
39 "-a", self
.location_rel
]
40 exitcode
, output_revert
, error
= run_command(command
)
42 raise IOError("[Darcs] error running '%s': %s" % (command
, error
))
44 command
= ["darcs", "pull", "--repodir", self
.root_dir
, "-a"]
45 exitcode
, output_pull
, error
= run_command(command
)
47 raise IOError("[Darcs] error running '%s': %s" % (command
, error
))
48 return output_revert
+ output_pull
50 def commit(self
, message
=None):
51 """Commits the file and supplies the given commit message if present"""
55 command
= ["darcs", "record", "-a", "--repodir", self
.root_dir
,
56 "--skip-long-comment", "-m", message
, self
.location_rel
]
57 exitcode
, output_record
, error
= run_command(command
)
59 raise IOError("[Darcs] Error running darcs command '%s': %s" \
62 command
= ["darcs", "push", "-a", "--repodir", self
.root_dir
]
63 exitcode
, output_push
, error
= run_command(command
)
65 raise IOError("[Darcs] Error running darcs command '%s': %s" \
67 return output_record
+ output_push
69 def getcleanfile(self
, revision
=None):
70 """Get a clean version of a file from the darcs repository
72 @param revision: ignored for darcs
75 filename
= os
.path
.join(self
.root_dir
, self
.RCS_METADIR
, 'pristine',
78 darcs_file
= open(filename
)
79 output
= darcs_file
.read()
81 except IOError, error
:
82 raise IOError("[Darcs] error reading original file '%s': %s" % \