1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import translate.storage.versioncontrol
24 from translate.storage.versioncontrol import run_command
25 from translate.storage.versioncontrol import GenericRevisionControlSystem
26
27
29 """check if bzr is installed"""
30 exitcode, output, error = run_command(["bzr", "version"])
31 return exitcode == 0
32
34 """return a tuple of (major, minor) for the installed bazaar client"""
35 import re
36 command = ["bzr", "--version"]
37 exitcode, output, error = run_command(command)
38 if exitcode == 0:
39 version_line = output.splitlines()[0]
40 version_match = re.search(r"\d+\.\d+", version_line)
41 if version_match:
42 major, minor = version_match.group().split(".")
43 if (major.isdigit() and minor.isdigit()):
44 return (int(major), int(minor))
45
46 return (0, 0)
47
48
49 -class bzr(GenericRevisionControlSystem):
50 """Class to manage items under revision control of bzr."""
51
52 RCS_METADIR = ".bzr"
53 SCAN_PARENTS = True
54
55 - def update(self, revision=None):
56 """Does a clean update of the given path"""
57
58 command = ["bzr", "revert", self.location_abs]
59 exitcode, output_revert, error = run_command(command)
60 if exitcode != 0:
61 raise IOError("[BZR] revert of '%s' failed: %s" \
62 % (self.location_abs, error))
63
64 command = ["bzr", "pull"]
65 exitcode, output_pull, error = run_command(command)
66 if exitcode != 0:
67 raise IOError("[BZR] pull of '%s' failed: %s" \
68 % (self.location_abs, error))
69 return output_revert + output_pull
70
71 - def commit(self, message=None, author=None):
72 """Commits the file and supplies the given commit message if present"""
73
74 command = ["bzr", "commit"]
75 if message:
76 command.extend(["-m", message])
77
78 if author and (get_version() >= (0, 91)):
79 command.extend(["--author", author])
80
81 command.append(self.location_abs)
82 exitcode, output_commit, error = run_command(command)
83 if exitcode != 0:
84 raise IOError("[BZR] commit of '%s' failed: %s" \
85 % (self.location_abs, error))
86
87 command = ["bzr", "push"]
88 exitcode, output_push, error = run_command(command)
89 if exitcode != 0:
90 raise IOError("[BZR] push of '%s' failed: %s" \
91 % (self.location_abs, error))
92 return output_commit + output_push
93
95 """Get a clean version of a file from the bzr repository"""
96
97 command = ["bzr", "cat", self.location_abs]
98 exitcode, output, error = run_command(command)
99 if exitcode != 0:
100 raise IOError("[BZR] cat failed for '%s': %s" \
101 % (self.location_abs, error))
102 return output
103