diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-08-30 23:02:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-08-30 23:02:48 +0400 |
commit | fa68f7ff76cea0fa8b818d332da3ec2213623b35 (patch) | |
tree | b888d106df012ab16df7e621b0e6d9e2c33c5cb7 /release | |
parent | fee715f8a99c38df08942f39769e7bc520d848da (diff) |
made python 2.x and 3.x compatible.
Diffstat (limited to 'release')
-rwxr-xr-x | release/datafiles/datatoc.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/release/datafiles/datatoc.py b/release/datafiles/datatoc.py index 805d7205651..ea72870f2a0 100755 --- a/release/datafiles/datatoc.py +++ b/release/datafiles/datatoc.py @@ -1,5 +1,6 @@ -#!/usr/bin/python3 -# +#!/usr/bin/python +# -*- coding: utf-8 -*- + # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or @@ -23,10 +24,10 @@ # # ***** END GPL LICENCE BLOCK ***** -import sys +import sys, os if len(sys.argv) < 2: - print("Usage: datatoc <data_file>") + sys.stdout.write("Usage: datatoc <data_file>\n") sys.exit(1) filename = sys.argv[1] @@ -34,37 +35,38 @@ filename = sys.argv[1] try: fpin = open(filename, "rb"); except: - print("Unable to open input <{0}>".format(sys.argv[1])) + sys.stdout.write("Unable to open input %s\n" % sys.argv[1]) sys.exit(1) -size = fpin.seek(0, 2) +fpin.seek(0, os.SEEK_END) +size = fpin.tell() fpin.seek(0) if filename[0] == ".": filename = filename[1:] cname = filename + ".c" -print("Making C file <{0}>".format(cname)) +sys.stdout.write("Making C file <%s>\n" % cname) filename = filename.replace(".", "_") - +sys.stdout.write(str(size)) try: fpout = open(cname, "w") except: - print("Unable to open output <{0}>".format(cname)) + sys.stdout.write("Unable to open output %s\n" % cname) sys.exit(1) -fpout.write("/* DataToC output of file <{0}> */\n\n".format(filename)) -fpout.write("int datatoc_{0}_size= {1};\n".format(filename, size)) +fpout.write("/* DataToC output of file <%s> */\n\n" % filename) +fpout.write("int datatoc_%s_size= %d;\n" % (filename, size)) -fpout.write("char datatoc_{0}[]= {{\n".format(filename)) +fpout.write("char datatoc_%s[]= {\n" % filename) while size > 0: size -= 1 if size % 32 == 31: fpout.write("\n") - fpout.write("{0:3d},".format(ord(fpin.read(1)))) + fpout.write("%.2d," % ord(fpin.read(1))) fpout.write("\n 0};\n\n") |