Merged in MBP-114-dont-use-tab-in-source-code (pull request #16)
MBP-114 dont use tab in source code
This commit is contained in:
@@ -2,9 +2,10 @@ image: python:3.7.3
|
||||
options:
|
||||
max-time: 1
|
||||
pipelines:
|
||||
pull-requests:
|
||||
'**':
|
||||
- step:
|
||||
default:
|
||||
- step:
|
||||
script:
|
||||
- git submodule update --init
|
||||
- python twincat_version_manager.py
|
||||
- git submodule
|
||||
- python twincat_version_manager.py
|
||||
- python check_fix_white_space.py
|
||||
|
||||
96
check_fix_white_space.py
Executable file
96
check_fix_white_space.py
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# Script to fix whithespace errors in files
|
||||
# All trailing white space are removed
|
||||
# TAB are replace by spaces
|
||||
#
|
||||
import glob
|
||||
import sys
|
||||
|
||||
file_patterns_tab_width = {"**/*.Tc*": 4,
|
||||
"**/*.py": 4,
|
||||
"**/*.sh": 8}
|
||||
def fix_white_space(debug, fix_files):
|
||||
"""
|
||||
Checks the Twincat source code for white space:
|
||||
TAB should not be used
|
||||
Trailing SPACE shoulf not be there.
|
||||
:return: A dictionary of white-space-damaged files
|
||||
"""
|
||||
incorrect_files = dict()
|
||||
for file_path, tab_width in file_patterns_tab_width.items():
|
||||
found_files = glob.glob(file_path, recursive=True)
|
||||
#if not found_files:
|
||||
# raise IOError("ERROR: No files of type {} found".format(file_path))
|
||||
|
||||
for pathname in found_files:
|
||||
dirty = False
|
||||
new_lines = []
|
||||
if debug >= 1:
|
||||
print("tab_with=%d pathname=%s" % (tab_width, pathname))
|
||||
file = open(pathname, 'r', newline='', encoding="iso-8859-1")
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
for old_line in lines:
|
||||
had_crlf = 0
|
||||
this_line_dirty = False
|
||||
if old_line.endswith('\r\n'):
|
||||
had_crlf = 2 # Both CR and LF
|
||||
elif old_line.endswith('\n'):
|
||||
had_crlf = 1 # LF
|
||||
# Convert all TAB into SPACE
|
||||
new_line = old_line.expandtabs(tabsize=tab_width)
|
||||
# Strip of all trailing white space, including the CRLF
|
||||
new_line = new_line.rstrip("\r\n ")
|
||||
if had_crlf == 2:
|
||||
new_line = new_line + '\r\n'
|
||||
elif had_crlf == 1:
|
||||
new_line = new_line + '\n'
|
||||
|
||||
if len(new_line) != len(old_line):
|
||||
dirty = True
|
||||
this_line_dirty = True
|
||||
new_lines.append(new_line)
|
||||
if this_line_dirty:
|
||||
if debug >= 2:
|
||||
print("had_crlf=%d" % had_crlf)
|
||||
print("old_line=%s" % old_line)
|
||||
print("new_line=%s" % new_line)
|
||||
# end of loop of all line in one file
|
||||
if debug >= 1:
|
||||
print("pathname=%s dirty=%d" % (pathname, dirty))
|
||||
if dirty:
|
||||
incorrect_files[pathname] = True
|
||||
if fix_files:
|
||||
file = open(pathname, 'w', newline='', encoding="iso-8859-1")
|
||||
file.writelines(new_lines)
|
||||
file.close()
|
||||
|
||||
return incorrect_files
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
argc = len(sys.argv)
|
||||
arg_idx = 1
|
||||
debug = 0
|
||||
fix_files = False
|
||||
while arg_idx < argc:
|
||||
if sys.argv[arg_idx] == "--fix":
|
||||
fix_files = True
|
||||
elif sys.argv[arg_idx] == "--debug":
|
||||
debug = debug + 1
|
||||
else:
|
||||
print("%s : [--fix|--debug]" % sys.argv[0])
|
||||
exit(2)
|
||||
arg_idx = arg_idx + 1
|
||||
incorrect_files = fix_white_space(debug, fix_files)
|
||||
if not fix_files:
|
||||
for file in incorrect_files:
|
||||
print("ERROR: '{}' has white space damage".format(file))
|
||||
if incorrect_files:
|
||||
exit(1)
|
||||
except IOError as e:
|
||||
print(e) # Likely no files found
|
||||
exit(2)
|
||||
Submodule solution/tc_epicscommodule updated: 3794bb7a98...e746bc4b80
@@ -3,12 +3,12 @@
|
||||
<GVL Name="GVL_APP" Id="{8fe9690c-7907-432e-bedb-6fc99b5ce255}">
|
||||
<Declaration><![CDATA[{attribute 'qualified_only'}
|
||||
VAR_GLOBAL
|
||||
|
||||
|
||||
END_VAR
|
||||
|
||||
VAR_GLOBAL CONSTANT
|
||||
axisNum : UINT:=3;
|
||||
//axisCoupleMax : UINT:=4;
|
||||
axisNum : UINT:=3;
|
||||
//axisCoupleMax : UINT:=4;
|
||||
END_VAR]]></Declaration>
|
||||
</GVL>
|
||||
</TcPlcObject>
|
||||
@@ -3,43 +3,43 @@
|
||||
<POU Name="MAIN" Id="{33eb6f49-7781-4211-a70b-87ada6d80cb7}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[PROGRAM MAIN
|
||||
VAR
|
||||
sVersion: STRING:='1.0.0';
|
||||
i : UINT; //index variable for AXES()
|
||||
aFbAxes: ARRAY [1..gvl_app.axisNum] OF FB_Axis;
|
||||
hmiAxisSelection : INT:=1; //Not possible to use local hmi variables for array indexes
|
||||
|
||||
sVersion: STRING:='1.0.0';
|
||||
i : UINT; //index variable for AXES()
|
||||
aFbAxes: ARRAY [1..gvl_app.axisNum] OF FB_Axis;
|
||||
hmiAxisSelection : INT:=1; //Not possible to use local hmi variables for array indexes
|
||||
|
||||
(******Outputs: Power for Limit switches and Home Sensors (every 4th output)********)
|
||||
|
||||
bOutput1 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput2 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput3 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput4 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput5 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput6 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput7 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput8 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput9 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput13 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput17 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput21 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput24 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput28 AT %Q*: BOOL:= TRUE;
|
||||
|
||||
|
||||
bOutput1 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput2 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput3 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput4 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput5 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput6 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput7 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput8 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput9 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput13 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput17 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput21 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput24 AT %Q*: BOOL:= TRUE;
|
||||
//bOutput28 AT %Q*: BOOL:= TRUE;
|
||||
|
||||
(******Error Handling********)
|
||||
fbErrorSystem: FB_ErrorSystem;
|
||||
aFbAxesError: ARRAY [1..gvl_app.axisNum] OF FB_NC_Error;
|
||||
|
||||
//fbEL1018 : EL1018;
|
||||
//fbEL2808 : EL2808;
|
||||
//fbEL5101 : EL5101;
|
||||
//fbEL9505 : EL9505;
|
||||
//fbEL1252 : EL1252;
|
||||
//fbEL9410 : EL9410;
|
||||
//fbEL7037 : EL7037;
|
||||
//fbEK1110 : EK1110;
|
||||
|
||||
|
||||
|
||||
fbErrorSystem: FB_ErrorSystem;
|
||||
aFbAxesError: ARRAY [1..gvl_app.axisNum] OF FB_NC_Error;
|
||||
|
||||
//fbEL1018 : EL1018;
|
||||
//fbEL2808 : EL2808;
|
||||
//fbEL5101 : EL5101;
|
||||
//fbEL9505 : EL9505;
|
||||
//fbEL1252 : EL1252;
|
||||
//fbEL9410 : EL9410;
|
||||
//fbEL7037 : EL7037;
|
||||
//fbEK1110 : EK1110;
|
||||
|
||||
|
||||
|
||||
END_VAR
|
||||
|
||||
]]></Declaration>
|
||||
@@ -52,7 +52,7 @@ ERROR();]]></ST>
|
||||
<Implementation>
|
||||
<ST><;
|
||||
aFbAxes[GVL.iAxis](stAxisStruct:=gvl.axes[GVL.iAxis]);
|
||||
END_FOR
|
||||
|
||||
|
||||
@@ -65,35 +65,35 @@ END_FOR
|
||||
(****FB containting the log of the errors****)
|
||||
//
|
||||
fbErrorSystem(
|
||||
En:= TRUE,
|
||||
bReset:= ,
|
||||
nErrorNum:= ,
|
||||
bACK:= ,
|
||||
bValidSelection:= ,
|
||||
nTableRowIndex:= ,
|
||||
EnO=> ,
|
||||
nSelectedError=> ,
|
||||
pErrorSystem=> );
|
||||
En:= TRUE,
|
||||
bReset:= ,
|
||||
nErrorNum:= ,
|
||||
bACK:= ,
|
||||
bValidSelection:= ,
|
||||
nTableRowIndex:= ,
|
||||
EnO=> ,
|
||||
nSelectedError=> ,
|
||||
pErrorSystem=> );
|
||||
|
||||
|
||||
FOR GVL.iAxis:=1 TO gvl_app.axisNum DO
|
||||
aFbAxesError[gvl.iAxis](EN:=TRUE,
|
||||
nNC_ErrorID:= gvl.axes[gvl.iAxis].status.nErrorID,
|
||||
nNC_AxisID:=gvl.axes[gvl.iAxis].Axis.NcToPlc.AxisId,
|
||||
ErrorSystem:= fbErrorSystem.pErrorSystem);
|
||||
aFbAxesError[gvl.iAxis](EN:=TRUE,
|
||||
nNC_ErrorID:= gvl.axes[gvl.iAxis].status.nErrorID,
|
||||
nNC_AxisID:=gvl.axes[gvl.iAxis].Axis.NcToPlc.AxisId,
|
||||
ErrorSystem:= fbErrorSystem.pErrorSystem);
|
||||
END_FOR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(*call all the necessary instance (input assistance F2 or right click) according to the terminals that you have in your hardware and
|
||||
add "TRUE" in the input En, the corresponding number of termianl to the iTerminal_ID and
|
||||
the variable "fbErrorSystem.pErrorSystem" to the input ErrorSystem in each FB E. g. :
|
||||
add "TRUE" in the input En, the corresponding number of termianl to the iTerminal_ID and
|
||||
the variable "fbErrorSystem.pErrorSystem" to the input ErrorSystem in each FB E. g. :
|
||||
fbEL1808(
|
||||
En:= TRUE,
|
||||
iTerminal_ID:= 01,
|
||||
ErrorSystem:= fbErorSystem.pErrorSystem,
|
||||
EnO=> ,
|
||||
bError=> );
|
||||
En:= TRUE,
|
||||
iTerminal_ID:= 01,
|
||||
ErrorSystem:= fbErorSystem.pErrorSystem,
|
||||
EnO=> ,
|
||||
bError=> );
|
||||
*)
|
||||
|
||||
]]></ST>
|
||||
|
||||
Reference in New Issue
Block a user