1
0
Fork 0

Fix scripts so they can work with python3 (#10276)

This commit is contained in:
Jan Christoph Uhde 2019-11-18 10:33:34 +01:00 committed by Jan
parent ebf3296e9c
commit f58c1f8abb
2 changed files with 56 additions and 52 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/python #!/usr/bin/env python3
from __future__ import print_function
import csv, sys, os.path, re import csv, sys, os.path, re
# wrap text after x characters # wrap text after x characters
@ -30,7 +31,7 @@ def genJsFile(errors):
+ " var internal = require(\"internal\");\n"\ + " var internal = require(\"internal\");\n"\
+ "\n"\ + "\n"\
+ " internal.errors = {\n" + " internal.errors = {\n"
# print individual errors # print individual errors
i = 0 i = 0
for e in errors: for e in errors:
@ -38,8 +39,8 @@ def genJsFile(errors):
msg = e[2].replace("\n", " ").replace("\\", "").replace("\"", "\\\"") msg = e[2].replace("\n", " ").replace("\\", "").replace("\"", "\\\"")
out = out\ out = out\
+ " " + name.ljust(30) + " : { \"code\" : " + e[1] + ", \"message\" : \"" + msg + "\" }" + " " + name.ljust(30) + " : { \"code\" : " + e[1] + ", \"message\" : \"" + msg + "\" }"
i = i + 1 i = i + 1
if i < len(errors): if i < len(errors):
out = out + ",\n" out = out + ",\n"
@ -90,12 +91,12 @@ def genCHeaderFile(errors):
wiki = "/// Error codes and meanings\n"\ wiki = "/// Error codes and meanings\n"\
+ "/// The following errors might be raised when running ArangoDB:\n"\ + "/// The following errors might be raised when running ArangoDB:\n"\
+ "\n\n" + "\n\n"
header = "#ifndef ARANGODB_BASICS_VOC_ERRORS_H\n"\ header = "#ifndef ARANGODB_BASICS_VOC_ERRORS_H\n"\
+ "#define ARANGODB_BASICS_VOC_ERRORS_H 1\n"\ + "#define ARANGODB_BASICS_VOC_ERRORS_H 1\n"\
+ "\n"\ + "\n"\
+ wiki + wiki
# print individual errors # print individual errors
for e in errors: for e in errors:
header = header\ header = header\
@ -104,7 +105,7 @@ def genCHeaderFile(errors):
+ wrap(e[3], 80, 0, 0, "/// ") + "\n"\ + wrap(e[3], 80, 0, 0, "/// ") + "\n"\
+ "constexpr int TRI_" + e[0].ljust(61) + " = " + e[1] + ";\n"\ + "constexpr int TRI_" + e[0].ljust(61) + " = " + e[1] + ";\n"\
+ "\n" + "\n"
header = header + "\n"\ header = header + "\n"\
+ "/// register all errors for ArangoDB\n"\ + "/// register all errors for ArangoDB\n"\
+ "void TRI_InitializeErrorMessages();\n"\ + "void TRI_InitializeErrorMessages();\n"\
@ -116,34 +117,38 @@ def genCHeaderFile(errors):
return header return header
# define some globals # define some globals
prologue = "/// auto-generated file generated from errors.dat\n"\ prologue = "/// auto-generated file generated from errors.dat\n"\
+ "\n" + "\n"
if len(sys.argv) < 3: if len(sys.argv) < 3:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0] print("usage: {} <sourcefile> <outfile>".format(sys.argv[0]), file=sys.stderr)
sys.exit() sys.exit(1)
source = sys.argv[1] source = sys.argv[1]
# read input file # read input file
errors = csv.reader(open(source, "rb"))
errorsList = []
r1 = re.compile(r'^#.*') erros = []
with open(source) as source_fh:
errors = csv.reader(open(source, "r"))
for e in errors: errorsList = []
if len(e) == 0:
continue
if r1.match(e[0]): r1 = re.compile(r'^#.*')
continue
if e[0] == "" or e[1] == "" or e[2] == "" or e[3] == "": for e in errors:
print >> sys.stderr, "invalid error declaration file: %s" % (source) if len(e) == 0:
sys.exit() continue
errorsList.append(e) if r1.match(e[0]):
continue
if e[0] == "" or e[1] == "" or e[2] == "" or e[3] == "":
print("invalid error declaration file: {}".format(source), file=sys.stderr)
sys.exit()
errorsList.append(e)
outfile = sys.argv[2] outfile = sys.argv[2]
extension = os.path.splitext(outfile)[1] extension = os.path.splitext(outfile)[1]
@ -160,10 +165,8 @@ elif extension == ".h":
elif extension == ".cpp": elif extension == ".cpp":
out = genCFile(errorsList, filename) out = genCFile(errorsList, filename)
else: else:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0] print("usage: {} <sourcefile> <outfile>".format(sys.argv[0]), file=sys.stderr)
sys.exit() sys.exit(1)
outFile = open(outfile, "wb")
outFile.write(out)
outFile.close()
with open(outfile, "w") as out_fh:
out_fh.write(out)

