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
28 """check if darcs is installed"""
29 exitcode
, output_revert
, error
= run_command(["darcs", "--version"])
33 class darcs(GenericRevisionControlSystem
):
34 """Class to manage items under revision control of darcs."""
36 RCS_METADIR
= "_darcs"
39 def update(self
, revision
=None):
40 """Does a clean update of the given path
42 @param revision: ignored for darcs
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
)
49 raise IOError("[Darcs] error running '%s': %s" % (command
, error
))
51 command
= ["darcs", "pull", "--repodir", self
.root_dir
, "-a"]
52 exitcode
, output_pull
, error
= run_command(command
)
54 raise IOError("[Darcs] error running '%s': %s" % (command
, error
))
55 return output_revert
+ output_pull
57 def commit(self
, message
=None):
58 """Commits the file and supplies the given commit message if present"""
62 command
= ["darcs", "record", "-a", "--repodir", self
.root_dir
,
63 "--skip-long-comment", "-m", message
, self
.location_rel
]
64 exitcode
, output_record
, error
= run_command(command
)
66 raise IOError("[Darcs] Error running darcs command '%s': %s" \
69 command
= ["darcs", "push", "-a", "--repodir", self
.root_dir
]
70 exitcode
, output_push
, error
= run_command(command
)
72 raise IOError("[Darcs] Error running darcs command '%s': %s" \
74 return output_record
+ output_push
76 def getcleanfile(self
, revision
=None):
77 """Get a clean version of a file from the darcs repository
79 @param revision: ignored for darcs
82 filename
= os
.path
.join(self
.root_dir
, self
.RCS_METADIR
, 'pristine',
85 darcs_file
= open(filename
)
86 output
= darcs_file
.read()
88 except IOError, error
:
89 raise IOError("[Darcs] error reading original file '%s': %s" % \