-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpc.py
717 lines (649 loc) · 27.4 KB
/
jpc.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
import sys
import os
from Tkinter import *
import tkMessageBox
import datetime
import time
import subprocess
import shutil
import threading
def rf_process_control(mode):
global config_file_variables
# Get serial number for device under test.
# Currently this is manually entered or scanned in by operator
# Will update function to get information directly from JabilTest in future
serial_number = get_serial_number()
print 'serial number for device under test is', serial_number
# Validation takes place now consisting of:
# F1C xml file generation
# Watch for response from F1C service
# Interpret the F1C response
next_instruction = rf_validate(mode, serial_number)
#print next_instruction
while next_instruction in ['LaunchRF', 'LaunchDSN', 'TIMEOUT']:
# Launching RF will:
# Run test software
# Wait for log file to be generated
# Interpret test result
# Update config file for next stage status
# Update config file with notes for detailed failures
if next_instruction == 'LaunchRF':
next_instruction = rf_test_software(mode, serial_number)
elif next_instruction == 'LaunchDSN':
next_instruction = dsn_test_software(mode, serial_number)
# Timeout takes place now consisting of:
# F1C xml file generation
# Watch for response from F1C service
# Interpret the F1C response
elif next_instruction == 'TIMEOUT':
next_instruction = rf_timeout(mode, serial_number)
print 'Next instruction is to %s' % next_instruction
if next_instruction == 'ERROR':
message = 'DUT is not validated as being in the correct work center'
print message
tkMessageBox.showerror('Error', message)
if next_instruction == 'TO_ERROR':
message = 'DUT did not complete process correctly; '
message += 'please notify engineering for review'
print message
tkMessageBox.showerror('Error', message)
elif next_instruction == 'MANUAL':
message = 'DUT has completed test process '
message += 'but has not been auto-timed out'
message += '\nManual timeout required'
print message
tkMessageBox.showwarning('Information', message)
elif next_instruction == 'DONE':
message = 'DUT has completed test process '
message += 'and has been auto-timed out to next stage'
print message
tkMessageBox.showinfo('Complete', message)
def rf_validate(mode, serial_number):
print 'validating...'
#print 'Current mode is', mode
# Create XML file to be passed to F1C service
name_of_file_generated, f1c_type = rf_generate_xml(serial_number)
print '%s has been written to %s' % (
name_of_file_generated, submitted_path_name)
#print f1c_type, 'is the current Field1Click type'
# Get the response from the IT service for the xml file created
# 0 = Missing | 1 = Success | 2 = Failed | 3 = DSN
response = watch_for_response(name_of_file_generated)
# Based on the response, figure out how to proceed
#'LaunchDSN' | 'ERROR' | 'TIMEOUT' | 'DONE'
next_step = interpret_response(name_of_file_generated, response, f1c_type)
return next_step
def rf_test_software(mode, serial_number):
print 'launching rf test software...'
launch_rf()
test_log_name = wait_for_rf(serial_number)
print 'RF testing has completed'
print '%s has been written to %s' % (
test_log_name, local_dsn_xml_path_name)
next_step = interpret_response(test_log_name, 3, 'RF')
print 'Proceeding to', next_step
time.sleep(5)
return next_step
def dsn_test_software(mode, serial_number):
print 'This function has been removed'
return 'FINAL'
def rf_timeout(mode, serial_number):
print 'timing out...'
name_of_file_generated, f1c_type = rf_generate_xml(serial_number)
print '%s has been written to %s' % (
name_of_file_generated, submitted_path_name)
#print f1c_type, 'is the current Field1Click type'
# Get the response from the IT service for the xml file created
# 0 = Missing | 1 = Success | 2 = Failed | 3 = DSN
response = watch_for_response(name_of_file_generated)
# Based on the response, figure out how to proceed
#'LaunchDSN' | 'ERROR' | 'TIMEOUT' | 'DONE'
next_step = interpret_response(name_of_file_generated, response, f1c_type)
return next_step
def rf_generate_xml(sn):
global submitted_path_name
config_file_variables = config_file_parsing()
xml_data = open_file_return_contents(path_name, 'F1Click_template.xml')
if mode in ['test', 'devtest']:
timestamp = '1900-01-01 12-00'
else:
now = datetime.datetime.now()
timestamp = '%s-%s-%s %s-%s' % (
now.year, now.month, now.day, now.hour, now.minute)
config_file_variables['<SerialNumber>'] = sn
site = config_file_variables['<Location>']
stage_names = find_stage_names(site)
tags_to_write = [
'<Location>', '<Client>', '<Contract>', '<ProcessType>',
'<WorkCenter>', '<UserName>', '<UserPassword>', '<OrderProcessType>',
'<HostName>', '<SerialNumber>']
for each in tags_to_write:
position = xml_data.find(each) + len(each)
# Making everything upper case except for:
# user name, user password, and host name
# Not really sure if those are appropriate to remain as is?
if each in ['<UserPassword>', '<UserName>', '<HostName>']:
xml_data = data_insert(
xml_data, str(config_file_variables[each]), position)
else:
xml_data = data_insert(
xml_data, str.upper(config_file_variables[each]), position)
#print config_file_variables['<ProcessType>']
if config_file_variables['<ProcessType>'] == 'F1C_VALIDATION':
f1c_type = 'VALIDATE'
elif config_file_variables['<ProcessType>'] == 'F1C_TIMEOUT':
f1c_type = 'TIMEOUT'
for stage in stage_names:
if stage == config_file_variables['<WorkCenter>']:
position = xml_data.find('<ResultCode>') + len('<ResultCode>')
xml_data = data_insert(xml_data, stage_names[stage], position)
position = xml_data.find('<Notes>', position) + len('<Notes>')
# print 'writing', config_file_variables['<Notes>'], 'to xml'
xml_data = data_insert(
xml_data, 'notes from JPC for %s success\n%s', position
) % (stage, config_file_variables['<Notes>'])
else:
f1c_type = 'UNKNOWN'
print 'Unknown type of <ProcessType> in REY.config file'
with open(
os.path.join(submitted_path_name, '%s-%s %s.xml') %
(sn, f1c_type, timestamp), 'wb'
) as xml_file:
xml_file.write(xml_data)
return ['%s-%s %s.xml' % (
sn, f1c_type, timestamp), f1c_type]
def get_serial_number():
popup = GetSerialNumber()
if popup.command():
return popup.command()
else:
message = 'Serial number window was closed without entry.'
message += '\nNow exiting...'
tkMessageBox.showerror('Error', message)
sys.exit(1)
class GetSerialNumber:
def __init__(self, default_sn=''):
self.master = Tk()
self.master.wm_title('DUT serial number')
self.master.iconbitmap(default='favicon.ico')
l_text = 'Please scan or enter serial number for device under test'
self.label = Label(self.master, text=l_text)
self.label.pack()
self.entry = Entry(self.master, width=50)
self.entry.focus_set()
self.entry.pack()
self.button = Button(
self.master, text="OK", command=self.command, default=ACTIVE)
self.button.pack()
self.master.bind('<Return>', self.command)
self.master.mainloop()
def command(self, event=None):
y = self.entry.get()
if y == '':
title = 'Invalid SN'
message = 'No serial number entered'
tkMessageBox.showerror(title, message)
else:
self.master.withdraw()
self.master.quit()
return y
class CancelButton(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.window = Tk()
self.window.geometry('+0+0')
self.window.wm_attributes('-topmost', 1)
self.window.overrideredirect(1)
self.button2 = Button(
self.window, text='Cancel Auto-timeout Process', command=self.cancel)
self.button2.configure(background='red')
self.button2.pack()
def cancel(self):
sys.exit()
def config_file_parsing():
global path_name
config_filename = 'REY.config'
interesting_tags = [
'<Location>', '<Client>', '<Contract>', '<ProcessType>', '<Notes>',
'<WorkCenter>', '<UserName>', '<UserPassword>', '<OrderProcessType>',
'<HostName>', '<LogPath>', '<DSNLocalLogPath>', '<DSNRemoteLogPath>',
'<TestProgram>', '<TestCommand>']
config_information = {}
config_file_data = open_file_return_contents(path_name, config_filename)
if config_file_data:
for each in interesting_tags:
config_information[each] = parse(config_file_data, each)
# print config_information[each], each
#find all scripts that included between the <TimeoutScriptsAllowed> tag
timeout_data = between_the_tags(
config_file_data, 'TimeoutScriptsAllowed', 0)
config_information['<TimeoutScriptsAllowed>'] = multi_parse(
timeout_data, '<Script>')
return config_information
def open_file_return_contents(pathname, filename):
try:
with open(os.path.join(pathname, filename)) as f:
return f.read()
except IOError:
print filename, 'is not present in directory:\n ', pathname
def parse(data, tag, initial_pos=0):
tag_information_start = data.find(tag, initial_pos) + len(tag)
tag_information_end = data.find('<', tag_information_start)
tag_information = data[tag_information_start:tag_information_end]
return tag_information
def multi_parse(data, tag, initial_pos=0):
list_of_found_items = []
for each in range(data.count(tag)):
list_of_found_items.append(parse(data, tag))
data = data[data.find(tag) + len(tag):]
return list_of_found_items
def between_the_tags(data, tag, start_pos=0):
tag_start = data.find('<' + tag + '>', start_pos) + len(tag + '<>')
tag_end = data.find('</' + tag + '>', tag_start+1)
return data[tag_start:tag_end]
def beginning_and_end_tags(data, tag, start_pos):
start = data.find('<'+tag, start_pos) + len('<'+tag)
end = data.find('</'+tag, start)
return start, end
def data_insert(original, new, pos):
return original[:pos] + new + original[pos:]
def data_remove(original, pos1, pos2):
return original[:pos1] + original[pos2:]
def find_stage_names(site):
# Check to see if status has been written to config file
contents = open_file_return_contents(path_name, 'REY.config')
if contents.count('<StageStatus'):
return {config_file_variables['<WorkCenter>']: between_the_tags(contents, 'StageStatus')}
if site == 'SITE A':
return {
'WC_1': 'TO_WC2',
'WC_2': 'TO_WC3',
'WC_3': None, }
elif site == 'SITE B':
return {
'WC_1': 'TO_WC2',
'WC_2': None, }
elif site == 'SITE C':
return {
'WC_1': 'TO_WC2',
'WC_2': 'TO_WC3',
'WC_3': None, }
else:
print 'Process Control Engine has not been setup for this location yet'
return {}
def watch_for_response(filename, timeout=60):
global response_path_name, failed_path_name
t0 = time.time()
path = os.path.join(response_path_name, filename)
print 'Waiting for', filename
if os.path.exists(path):
print 'Response file %s is already in %s' % (filename, path)
return 1
while time.time() - t0 < timeout:
time.sleep(3)
print '.',
sys.stdout.flush()
if os.path.exists(path):
print '\nReceived response file %s' % filename
return 1
print '\nResponse file not received after 60 seconds'
filename = filename.replace('.xml', '-ERROR.xml')
err_path = os.path.join(failed_path_name, filename)
if os.path.exists(err_path):
print 'Found response file in %s' % err_path
return 2
else:
print 'Nothing found'
return 0
def interpret_response(file_name, response_type, type):
global config_file_variables
site = config_file_variables['<Location>']
if type == 'VALIDATE':
if response_type == 2:
file_name = file_name.replace('.xml', '-ERROR.xml')
if response_type == 1 or response_type == 2:
IT_result = parse_response_file(
file_name, response_type, '<ResultMessage>')
if IT_result == 'SUCCESS':
print 'F1C has validated that unit is in correct work center.'
if site == 'SITE C':
return 'LaunchRF'
else:
return 'LaunchDSN'
elif 'Invalid Workcenter.' in IT_result:
print 'SYSTEM IS IN THE WRONG WORK CENTER.'
print IT_result
return 'ERROR'
elif IT_result == 'ITEM NOT FOUND.':
print 'SYSTEM SERIAL NUMBER DOES NOT EXIST IN SL.'
return 'ERROR'
elif IT_result == '':
print 'IT SERVICE RETURNED AN EMPTY RESPONSE'
return 'ERROR'
else:
print 'UNKNOWN STATUS FOR THIS UNIT.',
print ' PLEASE REPORT FOR INVESTIGATION.'
return 'ERROR'
else:
print 'No response file in /FROM or /FAILED folder after 60 secs'
print 'IT IS POSSIBLE THAT NETWORK CONNECTION HAS DROPPED'
return 'ERROR'
elif type == 'TIMEOUT':
if response_type == 2:
file_name = file_name.replace('.xml', '-ERROR.xml')
if response_type == 1 or response_type == 2:
IT_result = parse_response_file(
file_name, response_type, '<Result>')
if IT_result == 'SUCCESS':
print 'UNIT HAS SUCCESSFULLY TIMED OUT',
print 'AND IS READY TO MOVE TO NEXT STAGE'
return 'DONE'
elif IT_result == 'ERROR':
error_reported = parse_response_file(
file_name, response_type, '<ResultMessage>')
if 'is at work center' in error_reported:
print 'SYSTEM IN WRONG WORK CENTER'
print error_reported
return 'TO_ERROR'
elif 'Content is not allowed' in error_reported:
print 'SYSTEM MISSING RESULTS INFORMATION'
print error_reported
return 'TO_ERROR'
elif 'Serial Number does not exist' in error_reported:
print 'SYSTEM SERIAL NUMBER DOES NOT EXIST IN SL'
return 'TO_ERROR'
else:
print 'UNKNOWN ERROR FOR THIS UNIT.',
print ' PLEASE REPORT FOR INVESTIGATION'
return 'TO_ERROR'
else:
print 'UNKNOWN STATUS RETURNED FOR THIS UNIT.',
print ' PLEASE REPORT FOR INVESTIGATION'
return 'TO_ERROR'
else:
print 'No response file received in /FROM or /FAILED folders'
return 'TO_ERROR'
elif type == 'DSN':
DSN_result = parse_response_file(
file_name, response_type, '<ScriptStatus>')
DSN_script_name = parse_response_file(
file_name, response_type, '<ScriptName>')
print 'DSN has', DSN_result, 'the script named', DSN_script_name
if site == 'SITE A':
timeout_candidate = False
timeout_scripts = config_file_variables['<TimeoutScriptsAllowed>']
for each in timeout_scripts:
if each in DSN_script_name:
timeout_candidate = True
#copy from local dsn location to remote dsn location
shutil.copy(
os.path.join(local_dsn_xml_path_name, file_name),
os.path.join(remote_dsn_xml_path_name, file_name))
if DSN_result == 'PASSED' and timeout_candidate is True:
update_configuration_file()
return 'TIMEOUT'
elif DSN_result == 'PASSED' and timeout_candidate is False:
return 'MANUAL'
elif DSN_result == 'FAILED':
return 'ERROR'
else:
print 'Unknown Process Type'
return 'ERROR'
elif site == 'SITE B':
timeout_candidate = False
#copy from local dsn location to remote dsn location
shutil.copy(
os.path.join(local_dsn_xml_path_name, file_name),
os.path.join(remote_dsn_xml_path_name, file_name))
#LOGIC FOR BYDGOSCZC AUTO-TIMEOUT IS HERE
if DSN_result == 'PASSED':
update_configuration_file()
return 'TIMEOUT'
elif DSN_result == 'FAILED':
dsn_log_contents = open_file_return_contents(
local_dsn_xml_path_name, file_name)
notes_to_save = find_dsn_fails(dsn_log_contents)
failed_sl_codes = lookup_sl_fail_codes(notes_to_save)
print failed_sl_codes
update_configuration_file(notes=notes_to_save)
return 'TIMEOUT'
shutil.copy(
os.path.join(local_dsn_xml_path_name, file_name),
os.path.join(remote_dsn_xml_path_name, file_name))
else:
print 'Unknown dsn result routing rules for this location'
elif type == 'RF':
site = config_file_variables['<Location>']
total_failures, full_log = parse_rf_results(
local_dsn_xml_path_name, file_name)
if total_failures == '0':
test_status = 'PASSED'
else:
test_status = 'FAILED'
print 'RF test has %s testing' % test_status
if site == 'SITE C':
timeout_candidate = False
# copy from local log location to remote log location
shutil.copy(
os.path.join(local_dsn_xml_path_name, file_name),
os.path.join(remote_dsn_xml_path_name, file_name))
# LOGIC FOR SITE C TEST AUTO-TIMEOUT
if test_status == 'PASSED':
update_configuration_file()
lazy_update(test_status)
return 'TIMEOUT'
elif test_status == 'FAILED':
notes_to_save = find_rf_failures(full_log)
update_configuration_file(notes=notes_to_save)
lazy_update(test_status)
return 'TIMEOUT'
def parse_rf_results(log_path, filename):
entire_contents = open_file_return_contents(log_path, filename)
total_failures = between_the_tags(entire_contents, 'total_failed', 0)
return total_failures, entire_contents
def parse_response_file(file_name, location, tag):
# start from beginning of file unless overwritten later
start_searching_from = 0
if location == 1:
file_location = response_path_name
if location == 2:
file_location = failed_path_name
if location == 3:
file_location = local_dsn_xml_path_name
response_file_data = open_file_return_contents(file_location, file_name)
if location == 1 or location == 2:
x = '<ProcessResult>'
start_searching_from = response_file_data.find(x) + len(x)
results = parse(response_file_data, tag, start_searching_from)
return results
def wait_for_rf(serial_number):
before = [f for f in os.listdir(local_dsn_xml_path_name)]
print '...waiting for new_file log file for dut %s in %s' % (
serial_number, local_dsn_xml_path_name)
while True:
time.sleep(15)
after = [f for f in os.listdir(local_dsn_xml_path_name)]
added = [f for f in after if not f in before]
if added:
for new_file in added:
if sn_look_up_and_match(local_dsn_xml_path_name, new_file, serial_number):
print 'found file %s with serial number %s' % (new_file, serial_number)
return new_file
before = after
def sn_look_up_and_match(logpath, filename, serialnumber):
if '.xml' in filename:
data = open_file_return_contents(logpath, filename)
sn_from_log = between_the_tags(data, 'dut_serial_number', 0)
print 'detected serial number %s from new log file' % (sn_from_log)
if sn_from_log == serialnumber:
return True
return False
def launch_rf():
try:
os.startfile(rf_test_program, rf_test_command)
except WindowsError:
subprocess.call([rf_test_program, rf_test_command])
def find_rf_failures(entire_contents):
result = ''
failed_tests = []
results_start, results_end = beginning_and_end_tags(
entire_contents, 'test_results>', 0)
count = entire_contents.count('<test>', results_start, results_end)
result += 'Detected Failure'
result += '\nTests run: '+str(count-2)
result += '\nFailures include:'
start = results_start
for i in range(count-2):
test_start, test_end = beginning_and_end_tags(
entire_contents, 'test>', start)
test_step_start, test_step_end = beginning_and_end_tags(
entire_contents, 'test_step>', start)
test_step = entire_contents[test_step_start:test_step_end]
title_start, title_end = beginning_and_end_tags(
entire_contents, 'title>', start)
title = entire_contents[title_start:title_end]
pass_fail_start, pass_fail_end = beginning_and_end_tags(
entire_contents, 'pass_fail>', start)
pass_fail_status = entire_contents[pass_fail_start:pass_fail_end]
if pass_fail_status != 'Pass':
# result += '\n'+'-'*80
result += '\n%s: %s: %s' % (test_step, title, pass_fail_status)
failed_tests.append(title)
start = test_end
result += '\n'+'-'*80
result += '\nFail Code(s): '+str(failcode_lookup(failed_tests))
return result
def failcode_lookup(list_of_tests):
unit_fc = []
failcodes = {'a': 33.2,
'b': 33.2,
'c': 33.2,
'd': 33.2,
'e': 33.2,
'f': 33.2,
'g': 33.2,
'h': 37.2,
'i': 33.2,
'j': 33.2,
'k': 33.2,
'l': 33.2,
'm': 33.2,
'n': 33.2,
'o': 33.2,
'p': 33.2,
'q': 33.2,
'r': 33.2,
's': 33.2,
't': 33.2,
'u': 33.2,
'v': 37.2,
'w': 33.2,
'x': 33.2,
'y': 33.2,
'z': 33.2,
'aa': 33.2,
'ab': 33.2,
'ac': 33.2,
'ad': 33.2,
'ad': 33.2,
'ae': 33.2,
'af': 33.2,
'ag': 32.2, }
for failure in list_of_tests:
if failure in failcodes:
if failcodes[failure] not in unit_fc:
unit_fc.append(failcodes[failure])
else:
unit_fc.append('Invalid')
return str(unit_fc)
def update_configuration_file(notes=None):
#This function modifies the configuration file stored on the local machine
#This leaves the file on the server alone
config_filename = 'REY.config'
config_file_data = open_file_return_contents(path_name, config_filename)
pos_a1 = config_file_data.find('<ProcessType>') + len('<ProcessType>')
pos_a2 = config_file_data.find('</ProcessType>')
config_file_data = data_remove(config_file_data, pos_a1, pos_a2)
pos_a = config_file_data.find('<ProcessType>') + len('<ProcessType>')
config_file_data = data_insert(config_file_data, 'F1C_TIMEOUT', pos_a)
if notes:
pos_b1 = config_file_data.find('<Notes>') + len('<Notes>')
pos_b2 = config_file_data.find('</Notes>')
config_file_data = data_remove(config_file_data, pos_b1, pos_b2)
pos_b = config_file_data.find('<Notes>') + len('<Notes>')
config_file_data = data_insert(config_file_data, notes, pos_b)
with open(os.path.join(path_name, config_filename), 'wb') as f:
f.write(config_file_data)
# print 'updated config file JPC.config to be', config_file_data
def lazy_update(status):
config_filename = 'REY.config'
with open(os.path.join(path_name, config_filename), 'ab') as f:
f.write('<StageStatus>%s</StageStatus>' % (status))
def usage():
print '''
Accepted arguments include:
'test' (without quotes) = test mode
Configuaration file variables (REY.config)
must reside in same directory as script
XML template (xxx_template.xml)
must reside in same directory as script
'''
if __name__ == "__main__":
arguments = []
dut_serial_number = ''
mode = 'NOT test'
for arg in sys.argv[1:]:
x = ['help', '-help', '--help', 'h', '-h', '--h', '?', '-?', '--?']
if arg in x:
usage()
sys.exit()
elif arg in ['test', '-test']:
print 'mode set to test'
mode = 'test'
else:
arguments.append(arg)
usage()
sys.exit()
try:
if os.environ['COMPUTERNAME'] == 'JGLOF061':
mode = 'devtest'
except KeyError:
pass
path_name = os.getcwd()
# Always start process with a fresh copy of the config file
shutil.copy(
os.path.join(path_name, 'REY - Master.config'),
os.path.join(path_name, 'REY.config'))
#Variables pulled from REY.config file
config_file_variables = config_file_parsing()
if config_file_variables:
path_name = os.getcwd()
log_path_name = config_file_variables['<LogPath>']
submitted_path_name = os.path.join(log_path_name, 'To')
response_path_name = os.path.join(log_path_name, 'From')
failed_path_name = os.path.join(log_path_name, 'Failed')
# command = '"sudo /usr/local/bin/dcp/startdsn ; bash"'
# dsn_launcher = 'gnome-terminal -x bash -c %s' % (command)
# oct_path = 'C:\Users\schroedb\Documents\Process Control Engine\Octopus\sd\sd\\'
# octopus_command = 'Octopus_COMM_start.CMD'
# rf_test_program = 'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'
# rf_test_command = os.path.join(path_name, 'test_software.txt')
rf_test_program = config_file_variables['<TestProgram>']
rf_test_command = config_file_variables['<TestCommand>']
local_dsn_xml_path_name = config_file_variables['<DSNLocalLogPath>']
remote_dsn_xml_path_name = config_file_variables['<DSNRemoteLogPath>']
if mode == 'devtest':
submitted_path_name = 'P:\logs\Client\To'
response_path_name = 'P:\logs\Client\From'
failed_path_name = 'P:\logs\Client\Failed'
pass
else:
print 'REY.config appears to be empty'
sys.exit()
cancelbutton = CancelButton()
cancelbutton.start()
#t2 = threading.Thread(target=rf_process_control, args=(mode, ))
t2 = threading.Thread(target=rf_process_control(mode))
t2.start()
#t2.join()
#rf_process_control(mode)