summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2016-12-17 17:12:56 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2017-01-05 11:25:18 +0100
commit737e3b175886618eb28b46f3feed218fdad9c517 (patch)
tree5e755481ae5330d7af1ff720e3c4a79cac5467be /TOOLS
parent0e7dd6d4ff3c7510a147ba68f43040828dcf486f (diff)
downloadmpv-737e3b175886618eb28b46f3feed218fdad9c517.tar.bz2
mpv-737e3b175886618eb28b46f3feed218fdad9c517.tar.xz
build: use matroska.py & file2string.py as python modules
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/__init__.py0
-rwxr-xr-xTOOLS/file2string.py14
-rwxr-xr-xTOOLS/matroska.py4
3 files changed, 11 insertions, 7 deletions
diff --git a/TOOLS/__init__.py b/TOOLS/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/TOOLS/__init__.py
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
index 6cdd1a72ae..6f068caa43 100755
--- a/TOOLS/file2string.py
+++ b/TOOLS/file2string.py
@@ -5,23 +5,27 @@
# of every string, so code using the string may need to remove that to get
# the exact contents of the original file.
+from __future__ import unicode_literals
import sys
# Indexing a byte string yields int on Python 3.x, and a str on Python 2.x
def pord(c):
return ord(c) if type(c) == str else c
-def main(infile):
+def file2string(infilename, infile, outfile):
+ outfile.write("// Generated from %s\n\n" % infilename)
+
conv = ['\\' + ("%03o" % c) for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
"0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
+
for c in safe_chars:
conv[ord(c)] = c
for c, esc in ("\nn", "\tt", r"\\", '""'):
conv[ord(c)] = '\\' + esc
for line in infile:
- sys.stdout.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
+ outfile.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
-with open(sys.argv[1], 'rb') as infile:
- sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
- main(infile)
+if __name__ == "__main__":
+ with open(sys.argv[1], 'rb') as infile:
+ main(sys.argv[1], infile, sys.stdout)
diff --git a/TOOLS/matroska.py b/TOOLS/matroska.py
index 6e843560da..3f8ebd7dd6 100755
--- a/TOOLS/matroska.py
+++ b/TOOLS/matroska.py
@@ -285,8 +285,8 @@ parse_elems(elements_ebml, 'EBML')
parse_elems(elements_matroska, 'MATROSKA')
def printf(out, *args):
- out.write(' '.join([str(x) for x in args]))
- out.write('\n')
+ out.write(u' '.join([str(x) for x in args]))
+ out.write(u'\n')
def generate_C_header(out):
printf(out, '// Generated by TOOLS/matroska.py, do not edit manually')