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 import translate
.storage
.versioncontrol
24 from translate
.storage
.versioncontrol
import run_command
25 from translate
.storage
.versioncontrol
import GenericRevisionControlSystem
27 class bzr(GenericRevisionControlSystem
):
28 """Class to manage items under revision control of bzr."""
33 def update(self
, revision
=None):
34 """Does a clean update of the given path"""
36 command
= ["bzr", "revert", self
.location_abs
]
37 exitcode
, output_revert
, error
= run_command(command
)
39 raise IOError("[BZR] revert of '%s' failed: %s" \
40 % (self
.location_abs
, error
))
42 command
= ["bzr", "pull"]
43 exitcode
, output_pull
, error
= run_command(command
)
45 raise IOError("[BZR] pull of '%s' failed: %s" \
46 % (self
.location_abs
, error
))
47 return output_revert
+ output_pull
49 def commit(self
, message
=None):
50 """Commits the file and supplies the given commit message if present"""
52 command
= ["bzw", "commit"]
54 command
.extend(["-m", message
])
55 # the filename is the last argument
56 command
.append(self
.location_abs
)
57 exitcode
, output_commit
, error
= run_command(command
)
59 raise IOError("[BZR] commit of '%s' failed: %s" \
60 % (self
.location_abs
, error
))
62 command
= ["bzr", "push"]
63 exitcode
, output_push
, error
= run_command(command
)
65 raise IOError("[BZR] push of '%s' failed: %s" \
66 % (self
.location_abs
, error
))
67 return output_commit
+ output_push
69 def getcleanfile(self
, revision
=None):
70 """Get a clean version of a file from the bzr repository"""
72 command
= ["bzr", "cat", self
.location_abs
]
73 exitcode
, output
, error
= run_command(command
)
75 raise IOError("[BZR] cat failed for '%s': %s" \
76 % (self
.location_abs
, error
))