PEP8 radio/util/luaexport.py
Fix indentation
This commit is contained in:
+19
-15
@@ -22,6 +22,7 @@ exports_script_outputs = []
|
|||||||
warning = None
|
warning = None
|
||||||
error = None
|
error = None
|
||||||
|
|
||||||
|
|
||||||
def checkName(name):
|
def checkName(name):
|
||||||
global warning
|
global warning
|
||||||
if name in dups_name:
|
if name in dups_name:
|
||||||
@@ -36,7 +37,8 @@ def checkName(name):
|
|||||||
def LEXP(name, description):
|
def LEXP(name, description):
|
||||||
# print "LEXP %s, %s" % (name, description)
|
# print "LEXP %s, %s" % (name, description)
|
||||||
checkName(name)
|
checkName(name)
|
||||||
exports.append( (CONSTANT_VALUE, name, description) )
|
exports.append((CONSTANT_VALUE, name, description))
|
||||||
|
|
||||||
|
|
||||||
def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
|
def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
|
||||||
# print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
|
# print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
|
||||||
@@ -44,7 +46,8 @@ def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
|
|||||||
name = nameFormat + str(v)
|
name = nameFormat + str(v)
|
||||||
# print name
|
# print name
|
||||||
checkName(name)
|
checkName(name)
|
||||||
exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount) )
|
exports_multiple.append((CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount))
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Error: not enough arguments!")
|
print("Error: not enough arguments!")
|
||||||
@@ -63,7 +66,7 @@ print("Output file %s" % outputFile)
|
|||||||
if docFile:
|
if docFile:
|
||||||
print("Documentation file %s" % docFile)
|
print("Documentation file %s" % docFile)
|
||||||
|
|
||||||
inp = open(inputFile, "r")
|
np = open(inputFile, "r")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = inp.readline()
|
line = inp.readline()
|
||||||
@@ -71,10 +74,10 @@ while True:
|
|||||||
break
|
break
|
||||||
line = line.strip('\r\n')
|
line = line.strip('\r\n')
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
#print "line: %s" % line
|
# print "line: %s" % line
|
||||||
|
|
||||||
parts = line.split('LEXP')
|
parts = line.split('LEXP')
|
||||||
#print parts
|
# print parts
|
||||||
if len(parts) != 2:
|
if len(parts) != 2:
|
||||||
print("Wrong line: %s" % line)
|
print("Wrong line: %s" % line)
|
||||||
continue
|
continue
|
||||||
@@ -83,7 +86,7 @@ while True:
|
|||||||
if cnst.find('=') != -1:
|
if cnst.find('=') != -1:
|
||||||
# constant contains =
|
# constant contains =
|
||||||
cnst = cnst.split('=')[0].strip()
|
cnst = cnst.split('=')[0].strip()
|
||||||
#print "Found constant %s with command: %s" % (cnst, cmd)
|
# print "Found constant %s with command: %s" % (cnst, cmd)
|
||||||
try:
|
try:
|
||||||
CONSTANT_VALUE = cnst
|
CONSTANT_VALUE = cnst
|
||||||
# if CONSTANT_VALUE in dups_cnst:
|
# if CONSTANT_VALUE in dups_cnst:
|
||||||
@@ -103,7 +106,7 @@ inp.close()
|
|||||||
out = open(outputFile, "w")
|
out = open(outputFile, "w")
|
||||||
|
|
||||||
out.write("//This file was generated by luaexport.py script on %s for OpenTX version %s\n\n\n"
|
out.write("//This file was generated by luaexport.py script on %s for OpenTX version %s\n\n\n"
|
||||||
% ( time.asctime(), version))
|
% (time.asctime(), version))
|
||||||
|
|
||||||
header = """
|
header = """
|
||||||
struct LuaSingleField {
|
struct LuaSingleField {
|
||||||
@@ -127,7 +130,7 @@ out.write("""
|
|||||||
// this aray is alphabetically sorted by the second field (name)
|
// this aray is alphabetically sorted by the second field (name)
|
||||||
const LuaSingleField luaSingleFields[] = {
|
const LuaSingleField luaSingleFields[] = {
|
||||||
""")
|
""")
|
||||||
exports.sort(key = lambda x: x[1]) #sort by name
|
exports.sort(key=lambda x: x[1]) # sort by name
|
||||||
data = [" {%s, \"%s\", \"%s\"}" % export for export in exports]
|
data = [" {%s, \"%s\", \"%s\"}" % export for export in exports]
|
||||||
out.write(",\n".join(data))
|
out.write(",\n".join(data))
|
||||||
out.write("\n};\n\n")
|
out.write("\n};\n\n")
|
||||||
@@ -141,27 +144,28 @@ data = [" {%s, \"%s\", \"%s\", %d}" % export for export in exports_multiple]
|
|||||||
out.write(",\n".join(data))
|
out.write(",\n".join(data))
|
||||||
out.write("\n};\n\n")
|
out.write("\n};\n\n")
|
||||||
print("Generated %d items in luaMultipleFields[]" % len(exports_multiple))
|
print("Generated %d items in luaMultipleFields[]" % len(exports_multiple))
|
||||||
|
|
||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
if docFile:
|
if docFile:
|
||||||
#prepare fields
|
# prepare fields
|
||||||
all_exports = [(name, desc) for (id, name, desc) in exports]
|
all_exports = [(name, desc) for (id, name, desc) in exports]
|
||||||
for (id, nameFormat, descriptionFormat, valuesCount) in exports_multiple:
|
for (id, nameFormat, descriptionFormat, valuesCount) in exports_multiple:
|
||||||
for v in range(1, valuesCount + 1):
|
for v in range(1, valuesCount + 1):
|
||||||
name = nameFormat + str(v)
|
name = nameFormat + str(v)
|
||||||
desc = descriptionFormat % v
|
desc = descriptionFormat % v
|
||||||
all_exports.append( (name, desc) )
|
all_exports.append((name, desc))
|
||||||
#natural sort by field name
|
# natural sort by field name
|
||||||
convert = lambda text: int(text) if text.isdigit() else text
|
convert = lambda text: int(text) if text.isdigit() else text
|
||||||
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key[0]) ]
|
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key[0])]
|
||||||
all_exports.sort(key = alphanum_key)
|
all_exports.sort(key=alphanum_key)
|
||||||
|
|
||||||
out = open(docFile, "w")
|
out = open(docFile, "w")
|
||||||
out.write("Alphabetical list of Lua fields for OpenTX version %s\n\n\n" % version)
|
out.write("Alphabetical list of Lua fields for OpenTX version %s\n\n\n" % version)
|
||||||
FIELD_NAME_WIDTH = 25
|
FIELD_NAME_WIDTH = 25
|
||||||
out.write("Field name%sField description\n" % (' '*(FIELD_NAME_WIDTH-len('Field name'))))
|
out.write("Field name%sField description\n" % (' ' * (FIELD_NAME_WIDTH - len('Field name'))))
|
||||||
out.write("----------------------------------------------\n")
|
out.write("----------------------------------------------\n")
|
||||||
data = ["%s%s%s" % (name, ' '*(FIELD_NAME_WIDTH-len(name)) , desc) for (name, desc) in all_exports]
|
data = ["%s%s%s" % (name_, ' ' * (FIELD_NAME_WIDTH - len(name_)), desc_) for (name_, desc_) in all_exports]
|
||||||
out.write("\n".join(data))
|
out.write("\n".join(data))
|
||||||
out.write("\n")
|
out.write("\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user