-
Notifications
You must be signed in to change notification settings - Fork 3
/
pp_web_validate.py
1536 lines (1218 loc) · 65.7 KB
/
pp_web_validate.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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import json
import configparser
import remi.gui as gui
from remi_plus import AdaptableDialog
from pp_utils import parse_rectangle
from pp_timeofday import TimeOfDay
class ViewBackup(AdaptableDialog):
def __init__(self):
self.text=''
super(ViewBackup, self).__init__('Backup','',width=600,height=700,confirm_name='Done')
self.textb = gui.TextInput(width=550,height=600,single_line=False)
self.append_field(self.textb,'text')
def insert(self,text):
self.text +=text
self.textb.set_value(self.text)
@gui.decorate_event
def confirm_dialog(self,emitter):
self.hide()
def view_tracks_backup(self,pp_profile_dir,medialist):
if medialist !='':
backup_dir=pp_profile_dir.replace('pp_profiles','pp_profiles.bak')
medialist_path=backup_dir+os.sep+medialist
#print('tracks backup',medialist_path)
if os.path.exists(medialist_path):
ifile = open(medialist_path, 'r')
mdict = json.load(ifile)
ifile.close()
self.insert('\nTRACKS\n=======\n')
self.insert('Backup Version: '+mdict['issue'])
for i in mdict['tracks']:
self.insert_items(i,'track-ref')
else:
self.insert('\nBackup medialist not found: '+medialist_path+'\n')
def view_show_backup(self,pp_profile_dir,show_params):
backup_dir=pp_profile_dir.replace('pp_profiles','pp_profiles.bak')
showlist_path=backup_dir+os.sep+'pp_showlist.json'
#print('show backup',showlist_path)
show_ref=show_params['show-ref']
if os.path.exists(showlist_path):
ifile = open(showlist_path, 'r')
mdict = json.load(ifile)
ifile.close()
self.insert('\nSHOW\n======\n')
self.insert('Backup Version: '+mdict['issue'])
for show in mdict['shows']:
if show['show-ref']==show_ref:
self.insert_items(show,'show-ref')
else:
self.insert('\nBackup showlist not found: '+showlist_path+'\n')
def insert_items(self,item,ref):
self.insert('\n----------------------------------------------------------------\n')
self.insert('\n'+item['type']+' "'+item['title']+'" ['+item[ref]+']'+'\n')
for field in item:
if '\n' in item[field]:
self.insert(field+' = \n')
lines=item[field].split('\n')
for line in lines:
self.insert(line+'\n')
else:
self.insert (field+' = '+item[field]+'\n')
class Validator(AdaptableDialog):
def __init__(self, title):
self.text=''
self.errors=0
self.warnings=0
super(Validator, self).__init__('Validation Result','',width=600,height=700,confirm_name='Done')
self.textb = gui.TextInput(width=550,height=600,single_line=False)
self.append_field(self.textb,'text')
@gui.decorate_event
def confirm_dialog(self,emitter):
self.hide()
def display(self,priority,text):
if priority == 'f': self.errors+=1
if priority == 'w':self.warnings +=1
if self.display_it is False: return
if priority == 't':
self.insert(text+"\n")
if priority == 'f':
self.insert(" ** Error: "+text+"\n")
if priority == 'w':
self.insert(" ** Warning: "+text+"\n")
def insert(self,text):
self.text +=text
self.textb.set_value(self.text)
def stats(self,pp_profile):
if self.display_it is False: return
self.text="\nERRORS: "+str(self.errors)+"\nWARNINGS: "+str(self.warnings)+"\n\n"+self.text
self.text="\nVALIDATING PROFILE '"+ pp_profile + "'\n"+self.text
self.textb.set_value(self.text)
def num_errors(self):
return self.errors
def validate_profile(self, pp_dir, pp_home, pp_profile,editor_issue,display_it):
self.display_it=display_it
# USES
# self.current_showlist
# CREATES
# v_media_lists - file names of all medialists in the profile
# v_shows
# v_track_labels - list of track labels in current medialist.
# v_show_labels - list of show labels in the showlist
# v_medialist_refs - list of references to medialist files in the showlist
# open results display
if not os.path.exists(pp_profile+os.sep+"pp_showlist.json"):
self.display('f',"pp_showlist.json not in profile")
self.display('t', "Validation Aborted")
return False
ifile = open(pp_profile+os.sep+"pp_showlist.json", 'r')
sdict= json.load(ifile)
ifile.close()
v_shows=sdict['shows']
if 'issue' in sdict:
profile_issue= sdict['issue']
else:
profile_issue="1.0"
if profile_issue != editor_issue:
self.display('f',"Profile version "+profile_issue+ " is different to that editor")
self.display('t', "Validation Aborted")
return False
# MAKE LIST OF SHOW LABELS
v_show_labels=[]
for show in v_shows:
if show['type'] != 'start': v_show_labels.append(show['show-ref'])
# CHECK ALL MEDIALISTS AND THEIR TRACKS
v_media_lists = []
for medialist_file in os.listdir(pp_profile):
if not medialist_file.endswith(".json") and medialist_file not in ('readme.txt') and not os.path.isdir(pp_profile+os.sep+medialist_file):
self.display('w',"Placing a media file in a profile is discouraged: "+ medialist_file + '\n Place it in a directory')
if medialist_file.endswith(".json") and medialist_file not in ('pp_showlist.json','schedule.json'):
self.display('t',"\nChecking medialist '"+medialist_file+"'")
v_media_lists.append(medialist_file)
# open a medialist and test its tracks
ifile = open(pp_profile + os.sep + medialist_file, 'r')
sdict= json.load(ifile)
ifile.close()
tracks = sdict['tracks']
if 'issue' in sdict:
medialist_issue= sdict['issue']
else:
medialist_issue="1.0"
# check issue of medialist
if medialist_issue != editor_issue:
self.display('f',"Medialist version "+medialist_issue+ " is different to that editor")
self.display('t', "Validation Aborted")
return False
# open a medialist and test its tracks
v_track_labels=[]
anonymous=0
for track in tracks:
self.display('t'," Checking track '"+track['title']+"'")
# check track-ref
if track['track-ref'] == '':
anonymous+=1
else:
if track['track-ref'] in v_track_labels:
self.display('f',"'duplicate track reference: "+ track['track-ref'])
v_track_labels.append(track['track-ref'])
# warn if media tracks blank where optional
if track['type'] in ('audio','image'):
if track['location'].strip() == '':
self.display('w',"blank location")
# check location of relative media tracks where present
if track['type'] in ('audio','image'):
track_file=track['location']
if track_file.strip() != '' and track_file[0] == "+":
track_file=pp_home+track_file[1:]
if not os.path.exists(track_file): self.display('f',"location "+track['location']+ " Media File not Found")
if track_file.strip() != '' and track_file[0] == "@":
track_file=pp_profile+track_file[1:]
if not os.path.exists(track_file): self.display('f',"location "+track['location']+ " Media File not Found")
if track['type'] in ('mpv','audio','message','image','chrome','menu'):
# check common fields
self.check_animate('animate-begin',track['animate-begin'])
self.check_animate('animate-end',track['animate-end'])
self.check_plugin(track['plugin'],pp_home,pp_profile)
self.check_show_control(track['show-control-begin'],v_show_labels)
self.check_show_control(track['show-control-end'],v_show_labels)
if track['background-image'] != '':
track_file=track['background-image']
if track_file[0] == "+":
track_file=pp_home+track_file[1:]
if not os.path.exists(track_file): self.display('f',"background-image "+track['background-image']+ " background image file not found")
if track_file[0] == "@":
track_file=pp_profile+track_file[1:]
if not os.path.exists(track_file): self.display('f',"location "+track['location']+ " Background Image not Found")
if track['track-text'] != "":
if track['track-text-x'] != "" and not track['track-text-x'].isdigit(): self.display('f',"'Track Text x position' is not a positive integer")
if track['track-text-y'] != "" and not track['track-text-y'].isdigit(): self.display('f',"'Track Text y Position' is not a positive integer")
if track['track-text-justify'] != "" and track['track-text-justify'] not in ('left','right','center'): self.display('f',"'Track Text Justify' has illegal value")
if track['type']=='menu':
self.check_menu(track)
if track['type'] == "image":
if track['pause-timeout'] != "" and not track['pause-timeout'].isdigit():
self.display('f',"'Pause Timeout' is not blank or a positive integer")
else:
if track['pause-timeout'] != "" and int(track['pause-timeout']) < 1: self.display('f',"'Pause Timeout' is less than 1")
self.check_float_duration('track','Image Duration',track['duration'])
if track['image-rotate'] != "" and not track['image-rotate'].isdigit(): self.display('f',"'Image Rotation' is not blank, 0 or a positive integer")
self.check_image_window('track','image-window',track['image-window'])
if track['type'] == "vlc":
self.display('f',"'VLC Video Track has been removed from Pi Presents")
if track['type'] == "mpv":
if track['pause-timeout'] != "" and not track['pause-timeout'].isdigit():
self.display('f',"'Pause Timeout' is not blank or a positive integer")
else:
if track['pause-timeout'] != "" and int(track['pause-timeout']) < 1: self.display('f',"'Pause Timeout' is less than 1")
self.check_mpv_video_window('track','MPV Window',track['mpv-window'])
self.check_mpv_volume('track','MPV Volume',track['mpv-volume'])
self.check_mpv_max_volume('track','MPV Max Volume',track['mpv-max-volume'])
if track['type'] == "audio":
if track['pause-timeout'] != "" and not track['pause-timeout'].isdigit():
self.display('f',"'Pause Timeout' is not blank or a positive integer")
else:
if track['pause-timeout'] != "" and int(track['pause-timeout']) < 1: self.display('f',"'Pause Timeout' is less than 1")
self.check_float_duration('track','Audio Duration',track['duration'])
if track['duration'] == '0' : self.display('w',"'Duration' of an audio track is zero")
self.check_volume('track','mplayer-volume',track['mplayer-volume'])
if track['type'] == "message":
self.check_float_duration('track','Message Duration',track['duration'])
if track['text'] != "":
if track['message-x'] != '' and not track['message-x'].isdigit(): self.display('f',"'Message x Position' is not blank, a positive integer")
if track['message-y'] != '' and not track['message-y'].isdigit(): self.display('f',"'Message y Position' is not blank, a positive integer")
if track['message-colour']=='': self.display('f',"'Message Text Colour' is blank")
if track['message-font']=='': self.display('f',"Message Text Font' is blank")
if track['type'] == 'chrome':
self.check_float_duration('track','Chrome Web Duration',track['duration'])
self.check_browser_commands(track['browser-commands'],'chrome')
self.check_chrome_window('track','Chrome Web Window',track['chrome-window'])
self.check_chrome_zoom('track','Chrome Zoom',track['chrome-zoom'])
# SHOW TRACK - CHECK CROSS REF TRACK TO SHOW
if track['type'] == 'show':
if track['sub-show'] == "":
self.display('f',"No 'Sub-show to Run'")
else:
if track['sub-show'] not in v_show_labels: self.display('f',"Show "+track['sub-show'] + " does not exist")
# if anonymous == 0 :self.display('w',"zero anonymous tracks in medialist " + file)
# check for duplicate track-labels
# !!!!!!!!!!!!!!!!!! add check for all labels
# SHOWS
# find start show and test it, test show-refs at the same time
found=0
for show in v_shows:
if show['type'] == 'start':
self.display('t',"\nChecking show '"+show['title'] + "' first pass")
found+=1
if show['show-ref'] != 'start': self.display('f',"start show has incorrect label")
else:
self.display('t',"\nChecking show '"+show['title'] + "' first pass")
if show['show-ref'] == '': self.display('f',"Show Reference is blank")
if ' ' in show['show-ref']: self.display('f',"Spaces not allowed in Show Reference: " + show['show-ref'])
if found == 0:self.display('f',"There is no start show")
if found > 1:self.display('f',"There is more than 1 start show")
# check for duplicate show-labels
for show_label in v_show_labels:
found = 0
for show in v_shows:
if show['show-ref'] == show_label: found+=1
if found > 1: self.display('f',show_label + " is defined more than once")
# check other things about all the shows and create a list of medialist file references
v_medialist_refs=[]
for show in v_shows:
if show['type'] == "start":
self.display('t',"\nChecking show '"+show['title']+ "' second pass" )
self.check_start_shows(show,v_show_labels)
else:
self.display('t',"\nChecking show '"+show['title']+ "' second pass" )
if show['medialist']=='': self.display('f', show['show-ref']+ " show has blank medialist")
if '.json' not in show['medialist']:
self.display('f', show['show-ref']+ " show has invalid medialist")
self.display('t', "Validation Aborted")
return False
if show['medialist'] not in v_media_lists:
self.display('f', "'"+show['medialist']+ "' medialist not found")
self.display('t', "Validation Aborted")
return False
if not os.path.exists(pp_profile + os.sep + show['medialist']):
self.display('f', "'"+show['medialist']+ "' medialist file does not exist")
self.display('t', "Validation Aborted")
return False
v_medialist_refs.append(show['medialist'])
# open medialist and produce a dictionary of its contents for use later
ifile = open(pp_profile + os.sep + show['medialist'], 'r')
tracks = json.load(ifile)['tracks']
ifile.close()
# make a list of the track labels
v_track_labels=[]
for track in tracks:
if track['track-ref'] !='':
v_track_labels.append(track['track-ref'])
# check common fields in the show
#show
self.check_show_canvas('show','Show Canvas',show['show-canvas'])
#show background and text
if show['show-text'] != "":
if show['show-text-x'] != "" and not show['show-text-x'].isdigit(): self.display('f',"'Show Text x Position' is not a positive integer")
if show['show-text-y'] != "" and not show['show-text-y'].isdigit(): self.display('f',"'Show Text y Position' is not a positive integer")
if show['show-text-colour']=='': self.display('f',"'Show Text Colour' is blank")
if show['show-text-font']=='': self.display('f',"'Show Text Font' is blank")
background_image_file=show['background-image']
if background_image_file.strip() != '' and background_image_file[0] == "+":
track_file=pp_home+background_image_file[1:]
if not os.path.exists(track_file): self.display('f',"Background Image "+show['background-image']+ " background image file not found")
if background_image_file.strip() != '' and background_image_file[0] == "@":
track_file=pp_profile+background_image_file[1:]
if not os.path.exists(track_file): self.display('f',"Background Image "+show['background-image']+ " background image file not found")
#track defaults
if show['track-text-x'] != ''and not show['track-text-x'].isdigit(): self.display('f',"'Track Text x Position' is not a positive integer")
if show['track-text-y'] != ''and not show['track-text-y'].isdigit(): self.display('f',"'Track Text y Position' is not a positive integer")
if show['track-text-colour']=='': self.display('f',"'Track Text Colour' is blank")
if show['track-text-font']=='': self.display('f',"'Track Text Font' is blank")
if show['track-text-justify'] not in ('left','right','center'): self.display('f',"'Track Text Justify' has illegal value")
self.check_float_duration('show','Duration',show['duration'])
if show['pause-timeout'] != "" and not show['pause-timeout'].isdigit():
self.display('f',"'Pause Timeout' is not blank or a positive integer")
else:
if show['pause-timeout'] != "" and int(show['pause-timeout']) < 1: self.display('f',"'Pause Timeout' is less than 1")
if not show['image-rotate'].isdigit(): self.display('f',"'Image Rotation' is not 0 or a positive integer")
self.check_volume('show','Audio Volume',show['mplayer-volume'])
self.check_mpv_video_window('show','MPV Window',show['mpv-window'])
self.check_mpv_volume('show','MPV Volume',show['mpv-volume'])
self.check_image_window('show','Image Window',show['image-window'])
self.check_chrome_zoom('show','Chrome Zoom',show['chrome-zoom'])
#eggtimer
if show['eggtimer-text'] != "":
if show['eggtimer-colour']=='': self.display('f',"'Eggtimer Colour' is blank")
if show['eggtimer-font']=='': self.display('f',"'Eggtimer Font' is blank")
if not show['eggtimer-x']!='' and not show['eggtimer-x'].isdigit(): self.display('f',"'Eggtimer x Position' is not a positive integer")
if not show['eggtimer-y']!='' and not show['eggtimer-y'].isdigit(): self.display('f',"'Eggtimer y Position' is not a positive integer")
#check the schedule
self.check_schedule_for_show(show,v_show_labels)
# Validate simple fields of each show type
if show['type'] in ("mediashow",'liveshow'):
if show['child-track-ref'] != '':
if show['child-track-ref'] not in v_track_labels:
self.display('f',"'Child Track ' " + show['child-track-ref'] + ' is not in medialist' )
if not show['hint-x']!='' and not show['hint-y'].isdigit(): self.display('f',"'Hint y Position' is not a positive integer")
if not show['hint-x']!='' and not show['hint-x'].isdigit(): self.display('f',"'Hint x Position' is not a positive integer")
if show['hint-colour']=='': self.display('f',"'Hint Colour' is blank")
if show['hint-font']=='': self.display('f',"'Hint Font' is blank")
self.check_hh_mm_ss('Show Timeout',show['show-timeout'])
self.check_hh_mm_ss('Repeat Interval',show['interval'])
if not show['track-count-limit'].isdigit(): self.display('f',"'Track Count Limit' is not 0 or a positive integer")
if show['trigger-start-type']in('input','input-persist'):
self.check_triggers('Start Trigger Parameters',show['trigger-start-param'])
if show['trigger-next-type'] == 'input':
self.check_triggers('Next Trigger Parameters',show['trigger-next-param'])
if show['trigger-end-type'] == 'input':
self.check_triggers('End Trigger Parameters',show['trigger-end-param'])
self.check_chrome_window('show','Chrome Web Window',show['chrome-window'])
self.check_controls('controls',show['controls'])
#notices
if show['trigger-wait-text'] != "" or show['empty-text'] != "":
if show['admin-colour']=='': self.display('f',"' Notice Text Colour' is blank")
if show['admin-font']=='': self.display('f',"'Notice Text Font' is blank")
if not show['admin-x']!='' and not show['admin-x'].isdigit(): self.display('f',"'Notice Text x Position' is not a positive integer")
if not show['admin-y']!='' and not show['admin-y'].isdigit(): self.display('f',"'Notice Text y Position' is not a positive integer")
if show['type']== 'liveshow':
if show['repeat']=='repeat':
if show['empty-track-ref']=='':
self.display('f','Empty List Track is blank')
else:
if show['empty-track-ref'] not in v_track_labels:
self.display('f','Empty List Track is not in medialist: '+show['empty-track-ref'])
if show['type'] in ("artmediashow",'artliveshow'):
#notices
if show['empty-text'] != "":
if show['admin-colour']=='': self.display('f',"' Notice Text Colour' is blank")
if show['admin-font']=='': self.display('f',"'Notice Text Font' is blank")
if not show['admin-x']!='' and not show['admin-x'].isdigit(): self.display('f',"'Notice Text x Position' is not a positive integer")
if not show['admin-y']!='' and not show['admin-y'].isdigit(): self.display('f',"'Notice Text y Position' is not a positive integer")
self.check_controls('controls',show['controls'])
if show['type'] == "menu":
self.check_hh_mm_ss('Show Timeout',show['show-timeout'])
self.check_hh_mm_ss('Track Timeout',show['track-timeout'])
if show['menu-track-ref']=='':
self.display('f',"'menu track ' is blank")
else:
if show['menu-track-ref'] not in v_track_labels:
self.display('f',"'menu track ' is not in medialist: " + show['menu-track-ref'])
self.check_controls('controls',show['controls'])
if show['type'] == 'hyperlinkshow':
if show['first-track-ref']=='':
self.display('f',"'First Track ' is blank")
else:
if show['first-track-ref'] not in v_track_labels:
self.display('f',"'First track ' is not in medialist: " + show['first-track-ref'])
if show['home-track-ref']=='':
self.display('f',"'Home Track ' is blank")
else:
if show['home-track-ref'] not in v_track_labels:
self.display('f',"'Home track ' is not in medialist: " + show['home-track-ref'])
if show['timeout-track-ref']=='':
self.display('w',"'Timeout Track ' is blank")
else:
if show['timeout-track-ref'] not in v_track_labels:
self.display('f',"'timeout track ' is not in medialist: " + show['timeout-track-ref'])
self.check_hyperlinks('links',show['links'],v_track_labels)
self.check_hh_mm_ss('Show Timeout',show['show-timeout'])
self.check_hh_mm_ss('Track Timeout',show['track-timeout'])
if show['type'] == 'radiobuttonshow':
if show['first-track-ref']=='':
self.display('f',"'Home Track ' is blank")
else:
if show['first-track-ref'] not in v_track_labels:
self.display('f',"'first track ' is not in medialist: " + show['first-track-ref'])
self.check_radiobutton_links('links',show['links'],v_track_labels)
self.check_hh_mm_ss('Show Timeout',show['show-timeout'])
self.check_hh_mm_ss('Track Timeout',show['track-timeout'])
self.display('t', "\nVALIDATION COMPLETE")
self.stats(pp_profile)
if self.num_errors() == 0:
return True
else:
return False
# END END END
# ***********************************
# START SHOWS
# ************************************
def check_start_shows(self,show,v_show_labels):
text=show['start-show']
show_count=0
fields = text.split()
for field in fields:
show_count+=1
if field not in v_show_labels:
self.display('f',"start show has undefined Start Show: "+ field)
if show_count == 0:
self.display('w',"start show has zero Start Shows")
#check the schedule
self.check_schedule_for_show(show,v_show_labels)
# ***********************************
# TRIGGERS
# ************************************
def check_triggers(self,field,line):
words=line.split()
if len(words)!=1: self.display('f','Wrong number of fields in: ' + field + ", " + line)
# ***********************************
# VIDEO
# ************************************
def check_volume(self,track_type,field,line): # now audio track only
if track_type == 'show' and line.strip() == '':
self.display('f','Show must specify Audio Track volume: ' + field + ", " + line)
return
if track_type == 'track' and line.strip() == '':
return
if not line.isdigit():
self.display('f','Audio Track Volume must be a positive integer: ' + field + ", " + line)
return
audio_volume= int(line)
if audio_volume == 0:
self.display('w','Audio Track Volume range has changed from -60>0 to 0>100: ' + field + ", " + line)
if audio_volume>100:
self.display('f','Audio Track Volume must be <= 100: ' + field + ", " + line)
return
return
def check_mpv_volume(self,track_type,field,line):
if track_type == 'show' and line.strip() == '':
self.display('f','Show must specify MPV volume: ' + field + ", " + line)
return
if track_type == 'track' and line.strip() == '':
return
if not line.isdigit():
self.display('f','MPV Volume must be a positive integer: ' + field + ", " + line)
return
mpv_volume= int(line)
if mpv_volume>100:
self.display('f','MPV Volume must be <= 100: ' + field + ", " + line)
return
return
def check_mpv_max_volume(self,track_type,field,line):
if track_type == 'track' and line.strip() == '':
return
if not line.isdigit():
self.display('f','MPV Max Volume must be a positive integer: ' + field + ", " + line)
return
mpv_max_volume= int(line)
if mpv_max_volume>100:
self.display('f','MPV Max Volume must be <= 100: ' + field + ", " + line)
return
return
# ***********************************
# TIME SCHEDULER
# ************************************
def check_schedule_for_show(self,show,v_show_labels):
show_type=show['type']
show_ref=show['show-ref']
# print('check schedule for show ',show_type,show_ref)
if 'sched-everyday' in show:
text=show['sched-everyday']
lines=text.splitlines()
#chunk text into lines for one day line (day_lines) and leftover (lines)
while len(lines) != 0:
status,message,day_lines,lines=self.chunk_one_day(lines,show_ref,'everyday')
if status == 'error':
return
if len(day_lines)!=0:
# check one day line and its times
self.check_day(day_lines,'everyday',show_ref,show_type,v_show_labels)
if 'sched-weekday' in show:
text=show['sched-weekday']
lines=text.splitlines()
while len(lines) != 0:
status,message,day_lines,lines=self.chunk_one_day(lines,show_ref,'weekday')
if status == 'error':
return
if len(day_lines)!=0:
self.check_day(day_lines,'weekday',show_ref,show_type,v_show_labels)
if 'sched-monthday' in show:
text=show['sched-monthday']
lines=text.splitlines()
while len(lines) != 0:
status,message,day_lines,lines=self.chunk_one_day(lines,show_ref,'monthday')
# print 'in monthday',day_lines
if status == 'error':
return
if len(day_lines)!=0:
self.check_day(day_lines,'monthday',show_ref,show_type,v_show_labels)
if 'sched-specialday' in show:
text=show['sched-specialday']
lines=text.splitlines()
while len(lines) != 0:
status,message,day_lines,lines=self.chunk_one_day(lines,show_ref,'specialday')
if status == 'error':
return
if len(day_lines)!=0:
self.check_day(day_lines,'specialday',show_ref,show_type,v_show_labels)
def chunk_one_day(self,lines,show_ref,section):
this_day=[]
left_over=[]
#print 'get one day',lines
# check first line is day and move to output
#print lines[0]
if not lines[0].startswith('day'):
self.display('f','Schedule - first line of section ' + section + ' is not day: ' + lines[0] )
return 'error','',[],[]
this_day=[lines[0]]
#print ' this day',this_day
left_over=lines[1:]
# print 'left over',left_over
x_left_over=lines[1:]
for line in x_left_over:
#print 'in loop',line
if line.startswith('day'):
# print 'one day day',this_day,left_over
return 'normal','',this_day,left_over
this_day.append(line)
left_over=left_over[1:]
# print 'one day end',this_day,left_over
return 'normal','',this_day,left_over
def check_day(self,lines,section,show_ref,show_type,v_show_labels):
if section == 'everyday':
self.check_everyday(lines[0],show_ref,'everyday')
elif section == 'weekday':
self.check_weekday(lines[0],show_ref,'weekday')
elif section == 'monthday':
self.check_monthday(lines[0],show_ref,'monthday')
elif section == 'specialday':
self.check_specialday(lines[0],show_ref,'specialday')
else:
self.display('f','Schedule - invalid section name: '+ section)
return
if len(lines) >1:
time_lines=lines[1:]
self.check_time_lines(time_lines,show_ref,show_type,v_show_labels,section)
else:
self.display('w','Schedule - In '+ section+ ' there are zero time lines')
def check_everyday(self,line,show_ref,section):
words=line.split()
if words[0]!='day':
self.display('f', 'error','Schedule - In section '+ section + ' day line does not contain day: '+ line)
if words[1] != 'everyday':
self.display('f','Schedule - In section '+ section + ' day line does not contain everyday: '+ line)
def check_weekday(self,line,show_ref,section):
words=line.split()
if words[0]!='day':
self.display('f','Schedule - In section '+ section + ' day line does not contain day: ' + line)
days=words[1:]
for day in days:
if day not in TimeOfDay.DAYS_OF_WEEK:
self.display('f','Schedule - In section '+ section + ' day line has invalid day: '+ line)
def check_monthday(self,line,show_ref,section):
words=line.split()
if words[0]!='day':
self.display('f','Schedule - In section '+ section + ' day line does not contain day: ' + line)
days=words[1:]
for day in days:
if not day.isdigit():
self.display('f','Schedule - In section '+ section + ' day line has invalid day: '+ line)
return
if int(day) <1 or int(day)>31:
self.display('f','Schedule - In section '+ section + ' day line has out of range day: '+ line)
return
def check_specialday(self,line,show_ref,section):
words=line.split()
if words[0]!='day':
self.display('f','Schedule - In section '+ section + ' day line does not contain day: ' + line)
days=words[1:]
for day in days:
self.check_date(day,show_ref,section)
def check_time_lines(self,lines,show_ref,show_type,v_show_labels,section):
# lines - list of lines each with text 'command time'
# returns list of lists each being [command, time]
time_lines=[]
for line in lines:
# split line into time,command
words=line.split()
if len(words)<2:
self.display('f','Schedule - In section '+ section + ' time line has wrong length: '+ line)
return
self.check_time(words[0],show_ref,section)
if show_type=='start':
command = ' '.join(words[1:])
self.check_show_control_fields(command,v_show_labels)
else:
if words[1] not in ('open','close'):
self.display('f','Schedule - In section '+ section+ ' illegal command: '+ line)
return
def check_time(self,item,show_ref,section):
fields=item.split(':')
if len(fields) == 0:
self.display('f','Schedule - In section ' + section + ' time field is empty: '+ item)
return
if len(fields)>3:
self.display('f','Schedule - In section ' + section + ' time line has too many fields: ' + item)
return
if len(fields) == 1:
seconds=fields[0]
minutes='0'
hours='0'
if len(fields) == 2:
seconds=fields[1]
minutes=fields[0]
hours='0'
if len(fields) == 3:
seconds=fields[2]
minutes=fields[1]
hours=fields[0]
if not seconds.isdigit() or not minutes.isdigit() or not hours.isdigit():
self.display('f','Schedule - In section ' + section + ' time field is invalid: ' + item)
return
if int(minutes)>59:
self.display('f','Schedule - In section ' + section + ' Minutes of '+ item + ' is out of range')
if int(seconds)>59:
self.display('f','Schedule - In section ' + section + ' Seconds of '+ item + ' is out of range')
if int(hours)>23:
self.display('f','Schedule - In section ' + section + ' Hours of '+ item + ' is out of range')
return
def check_date(self,item,show_ref,section):
fields=item.split('-')
if len(fields) == 0:
self.display('f','Schedule - In section ' + section + ' Date field is empty: '+item)
return
if len(fields)!=3:
self.display('f','Schedule - In section ' + section + ' Too many or few fields in date: ' + item)
return
year=fields[0]
month=fields[1]
day = fields[2]
if not year.isdigit() or not month.isdigit() or not day.isdigit():
self.display('f','Schedule - In section ' + section + ' Fields of '+ item + ' are not positive integers ' )
return
if int(year)<2018:
self.display('f','Schedule - In section ' + section + ' Year of '+ item + ' is out of range ')
if int(month)>12:
self.display('f','Schedule - In section ' + section + ' Month of '+ item + ' is out of range ')
if int(day)>31:
self.display('f','Schedule - In section ' + section + ' Day of '+ item + ' is out of range ')
def check_duration(self,field,line):
fields=line.split(':')
if len(fields) == 0:
self.display('f','End Trigger, ' + field +' Field is empty: ' + line)
return
if len(fields)>3:
self.display('f','End Trigger, ' + field + ' More then 3 fields: ' + line)
return
if len(fields) == 1:
secs=fields[0]
minutes='0'
hours='0'
if len(fields) == 2:
secs=fields[1]
minutes=fields[0]
hours='0'
if len(fields) == 3:
secs=fields[2]
minutes=fields[1]
hours=fields[0]
if not hours.isdigit() or not minutes.isdigit() or not secs.isdigit():
self.display('f','End Trigger, ' + field + ' Fields are not positive integers: ' + line)
return
if int(hours)>23 or int(minutes)>59 or int(secs)>59:
self.display('f','End Trigger, ' + field + ' Fields are out of range: ' + line)
return
# *******************
# MENU
# ***********************
def check_menu(self,track):
if not track['menu-rows'].isdigit(): self.display('f'," Menu Rows is not 0 or a positive integer")
if not track['menu-columns'].isdigit(): self.display('f'," Menu Columns is not 0 or a positive integer")
if not track['menu-icon-width'].isdigit(): self.display('f'," Icon Width is not 0 or a positive integer")
if not track['menu-icon-height'].isdigit(): self.display('f'," Icon Height is not 0 or a positive integer")
if not track['menu-horizontal-padding'].isdigit(): self.display('f'," Horizontal Padding is not 0 or a positive integer")
if not track['menu-vertical-padding'].isdigit(): self.display('f'," Vertical padding is not 0 or a positive integer")
if not track['menu-text-width'].isdigit(): self.display('f'," Text Width is not 0 or a positive integer")
if not track['menu-text-height'].isdigit(): self.display('f'," Text Height is not 0 or a positive integer")
if not track['menu-horizontal-separation'].isdigit(): self.display('f'," Horizontal Separation is not 0 or a positive integer")
if not track['menu-vertical-separation'].isdigit(): self.display('f'," Vertical Separation is not 0 or a positive integer")
if not track['menu-strip-padding'].isdigit(): self.display('f'," Stipple padding is not 0 or a positive integer")
if not track['hint-x']!='' and not track['hint-x'].isdigit(): self.display('f',"'Hint x Position' is not a positive integer")
if not track['hint-y']!='' and not track['hint-y'].isdigit(): self.display('f',"'Hint y Position' is not a positive integer")
if track['track-text-x'] != "" and not track['track-text-x'].isdigit(): self.display('f'," Menu Text x Position is not a positive integer")
if track['track-text-y'] != "" and not track['track-text-y'].isdigit(): self.display('f'," Menu Text y Position is not a positive integer")
if track['menu-icon-mode'] == 'none' and track['menu-text-mode'] == 'none':
self.display('f'," Icon and Text are both None")
if track['menu-icon-mode'] == 'none' and track['menu-text-mode'] == 'overlay':
self.display('f'," cannot overlay none icon")
self.check_menu_window(track['menu-window'])
def check_menu_window(self,line):
if line == '':
self.display('f'," menu Window: may not be blank")
return
if line != '':
fields = line.split()
if len(fields) not in (1, 2,4):
self.display('f'," menu Window: wrong number of fields")
return
if len(fields) == 1:
if fields[0] != 'fullscreen':
self.display('f'," menu Window: single argument must be fullscreen")
return
if len(fields) == 2:
if not (fields[0].isdigit() and fields[1].isdigit()):
self.display('f'," menu Window: coordinates must be positive integers")
return
if len(fields) == 4:
if not(fields[0].isdigit() and fields[1].isdigit() and fields[2].isdigit() and fields[3].isdigit()):
self.display('f'," menu Window: coordinates must be positive integers")
return
# *******************
# TRACK PLUGIN
# *******************
def check_plugin(self,plugin_cfg,pp_home,pp_profile):
if plugin_cfg.strip() != '' and plugin_cfg[0] == "+":
plugin_cfg=pp_home+plugin_cfg[1:]
if not os.path.exists(plugin_cfg):
self.display('f','track plugin configuration file not found: '+ plugin_cfg)
if plugin_cfg.strip() != '' and plugin_cfg[0] == "@":
plugin_cfg=pp_profile+plugin_cfg[1:]
if not os.path.exists(plugin_cfg):
self.display('f','plugin configuration file not found: '+ plugin_cfg)
# *******************
# BROWSER COMMANDS
# *******************
def check_browser_commands(self,command_text,b_type):
lines = command_text.split('\n')
for line in lines:
if line.strip() == "":
continue
self.check_chrome_command(line)
def check_chrome_command(self,line):
fields = line.split()
if len(fields) not in (1,2):
self.display('f','incorrect number of fields in browser command: '+ line)
return
command = fields[0]
if command not in ('load','refresh','wait','loop'):
self.display('f','unknown command in browser commands: '+ line)
return
if command in ('refresh',) and len(fields) != 1:
self.display('f','incorrect number of fields for '+ command + ' in: '+ line)
return
if command =='loop' and len(fields)==1:
return
if command == 'load':
if len(fields) != 2:
self.display('f','incorrect number of fields for '+ command + ' in: '+ line)
return
if command in ('wait','loop'):
if len(fields) != 2:
self.display('f','incorrect number of fields for '+ command + ' in: '+ line)
return
arg = fields[1]
if not arg.isdigit():
self.display('f','Argument for "wait" or "loop" is not 0 or positive number in: '+ line)
return
# *******************
# CONTROLS
# *******************
def check_controls(self,name,controls_text):
lines = controls_text.split('\n')
for line in lines:
if line.strip() == "":
continue
self.check_control(line)
def check_control(self,line):
fields = line.split()
if len(fields) != 2 :
self.display('f',"incorrect number of fields in Control: " + line)
return