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