OLD | NEW |
1 # Copyright (c) 2010 Google Inc. All rights reserved. | 1 # Copyright (c) 2010 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 13 matching lines...) Expand all Loading... |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import os | 29 import os |
30 import tempfile | 30 import tempfile |
31 | 31 |
32 | 32 |
33 class PrettyPatch(object): | 33 class PrettyPatch(object): |
| 34 |
34 def __init__(self, executive): | 35 def __init__(self, executive): |
35 self._executive = executive | 36 self._executive = executive |
36 | 37 |
37 def pretty_diff_file(self, diff): | 38 def pretty_diff_file(self, diff): |
38 # Diffs can contain multiple text files of different encodings | 39 # Diffs can contain multiple text files of different encodings |
39 # so we always deal with them as byte arrays, not unicode strings. | 40 # so we always deal with them as byte arrays, not unicode strings. |
40 assert(isinstance(diff, str)) | 41 assert(isinstance(diff, str)) |
41 pretty_diff = self.pretty_diff(diff) | 42 pretty_diff = self.pretty_diff(diff) |
42 diff_file = tempfile.NamedTemporaryFile(suffix=".html") | 43 diff_file = tempfile.NamedTemporaryFile(suffix=".html") |
43 diff_file.write(pretty_diff) | 44 diff_file.write(pretty_diff) |
(...skipping 11 matching lines...) Expand all Loading... |
55 prettify_path = os.path.join(pretty_patch_path, "prettify.rb") | 56 prettify_path = os.path.join(pretty_patch_path, "prettify.rb") |
56 args = [ | 57 args = [ |
57 "ruby", | 58 "ruby", |
58 "-I", | 59 "-I", |
59 pretty_patch_path, | 60 pretty_patch_path, |
60 prettify_path, | 61 prettify_path, |
61 ] | 62 ] |
62 # PrettyPatch does not modify the encoding of the diff output | 63 # PrettyPatch does not modify the encoding of the diff output |
63 # so we can't expect it to be utf-8. | 64 # so we can't expect it to be utf-8. |
64 return self._executive.run_command(args, input=diff, decode_output=False
) | 65 return self._executive.run_command(args, input=diff, decode_output=False
) |
OLD | NEW |