View File

@ -1,4 +1,5 @@
#!/usr/bin/python #!/usr/bin/env python3
from __future__ import print_function
import csv, sys, os.path, re import csv, sys, os.path, re
# wrap text after x characters # wrap text after x characters
@ -39,7 +40,7 @@ def genJsFile(errors):
out = out\ out = out\
+ " " + name.ljust(30) + " : { \"code\" : " + e[1] + ", \"message\" : \"" + msg + "\" }" + " " + name.ljust(30) + " : { \"code\" : " + e[1] + ", \"message\" : \"" + msg + "\" }"
i = i + 1 i = i + 1
if i < len(errors): if i < len(errors):
out = out + ",\n" out = out + ",\n"
@ -143,7 +144,7 @@ def genCHeaderFile(errors):
+ "\n"\ + "\n"\
+ wiki\ + wiki\
+ "\n" + "\n"
# print individual errors # print individual errors
for e in errors: for e in errors:
header = header\ header = header\
@ -164,34 +165,36 @@ def genCHeaderFile(errors):
return header return header
# define some globals # define some globals
prologue = "/// auto-generated file generated from exitcodes.dat\n"\ prologue = "/// auto-generated file generated from exitcodes.dat\n"\
+ "\n" + "\n"
if len(sys.argv) < 3: if len(sys.argv) < 3:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0] print("usage: {} <sourcefile> <outfile>".format(sys.argv[0]), file=sys.stderr)
sys.exit() sys.exit(1)
source = sys.argv[1] source = sys.argv[1]
# read input file # read input file
errors = csv.reader(open(source, "rb")) errors=None
errorsList = [] errorsList = []
with open(source, "r") as source_fh:
errors = csv.reader(source_fh)
r1 = re.compile(r'^#.*') r1 = re.compile(r'^#.*')
for e in errors: for e in errors:
if len(e) == 0: if len(e) == 0:
continue continue
if r1.match(e[0]): if r1.match(e[0]):
continue continue
if e[0] == "" or e[1] == "" or e[2] == "" or e[3] == "": if e[0] == "" or e[1] == "" or e[2] == "" or e[3] == "":
print >> sys.stderr, "invalid exit code declaration file: %s" % (source) print("invalid exit code declaration file: {}".format(source), file=sys.stderr)
sys.exit() sys.exit(1)
errorsList.append(e) errorsList.append(e)
outfile = sys.argv[2] outfile = sys.argv[2]
extension = os.path.splitext(outfile)[1] extension = os.path.splitext(outfile)[1]
@ -210,10 +213,8 @@ elif extension == ".cpp":
elif extension == ".nsh": elif extension == ".nsh":
out = genNSISFile(errorsList, filename) out = genNSISFile(errorsList, filename)
else: else:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0] print("usage: {} <sourcefile> <outfile>".format(sys.argv[0]), file=sys.stderr)
sys.exit() sys.exit(1)
outFile = open(outfile, "wb")
outFile.write(out);
outFile.close()
with open(outfile, "w") as out_fh:
out_fh.write(out);