[genpinmap] Use Flake8 for Style Guide Enforcement

http://flake8.pycqa.org/

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
This commit is contained in:
Frederic.Pillon 2018-11-16 15:37:52 +01:00
parent 27cea3ca8a
commit c41950af8b
2 changed files with 22 additions and 24 deletions

2
src/genpinmap/.flake8 Normal file
View file

@ -0,0 +1,2 @@
[flake8]
max-line-length = 88

View file

@ -6,7 +6,6 @@ import os
import re import re
import sys import sys
import textwrap import textwrap
from xml.dom import minidom
from xml.dom.minidom import parse, Node from xml.dom.minidom import parse, Node
from argparse import RawTextHelpFormatter from argparse import RawTextHelpFormatter
@ -64,7 +63,7 @@ def get_gpio_af_num(pintofind, iptofind):
if m.nodeType == Node.ELEMENT_NODE: if m.nodeType == Node.ELEMENT_NODE:
for secondlevel in m.attributes.items(): for secondlevel in m.attributes.items():
k += 1 k += 1
# if 'I2C1_SDA' in secondlevel: # if 'I2C1_SDA' in secondlevel:
if iptofind in secondlevel: if iptofind in secondlevel:
# DBG print (i, j, m.attributes.items()) # DBG print (i, j, m.attributes.items())
# m = IP node found # m = IP node found
@ -115,7 +114,7 @@ def get_gpio_af_numF1(pintofind, iptofind):
for secondlevel in m.attributes.items(): for secondlevel in m.attributes.items():
# print ('secondlevel ' , i, j, k , secondlevel) # print ('secondlevel ' , i, j, k , secondlevel)
k += 1 k += 1
# if 'I2C1_SDA' in secondlevel: # if 'I2C1_SDA' in secondlevel:
if iptofind in secondlevel: if iptofind in secondlevel:
# m = IP node found # m = IP node found
# print (i, j, m.attributes.items()) # print (i, j, m.attributes.items())
@ -123,14 +122,14 @@ def get_gpio_af_numF1(pintofind, iptofind):
# p node 'RemapBlock' # p node 'RemapBlock'
if ( if (
p.nodeType == Node.ELEMENT_NODE p.nodeType == Node.ELEMENT_NODE
and p.hasChildNodes() == False and p.hasChildNodes() is False
): ):
mygpioaf += " AFIO_NONE" mygpioaf += " AFIO_NONE"
else: else:
for s in p.childNodes: for s in p.childNodes:
if s.nodeType == Node.ELEMENT_NODE: if s.nodeType == Node.ELEMENT_NODE:
# s node 'Specific parameter' # s node 'Specific parameter'
# DBG print (i,j,k,p.attributes.items()) # print (i,j,k,p.attributes.items())
for myc in s.childNodes: for myc in s.childNodes:
# DBG print (myc) # DBG print (myc)
if ( if (
@ -282,7 +281,7 @@ def print_header():
""" % ( """ % (
datetime.datetime.now().year, datetime.datetime.now().year,
os.path.basename(input_file_name), os.path.basename(input_file_name),
re.sub("\.c$", "", out_c_filename), re.sub("\\.c$", "", out_c_filename),
) )
out_c_file.write(s) out_c_file.write(s)
@ -427,8 +426,8 @@ def print_dac():
) )
def print_i2c(l): def print_i2c(lst):
for p in l: for p in lst:
result = get_gpio_af_num(p[1], p[2]) result = get_gpio_af_num(p[1], p[2])
if result != "NOTFOUND": if result != "NOTFOUND":
s1 = "%-12s" % (" {" + p[0] + ",") s1 = "%-12s" % (" {" + p[0] + ",")
@ -481,15 +480,15 @@ def print_pwm():
) )
def print_uart(l): def print_uart(lst):
for p in l: for p in lst:
result = get_gpio_af_num(p[1], p[2]) result = get_gpio_af_num(p[1], p[2])
if result != "NOTFOUND": if result != "NOTFOUND":
s1 = "%-12s" % (" {" + p[0] + ",") s1 = "%-12s" % (" {" + p[0] + ",")
# 2nd element is the UART_XX signal # 2nd element is the UART_XX signal
b = p[2].split("_")[0] b = p[2].split("_")[0]
s1 += "%-9s" % (b[: len(b) - 1] + b[len(b) - 1 :] + ",") s1 += "%-9s" % (b[: len(b) - 1] + b[len(b) - 1 :] + ",")
if "STM32F10" in mcu_file and l == uartrx_list: if "STM32F10" in mcu_file and lst == uartrx_list:
s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, " s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
else: else:
s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@ -505,8 +504,8 @@ def print_uart(l):
) )
def print_spi(l): def print_spi(lst):
for p in l: for p in lst:
result = get_gpio_af_num(p[1], p[2]) result = get_gpio_af_num(p[1], p[2])
if result != "NOTFOUND": if result != "NOTFOUND":
s1 = "%-12s" % (" {" + p[0] + ",") s1 = "%-12s" % (" {" + p[0] + ",")
@ -525,9 +524,8 @@ def print_spi(l):
) )
def print_can(l): def print_can(lst):
for p in l: for p in lst:
b = p[2]
result = get_gpio_af_num(p[1], p[2]) result = get_gpio_af_num(p[1], p[2])
if result != "NOTFOUND": if result != "NOTFOUND":
s1 = "%-12s" % (" {" + p[0] + ",") s1 = "%-12s" % (" {" + p[0] + ",")
@ -535,7 +533,7 @@ def print_can(l):
instance = p[2].split("_")[0].replace("CAN", "") instance = p[2].split("_")[0].replace("CAN", "")
if len(instance) == 0: if len(instance) == 0:
instance = "1" instance = "1"
if "STM32F10" in mcu_file and l == canrd_list: if "STM32F10" in mcu_file and lst == canrd_list:
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, " s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
else: else:
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, " s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
@ -807,9 +805,9 @@ its name, you should call it with double quotes"""
args = parser.parse_args() args = parser.parse_args()
if not (os.path.isdir(cubemxdir)): if not (os.path.isdir(cubemxdir)):
print("\n ! ! ! Cube Mx seems not to be installed or not at the requested location") print("\nCube Mx seems not to be installed or not at the requested location.")
print( print(
"\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file" "\nPlease check the value you set for 'CUBEMX_DIRECTORY' in '%s' file."
% config_filename % config_filename
) )
quit() quit()
@ -819,10 +817,10 @@ cubemxdirIP = os.path.join(cubemxdir, "IP")
if args.mcu: if args.mcu:
# check input file exists # check input file exists
if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))): if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))):
print("\n ! ! ! " + args.mcu + " file not found") print("\n" + args.mcu + " file not found")
print("\n ! ! ! Check in " + cubemxdir + " the correct name of this file") print("\nCheck in " + cubemxdir + " the correct name of this file")
print( print(
"\n ! ! ! You may use double quotes for this file if it contains special characters" "\nYou may use double quotes for file containing special characters"
) )
quit() quit()
mcu_list.append(args.mcu) mcu_list.append(args.mcu)
@ -848,11 +846,9 @@ for mcu_file in mcu_list:
# open output file # open output file
if os.path.isfile(output_c_filename): if os.path.isfile(output_c_filename):
# print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
os.remove(output_c_filename) os.remove(output_c_filename)
out_c_file = open(output_c_filename, "w") out_c_file = open(output_c_filename, "w")
if os.path.isfile(output_h_filename): if os.path.isfile(output_h_filename):
# print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
os.remove(output_h_filename) os.remove(output_h_filename)
out_h_file = open(output_h_filename, "w") out_h_file = open(output_h_filename, "w")