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

Unified Diff: Source/build/scripts/xxd.py

Issue 42793005: Port xxd.pl to xxd.py (Perl to Python) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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())

Powered by Google App Engine
This is Rietveld 408576698