diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index f3e3890..d47cd1d 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -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 \ No newline at end of file + - git submodule + - python twincat_version_manager.py + - python check_fix_white_space.py diff --git a/check_fix_white_space.py b/check_fix_white_space.py new file mode 100755 index 0000000..cf6fe3c --- /dev/null +++ b/check_fix_white_space.py @@ -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) diff --git a/solution/tc_epicscommodule b/solution/tc_epicscommodule index 3794bb7..e746bc4 160000 --- a/solution/tc_epicscommodule +++ b/solution/tc_epicscommodule @@ -1 +1 @@ -Subproject commit 3794bb7a9801d08901fe8efcf3e103582b5d7e2c +Subproject commit e746bc4b801554a2af3cc5432f9374ffc9fbd82b diff --git a/solution/tc_project_app/GVLs/GVL_APP.TcGVL b/solution/tc_project_app/GVLs/GVL_APP.TcGVL index 2d96afa..a846a85 100644 --- a/solution/tc_project_app/GVLs/GVL_APP.TcGVL +++ b/solution/tc_project_app/GVLs/GVL_APP.TcGVL @@ -3,12 +3,12 @@ \ No newline at end of file diff --git a/solution/tc_project_app/POUs/MAIN.TcPOU b/solution/tc_project_app/POUs/MAIN.TcPOU index 50890c8..d74f2d1 100644 --- a/solution/tc_project_app/POUs/MAIN.TcPOU +++ b/solution/tc_project_app/POUs/MAIN.TcPOU @@ -3,43 +3,43 @@ @@ -52,7 +52,7 @@ ERROR();]]> , - 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=> ); *) ]]> diff --git a/solution/tc_project_app/tc_mca_std_lib b/solution/tc_project_app/tc_mca_std_lib index afc8c96..ce9f69f 160000 --- a/solution/tc_project_app/tc_mca_std_lib +++ b/solution/tc_project_app/tc_mca_std_lib @@ -1 +1 @@ -Subproject commit afc8c964ba035d22f55f2ead68c3ab38f62eb7ba +Subproject commit ce9f69ffdc2ac817ced936189f4550b65235025d