Index: Source/build/scripts/xxd.py |
diff --git a/Tools/Scripts/print-layout-test-types b/Source/build/scripts/xxd.py |
old mode 100755 |
new mode 100644 |
similarity index 70% |
copy from Tools/Scripts/print-layout-test-types |
copy to Source/build/scripts/xxd.py |
index 3cc36c64bb26ebaf0e173e0dad4ce8c9b0b1cd52..97d4062b3bb7dd33b4402ce6c837cfc9f06cb05d |
--- a/Tools/Scripts/print-layout-test-types |
+++ b/Source/build/scripts/xxd.py |
@@ -1,5 +1,3 @@ |
-#!/usr/bin/python |
-# |
# Copyright (C) 2013 Google Inc. All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
@@ -28,9 +26,28 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+"""Represent a file as a C++ constant string.""" |
+ |
+import optparse |
import sys |
-from webkitpy.common import host |
-from webkitpy.layout_tests import print_layout_test_types |
-print_layout_test_types.main(host.Host(), sys.argv[1:]) |
+def parse_arguments(): |
+ parser = optparse.OptionParser() |
+ _, args = parser.parse_args() |
+ return args |
Nico
2013/10/25 04:14:31
Why not just `return sys.argv[1:]`? What does the
Nils Barth (inactive)
2013/10/25 07:22:36
Good point, thanks!
I was just using optparse by d
|
+ |
+ |
+def main(): |
+ variable_name, input_filename, output_filename = parse_arguments() |
+ with open(input_filename) as input_file: |
+ input_text = input_file.read() |
+ hex_values = ['0x{:02x}'.format(ord(char)) for char in input_text] |
+ output = 'const unsigned char %s[] = {\n%s\n};\n' % ( |
+ variable_name, ', '.join(hex_values)) |
+ with open(output_filename, 'w') as output_file: |
+ output_file.write(output) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |