summaryrefslogtreecommitdiff
path: root/gio/data-to-c.py
blob: 1724f7dd15b5a9bd46403601d2014fc9ccbb5fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python

import sys

if len(sys.argv) < 4:
    print("Usage: {0} <filename> <variable> <output>")

with open(sys.argv[1], "rb") as f:
    in_data = f.read().decode("utf-8", "backslashreplace")
b = [r"\x{:02x}".format(ord(c)) for c in in_data]

out_data = 'const char {0}[] = "'.format(sys.argv[2])
out_data += "".join(b) + '";\n'

with open(sys.argv[3], "w") as f:
    f.write(out_data)