Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1172)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkit-patch

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 Code Aurora Forum. All rights reserved. 2 # Copyright (c) 2011 Code Aurora Forum. All rights reserved.
3 # Copyright (c) 2010 Google Inc. All rights reserved. 3 # Copyright (c) 2010 Google Inc. All rights reserved.
4 # Copyright (c) 2009 Apple Inc. All rights reserved. 4 # Copyright (c) 2009 Apple Inc. All rights reserved.
5 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) 5 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
6 # 6 #
7 # Redistribution and use in source and binary forms, with or without 7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are 8 # modification, are permitted provided that the following conditions are
9 # met: 9 # met:
10 # 10 #
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 from webkitpy.common.system.logutils import configure_logging 43 from webkitpy.common.system.logutils import configure_logging
44 from webkitpy.tool.webkit_patch import WebKitPatch 44 from webkitpy.tool.webkit_patch import WebKitPatch
45 45
46 # A StreamWriter will by default try to encode all objects passed 46 # A StreamWriter will by default try to encode all objects passed
47 # to write(), so when passed a raw string already encoded as utf8, 47 # to write(), so when passed a raw string already encoded as utf8,
48 # it will blow up with an UnicodeDecodeError. This does not match 48 # it will blow up with an UnicodeDecodeError. This does not match
49 # the default behaviour of writing to sys.stdout, so we intercept 49 # the default behaviour of writing to sys.stdout, so we intercept
50 # the case of writing raw strings and make sure StreamWriter gets 50 # the case of writing raw strings and make sure StreamWriter gets
51 # input that it can handle. 51 # input that it can handle.
52
53
52 class ForgivingUTF8Writer(codecs.lookup('utf-8')[-1]): 54 class ForgivingUTF8Writer(codecs.lookup('utf-8')[-1]):
55
53 def write(self, object): 56 def write(self, object):
54 if isinstance(object, str): 57 if isinstance(object, str):
55 # Assume raw strings are utf-8 encoded. If this line 58 # Assume raw strings are utf-8 encoded. If this line
56 # fails with an UnicodeDecodeError, our assumption was 59 # fails with an UnicodeDecodeError, our assumption was
57 # wrong, and the stacktrace should show you where we 60 # wrong, and the stacktrace should show you where we
58 # write non-Unicode/UTF-8 data (which we shouldn't). 61 # write non-Unicode/UTF-8 data (which we shouldn't).
59 object = object.decode('utf-8') 62 object = object.decode('utf-8')
60 return codecs.StreamWriter.write(self, object) 63 return codecs.StreamWriter.write(self, object)
61 64
62 # By default, sys.stdout assumes ascii encoding. Since our messages can 65 # By default, sys.stdout assumes ascii encoding. Since our messages can
63 # contain unicode strings (as with some peoples' names) we need to apply 66 # contain unicode strings (as with some peoples' names) we need to apply
64 # the utf-8 codec to prevent throwing and exception. 67 # the utf-8 codec to prevent throwing and exception.
65 # Not having this was the cause of https://bugs.webkit.org/show_bug.cgi?id=63452 . 68 # Not having this was the cause of https://bugs.webkit.org/show_bug.cgi?id=63452 .
66 sys.stdout = ForgivingUTF8Writer(sys.stdout) 69 sys.stdout = ForgivingUTF8Writer(sys.stdout)
67 70
68 _log = logging.getLogger("webkit-patch") 71 _log = logging.getLogger("webkit-patch")
69 72
73
70 def main(): 74 def main():
71 # This is a hack to let us enable DEBUG logging as early as possible. 75 # This is a hack to let us enable DEBUG logging as early as possible.
72 # Note this can't be ternary as versioning.check_version() 76 # Note this can't be ternary as versioning.check_version()
73 # hasn't run yet and this python might be older than 2.5. 77 # hasn't run yet and this python might be older than 2.5.
74 if set(["-v", "--verbose"]).intersection(set(sys.argv)): 78 if set(["-v", "--verbose"]).intersection(set(sys.argv)):
75 logging_level = logging.DEBUG 79 logging_level = logging.DEBUG
76 else: 80 else:
77 logging_level = logging.INFO 81 logging_level = logging.INFO
78 configure_logging(logging_level=logging_level) 82 configure_logging(logging_level=logging_level)
79 WebKitPatch(os.path.abspath(__file__)).main() 83 WebKitPatch(os.path.abspath(__file__)).main()
80 84
81 85
82 if __name__ == "__main__": 86 if __name__ == "__main__":
83 try: 87 try:
84 main() 88 main()
85 except KeyboardInterrupt: 89 except KeyboardInterrupt:
86 sys.exit(signal.SIGINT + 128) 90 sys.exit(signal.SIGINT + 128)
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/run-bindings-tests ('k') | third_party/WebKit/Tools/Scripts/webkitpy/bindings/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698