-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkStep_support.py
392 lines (311 loc) · 11 KB
/
checkStep_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 4.24.1
# in conjunction with Tcl version 8.6
# Aug 16, 2019 11:38:10 AM CDT platform: Windows NT
import sys
from tkinter import filedialog
from tkinter import *
import timeit
import time
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
def set_Tk_var():
global awlpath #Label pathAWLFile
awlpath = StringVar()
global prog_var #It was for progress bar
prog_var = tk.IntVar()
global checkCo #CheckBotton Comments
checkCo = tk.IntVar()
global checkFB #CheckBotton Network
checkFB = tk.IntVar()
global checkDBinitialized #CheckBotton DB Initialized
checkDBinitialized = tk.IntVar()
global message #Label Message
message = tk.StringVar()
global flag #CheckBotton Network
flag = tk.IntVar()
def init(top, gui, *args, **kwargs):
global w, top_level, root
w = gui
top_level = top
root = top
awlpath.set("AWL Path: ")
message.set("")
flag = 0
def destroy_window():
# Function which closes the window.
global top_level
top_level.destroy()
top_level = None
if __name__ == '__main__':
import checkStep
checkStep.vp_start_gui()
#Function to open browse and select awl file
def awlBrowse():
root = Tk() #withdraw() unable open extra window
root.withdraw()
root.file = filedialog.askopenfilename(initialdir = "/",title = "Select AWL",filetypes = (("AWL file","*.awl"),("All files","*.*")))
awlpath.set(root.file)
#Function to do the logic when Start is selected
def startProgram():
start = timeit.default_timer()
if checkCo.get() == True:
print("///////////////////////////////////////////")
comments(awlpath.get())
message.set("")
message.set("Done - Checking if there network with comments")
#print("Done Comments \n")
flag = 1
if checkFB.get() == True:
print("///////////////////////////////////////////")
network(awlpath.get())
message.set("")
message.set("Done - Checking if title's network is equal to FB Name")
#print("Done Title's Network \n")
flag = 1
if checkDBinitialized.get() == True:
print("///////////////////////////////////////////")
dbInitialized(awlpath.get())
message.set("")
message.set("Done - Checking if DB Initialized")
#print("Done DB Initialized \n")
flag = 1
if (checkCo.get() and checkFB.get()) == False:
if flag == 0:
message.set("")
message.set("Select a option")
print("Select")
if flag == 1:
stop = timeit.default_timer()
print("///////////////////////////////////////////")
print('Time: ', stop - start)
flag = 0
#Function to check if there is a network if comment
def comments(awlfilepath):
#initialize variables
FB = ""
same = ""
activeFB = 0
activeLogic = 0
find = 0
firstTitle = 0
flag = 0
#string to compare if awl
beginFB = 'FUNCTION_BLOCK FB '
endFB = 'END_FUNCTION_BLOCK'
title = 'TITLE ='
beginLogic = 'BEGIN'
comment = '//'
#Open generated txt
awl_com = open("generated/comments_awl.txt", "w")
#Open AWL
with open(awlfilepath, 'r') as file:
for line in file:
#There is a lengh difference when the decimal changes
if beginFB in line:
if len(line) == 23:
FB = line[18:22]
if len(line) == 22:
FB = line[18:21]
if len(line) == 21:
FB = line[18:20]
activeFB = 1
#Change from STR to Int
if FB == "":
FB = 0
#Rules
#We don't need to check FB 0-100 and 1600-1800
#Safety FBs or Basic FBs
if 1600 < int(str(FB)) < 1800 or 0 < int(str(FB)) < 200:
activeFB = 0
#Logic
#Find the FB Title
if firstTitle == 0 and activeFB == 1:
if title in line:
firstTitle = 1
#Find BEGIN that means that we are in the FB Logic - It's not necessary in this logic
if activeFB == 1:
if beginLogic in line:
activeLogic = 1
#check if the next line has "//"
if flag == 1:
if comment in line:
print("FB "+str(FB))
print(line)
flag = 0
find = 1
#After find the first TITLE=, it checks the Title Network and FB Name matchs
if firstTitle == 1 and activeLogic == 1 and activeFB == 1:
if title in line:
flag = 1
#Find END_FUNCTION_BLOCK
if endFB in line:
if find == 1:
awl_com.write("FB " + str(FB) + "\n")
find = 0
activeLogic = 0
activeFB = 0
firstTitle = 0
flag = 0
#Close generated txt
awl_com.close()
print("Checking if Network has Comments...DONE!\n")
#Function to check if the network has the same name as the FG Name *needs to implement Symbol names
def network(awlfilepath):#network
#initialize variables
FB = ''
FBName = ''
activeFB = 0
activeLogic = 0
find = 0
firstTitle = 0
#string to compare if awl
beginFB = 'FUNCTION_BLOCK FB '
endFB = 'END_FUNCTION_BLOCK'
title = 'TITLE ='
beginLogic = 'BEGIN'
#Open generated txt
awl_net = open("generated/network_awl.txt", "w")
#Open AWL
with open(awlfilepath, 'r') as file:
for line in file:
#There is a lengh difference when the decimal changes
if beginFB in line:
if len(line) == 23:
FB = line[18:22]
if len(line) == 22:
FB = line[18:21]
if len(line) == 21:
FB = line[18:20]
activeFB = 1
#Change from STR to Int
if FB == "":
FB = 0
#Rules
#We don't need to check FB 0-100 and 1600-1800
#Safety FBs or Basic FBs
if 1600 < int(str(FB)) < 1800 or 0 < int(str(FB)) < 200:
activeFB = 0
#Logic
#Find the FB Title
if firstTitle == 0 and activeFB == 1:
if title in line:
FBName = line[7:16] #copy FB name from the network
firstTitle = 1
#Find BEGIN that means that we are in the FB Logic - It's not necessary in this logic
if activeFB == 1:
if beginLogic in line:
activeLogic = 1
#After find the first TITLE=, it checks the Title Network and FB Name matchs
if firstTitle == 1:
if title in line:
if activeLogic == 1 and activeFB == 1: #it means that we are inside a FB and in the logic part
if FBName != None: #Just to check if FB name is not empty
if line[7:16] != FBName: #to make sure that will appear just once the FB
find = 1
#Find END_FUNCTION_BLOCK
if endFB in line:
if find == 1:
print("FB "+str(FB))
awl_net.write("FB " + str(FB) + "\n")
find = 0
activeLogic = 0
activeFB = 0
firstTitle = 0
#Close generated txt
awl_net.close()
print("Checking if Title's Network has the FB Name...DONE!\n")
def dbInitialized(awlfilepath): #dbInitialized
#initialize variables
DB = ""
flag = 0
ban = 0
finished = 0
activeDB = 0
#string to compare if awl
beginDB = 'DATA_BLOCK DB '
endDB = 'END_DATA_BLOCK'
beginStruct = 'S7_language :='
endStruct = 'BEGIN' #it's after declaration
compareString = ':='
howToStruct = 'KNOW_HOW_PROTECT'
containsUDT = 'UDT'
itsIDB = 'SFB 52'
itsIDB_2 = 'SFB 53'
#Open generated txt
awl_db = open("generated/comments_db.txt", "w")
#Open AWL
with open(awlfilepath, 'r') as file:
for line in file:
#There is a lengh difference when the decimal changes
if beginDB in line:
if len(line) == 16:
DB = line[14:15]
if len(line) == 17:
DB = line[14:16]
if len(line) == 18:
DB = line[14:17]
if len(line) == 19:
DB = line[14:18]
activeDB = 1
#print("DB "+DB)
#Start the part where we want to search
if beginStruct in line:
if activeDB == 1:
finished = 0
#Logic
#Find KNOW_HOW_PROTECT
if howToStruct in line:
if ban == 0 and finished == 0 and activeDB == 1:
ban = 1
print("DB "+DB + " is KNOW HOW PROTECTED and can not be checked")
flag = 1
#Find IDB - SFB 52
if itsIDB in line:
if ban == 0 and finished == 0 and activeDB == 1:
ban = 1
print("DB "+DB + " is Instanz DB and can not be checked")
flag = 2
#Find IDB - SFB 53
if itsIDB_2 in line:
if ban == 0 and finished == 0 and activeDB == 1:
ban = 1
print("DB "+DB + " is Instanz DB and can not be checked")
flag = 2
#Find UDT
if containsUDT in line:
if ban == 0 and finished == 0 and activeDB == 1: #to make sure that will appear just once the FB
print("DB "+DB + " contains UDT Datas")
flag = 3
ban = 1
#Find :=
if compareString in line:
if ban == 0 and flag == 0 and finished == 0 and activeDB == 1 : #to make sure that will appear just once the FB
#print("DB "+DB + ' is not initialized')
#print(line)
flag = 4
#When finds BEGIN, means that it leaving declaration
if endStruct in line:
if flag == 5: #STILL NOT WORKING
print("DB "+DB + ' is not initialized')
flag = 0
ban = 0
finished = 1
#Close DB
if endDB in line:
activeDB = 0
awl_db.close()
#Function to update the progress bar *NOT WORKING
def update (v):
#print ('Progress_Bar: update: v =', v)
prog_var.set(int(v*100))