-
Notifications
You must be signed in to change notification settings - Fork 0
/
hu_src_ctrl.py
executable file
·1316 lines (1082 loc) · 31.9 KB
/
hu_src_ctrl.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
#!/usr/bin/python
# MUSIC SOURCE CONTROLLER is used as part of a music playing platform.
# Similar to the source knob on a HiFi receiver or car headunit, this
# script can cycle through its connected sources.
#
# The Source Controller can be used to control playback of the source.
#
# Venema, S.R.G.
# 2018-03-23
# License: MIT
#
# Loads source plugins from /sources folder
#
# Switches:
# -r, --resume Resume source
# -p, --play Start playback (ignore resume)
#
## IGNORING QUEUING FOR NOW ! ##
import sys
import json # load json source configuration
from Queue import Queue # queuing
import inspect # dynamic module loading
import gobject # main loop
from dbus.mainloop.glib import DBusGMainLoop
#********************************************************************************
# Logging
from logging import getLogger
#********************************************************************************
# Headunit modules
from modules.hu_source import SourceController
from modules.hu_msg import MqPubSubFwdController
from modules.hu_msg import parse_message
from modules.hu_utils import * #init_load_config
#********************************************************************************
# Third party and others...
from slugify import slugify
#********************************************************************************
# Version
#
from version import __version__
# *******************************************************************************
# Global variables and constants
#
DESCRIPTION = "Source Controller"
LOG_TAG = 'SRCTRL'
LOGGER_NAME = 'srctrl'
DEFAULT_CONFIG_FILE = '/etc/configuration.json'
#SETTINGS = '/etc/hu/source.json'
SETTINGS = '/mnt/PIHU_CONFIG/source.json'
DEFAULT_LOG_LEVEL = LL_INFO
DEFAULT_PORT_PUB = 5559
DEFAULT_PORT_SUB = 5560
SUBSCRIPTIONS = ['/source/','/player/','/events/udisks/']
logger = None # logging
args = None # command line arguments
messaging = None # mq messaging
configuration = None # configuration
settings = None # operational settings
sc_sources = None # source controller
# ********************************************************************************
# Output wrapper
#
def printer( message, level=LL_INFO, continuation=False, tag=LOG_TAG ):
logger.log(level, message, extra={'tag': tag})
# NOT USED AT THE MOMENT...
def process_queue():
if not queue_actions.empty():
item = queue_actions.get()
# do smart stuff #TODO
# - future actions that eliminate all priors: source_next, ...
globals()[item[0]](item[1], item[2], item[3])
queue_actions.task_done()
return True
def validate_args(args, min_args, max_args):
if len(args) < min_args:
printer('Function arguments missing', level=LL_ERROR)
return False
if len(args) > max_args:
printer('More than {0} argument(s) given, ignoring extra arguments'.format(max_args), level=LL_WARNING)
#args = args[:max_args]
return True
def get_data(ret,returndata=False,eventpath=None):
print "DEBUG: ret = {0}".format(ret)
data = {}
if ret is None:
data['retval'] = 500
data['payload'] = None
elif ret is False:
data['retval'] = 500
data['payload'] = None
elif ret is True:
data['retval'] = 200
data['payload'] = None
else:
data['retval'] = 200
data['payload'] = ret
if eventpath is not None:
#TODO: AVAILABLE EVENTS FOR EVERY AVAILABLE SOURCE ON CHECK() !!! !!! !!!
if eventpath == '/events/source/active': # or eventpath == '/events/source/available':
curr_source = sc_sources.source()
data['payload'] = curr_source
messaging.publish(eventpath,'DATA',data)
# settings['source'] = curr_source['name']
# save_settings()
save_resume()
#if eventpath == '/events/source/available':
# now_available, now_unavailable = sc_sources.che
# data['payload'] = None
if not returndata:
data['payload'] = None
return data
def handle_path_source(path,cmd,args,data):
base_path = 'source'
# remove base path
del path[0]
# -------------------------------------------------------------------------
# Sub Functions must return None (invalid params) or a {data} object.
def get_primary(args):
""" Retrieve Primary Sources
Arguments:
None Retrieve list of all sources
Return data:
List of Sources
Arguments:
<source_id> Retrieve specified source
Return data:
Specified source
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,1)
if not valid:
return None
if not args:
ret = sc_sources.source_all()
elif len(args) == 1:
ret = sc_sources.source(args[0])
data = get_data(ret,True)
return data
def put_primary(args):
""" Set active (sub)source to <id> (<subid>). If "P" then also start playing.
? Starts playback if P is specified, or not (default)
? Does not start playback if S specified
Arguments:
<int:source_id>,[int:subsource_id][,S|P]
Return data:
Nothing
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,3)
if not valid:
return None
elif len(args) == 1:
ret = sc_sources.select(args[0])
elif len(args) == 2:
ret = sc_sources.select(args[0],args[1])
elif len(args) == 3:
ret = sc_sources.select(args[0],args[1])
#TODO: not implemented
data = get_data(ret,False,'/events/source/active')
return data
def post_primary(args):
""" Add a new source
Arguments:
{source}
Return data:
Nothing
Return codes:
200 OK
500 Error
"""
#TODO
return None
ret = sc_sources.add(args[0])
data = get_data(ret)
return data
def del_primary(args):
""" Remove a source
Arguments:
None: Remove current source
source_id Remove specified source
Return data:
Nothing
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,1)
if not valid:
return None
if not args:
ret = sc_sources.rem()
elif len(args) == 1:
ret = sc_sources.rem(args[0])
# LL_DEBUG:
printSummary()
data = get_data(ret)
return data
def get_subsource(args):
"""
Arguments:
None Return list of sub-sources for current index
source_id Return list of sub-sources for specified index
source_id, subsource_id Return specified subsource
Return data:
List of sub-sources
Sub-source
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,2)
if not valid:
return None
ret = None
if not args:
ret = sc_sources.subsource_all()
elif len(args) == 1:
if type(args[0]) == int:
ret = sc_sources.subsource_all(args[0])
#else:
# invalid arg...
# todo
elif len(args) == 2:
ret = sc_sources.subsource(args[0],args[1])
data = get_data(ret,True)
return data
def put_subsource(args):
"""Set active subsource to <subid>. If "P" then also start playing.
? Starts playback if P is specified, or not (default)
? Does not start playback if S specified
Arguments:
<int:source_id>,<int:subsource_id>[,S|P]
Return data:
Nothing
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,1,3)
if not valid:
return None
if len(args) == 2:
ret = sc_sources.select(args[0],args[1])
elif len(args) == 3:
ret = sc_sources.select(args[0],args[1])
#TODO: not implemented
data = get_data(ret,False,'/events/source/active')
return data
def post_subsource(args):
#TODO
return None
def del_subsource(args):
""" Remove a subsource
Arguments:
None: Remove current subsource
<source_id>, <subsource_id> Remove specified subsource
Return data:
Nothing
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,2)
if not valid:
return None
if not args:
ret = sc_sources.rem_sub()
elif len(args) == 1:
printer('This function requires an index and subindex', level=LL_ERROR)
return None
elif len(args) == 2:
ret = sc_sources.rem_sub(args[0],args[1])
# LL_DEBUG:
printSummary()
data = get_data(ret)
return data
def put_available(args):
""" Mark (sub)source as (un)available
Arguments:
True|False, source_id Mark Source ID
True|False, source_id, sub-source_id Mark Sub-Source ID
Return data:
None
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,2,3)
if not valid:
return None
if len(args) == 2:
ret = sc_sources.set_available(args[1],str2bool(args[0]))
elif len(args) == 3:
ret = sc_sources.set_available(args[1],str2bool(args[0]),args[2])
# LL_DEBUG
printSummary()
data = get_data(ret,False,'/events/source/available')
return data
def put_next(args):
""" Change to next available (sub)source and start playing
Arguments:
None
Return data:
None
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,0)
if not valid:
print "INVALID ARGS"
return None
ret = sc_sources.select_next()
# returns None if cannot change source
if ret is not None:
# LL_DEBUG
printSummary()
data = get_data(ret,False,'/events/source/active')
print data
# TODO, Should we return a 4xx or 5xx maybe?
#return data
def put_prev(args):
""" Change to prev available (sub)source and start playing
Arguments:
None
Return data:
None
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,0)
if not valid:
return None
ret = sc_sources.select_prev()
# LL_DEBUG
printSummary()
data = get_data(ret,False,'/events/source/active')
return data
def put_check(args):
""" Do an availability check on given or current source
Arguments:
None Check current source
source_id Check source
source_id, sub-source_id Check sub-source
Return data:
None
Return codes:
200 OK
500 Error
"""
valid = validate_args(args,0,2)
if not valid:
return None
if not args:
ret = sc_sources.check()
elif len(args) == 1:
ret = sc_sources.check(args[0])
elif len(args) == 2:
ret = sc_sources.check(args[0],args[1])
if ret != False:
printSummary() # LL_DEBUG
# TODO: MOVE "check_all" LOOP HERE SO WE CAN SEND OUT EVENTS EARLIER !
# TODO-INSTEAD: local def function check_all()
for change in ret:
print "CHANGED: {0}".format(change)
#available_source = {}
#available_source['index'] = change['index']
#available_source['subindex'] = change['subindex']
#available_source['available'] = change['available']
#messaging.publish('/events/source/available','DATA',available_source)
messaging.publish('/events/source/available','DATA',change)
"""
for indexes in ret:
print "FOR INDEX IN RET: index={0}".format(indexes) # [1,0], [1]
index = indexes[0]
if len(indexes) > 1:
for subindex in indexes[1:]:
print "FOR SUBINDEX IN {0}".format(indexes[1:])
subsource = sc_sources.subsource(index,subindex)
available_source = {}
available_source['index'] = index
available_source['subindex'] = subindex
available_source['available'] = subsource['available']
messaging.publish('/events/source/available','DATA',available_source)
else:
source = sc_sources.source(index)
available_source = {}
available_source['index'] = index
available_source['available'] = source['available']
messaging.publish('/events/source/available','DATA',available_source)
"""
data = get_data(ret)
return data
# -------------------------------------------------------------------------
if path:
function_to_call = cmd + '_' + '_'.join(path)
else:
# called without sub-paths
function_to_call = cmd + '_' + base_path
ret = None
if function_to_call in locals():
ret = locals()[function_to_call](args)
printer('Executed {0} function {1} with result status: {2}'.format(base_path,function_to_call,ret)) # TODO: LL_DEBUG
else:
printer('Function {0} does not exist'.format(function_to_call))
return ret
def handle_path_player(path,cmd,args,data):
base_path = 'player'
# remove base path
del path[0]
def get_track(args):
""" Retrieve Track details
Arguments: None
Return data: Track Details
"""
valid = validate_args(args,0,0)
if not valid:
return None
if not args:
ret = sc_sources.source_get_details()
# only keep the track section
if ret is not None and 'track' in ret:
ret = ret['track']
data = get_data(ret,True)
return data
def put_track(args):
""" Play track at specified playlist position
Arguments: Playlist position
Return data: Nothing
"""
valid = validate_args(args,1,1)
if not valid:
return None
if len(args) == 1:
ret = sc_sources.source_play(position=args[0])
data = get_data(ret,True)
return data
'''
TODO
def get_folders(args):
""" Retrieve list of playlist-folder mappings
Arguments: None
Return data: playlist-folder mapping
"""
valid = validate_args(args,0,0)
if not valid:
return None
if not args:
ret = sc_sources.()
data = get_data(ret,True)
return data
'''
def put_pause(args):
""" Enable/Disable Pause
Arguments: on|off|toggle
Return data: Nothing
"""
valid = validate_args(args,1,1)
if not valid:
return None
if len(args) == 1:
ret = sc_sources.source_pause(args[0])
# Set pause: on|off|toggle
data = get_data(ret,True)
return data
def get_state(args):
""" Get play state
Arguments: None
Return data: State
"""
valid = validate_args(args,0,0)
if not valid:
return None
if not args:
ret = sc_sources.source_get_state()
# Get state: play|pause|stop, toggle random
data = get_data(ret,True)
return data
def put_state(args):
""" Set play state
Arguments: {state}
Return data: Nothing
"""
valid = validate_args(args,1,1)
if not valid:
return None
state = json.loads(args[0])
# PARSE STATE -- IS THIS THE RIGHT PLACE TO DO THIS?
if not isinstance(state,dict):
#return False #?
printer ("argument is not a dictionary")
return None
if 'state' in state:
if state['state'] in ('play','playing'):
ret = sc_sources.source_play()
elif state['state'] in ('stop'):
ret = sc_sources.source_stop()
elif state['state'] in ('pause','paused'):
ret = sc_sources.source_pause()
else:
print "UNKNOWN state: {0}".format(state['state'])
return None #?
# Set state: play|pause|stop, toggle random
data = get_data(ret,True)
return data
def put_random(args):
""" Set random mode
Arguments: on|off|toggle|mode
Return data: Nothing
"""
valid = validate_args(args,1,1)
if not valid:
return None
# Set random on|off|toggle|special modes
if len(args) == 1:
ret = sc_sources.source_random(args[0])
data = get_data(ret,True)
return data
'''
TODO
def get_randommode(args):
""" Get list of supported random modes
Arguments: None
Return data: {randommodes}
"""
valid = validate_args(args,0,0)
if not valid:
return None
if not args:
ret = sc_sources.()
# Get list of (supported) random modes
data = get_data(ret,True)
return data
'''
def put_next(args):
""" Next track
Arguments:
None Advance by 1
<int> Advance by <int>
Return data: Nothing
"""
valid = validate_args(args,0,1)
if not valid:
return None
if not args:
print "PUT NEXT NO ARGS"
ret = sc_sources.source_next()
elif len(args) == 1:
print "PUT NEXT 1 ARG"
ret = sc_sources.source_next(adv=args[0])
data = get_data(ret,True)
return data
def put_prev(args):
""" Prev track
Arguments:
None Go back 1
<int> Go back <int>
Return data: Nothing
"""
valid = validate_args(args,0,1)
if not valid:
return None
if not args:
ret = sc_sources.source_prev()
elif len(args) == 1:
ret = sc_sources.source_prev(args[0])
data = get_data(ret,True)
return data
"""
def put_nextfolder(args):
return True
def put_prevfolder(args):
return True
"""
def put_seekfwd(args):
""" Seek FWD
Arguments:
None Seek Fwd by ? seconds
<int> Seek Fwd by <int> seconds
Return data: Nothing
"""
valid = validate_args(args,0,1)
if not args:
ret = sc_sources.seekfwd()
elif len(args) == 1:
ret = sc_sources.seekfwd(args[0])
data = get_data(ret,True)
return data
def put_seekrev(args):
""" Seek REV
Arguments:
None Seek back by ? seconds
<int> Seek back by <int> seconds
Return data: Nothing
"""
valid = validate_args(args,0,1)
if not args:
ret = sc_sources.seekrev()
elif len(args) == 1:
ret = sc_sources.seekrev(args[0])
data = get_data(ret,True)
return data
"""
def get_playlist(args):
# Retrieve current or specified playlist
playlist = sc_sources.source_get_playlist()
print playlist
# TODO: ehmm, do something with the state
return True
"""
'''
TODO
def put_update_location(args):
""" Update MPD, preferably set a location
Arguments:
None Update entire database
<location> Update <location>
Return data: Nothing
"""
valid = validate_args(args,0,1)
if not args:
ret = sc_sources.()
elif len(args) == 1:
ret = sc_sources.(args[0])
# Update MPD, preferablly specify a location
ret = sc_sources.source_update()
return ret
'''
def put_update_source(args):
""" Update MPD for source
Arguments: Source index
Return data: Nothing
"""
valid = validate_args(args,1,1)
if not args:
ret = sc_sources.source_update()
elif len(args) == 1:
ret = sc_sources.source_update(args[0])
data = get_data(ret,True)
return data
if path:
function_to_call = cmd + '_' + '_'.join(path)
else:
# called without sub-paths
function_to_call = cmd + '_' + base_path
ret = None
if function_to_call in locals():
ret = locals()[function_to_call](args)
printer('Executed {0} function {1} with result status: {2}'.format(base_path,function_to_call,ret))
else:
printer('Function {0} does not exist'.format(function_to_call))
return ret
def handle_path_events(path,cmd,args,data):
base_path = 'events'
# remove base path
del path[0]
def data_source_active(data):
print "ACTIVE"
pass
def data_source_available(data):
print "AVAILABLE"
pass
def data_player_state(data):
print "STATE"
pass
def data_player_track(data):
print "TRACK"
pass
def data_player_elapsed(data):
print "ELAPSED"
pass
def data_player_updating(data):
print "UPDATING"
pass
def data_player_updated(data):
print "UPDATED"
pass
def data_volume_changed(data):
print "VOL_CHG"
pass
def data_volume_att(data):
print "ATT"
pass
def data_volume_mute(data):
print "MUTE"
pass
def data_network_up(data):
print "NET UP"
pass
def data_network_down(data):
payload = json.loads(data)
sc_sources.do_event('network',path,payload)
printSummary()
return None
def data_system_shutdown(data):
print "SHUTDOWN"
pass
def data_system_reboot(data):
print "REBOOT"
pass
def data_udisks_added(data):
""" New media added
Data object:
{
device
uuid
mountpoint
label
}
Return data:
?
Return codes:
?
"""
#valid = validate_args(args,1,3)
#if not valid:
# return None
payload = json.loads(data)
sc_sources.do_event('udisks',path,payload) # do_event() executes the 'udisks' event
printSummary()
return None
def data_udisks_removed(data):
print "REMOVED"
pass
if path:
function_to_call = cmd + '_' + '_'.join(path)
else:
# called without sub-paths
function_to_call = cmd + '_' + base_path
ret = None
if function_to_call in locals():
ret = locals()[function_to_call](data)
printer('Executed {0} function {1} with result status: {2}'.format(base_path,function_to_call,ret))
else:
printer('Function {0} does not exist'.format(function_to_call))
return ret
# ********************************************************************************
# On Idle
#
def idle_message_receiver():
#print "DEBUG: idle_msg_receiver()"
def dispatcher(path, command, arguments, data):
handler_function = 'handle_path_' + path[0]
if handler_function in globals():
ret = globals()[handler_function](path, command, arguments, data)
return ret
else:
print("No handler for: {0}".format(handler_function))
return None
rawmsg = messaging.poll(timeout=None) #None=Blocking
if rawmsg:
printer("Received message: {0}".format(rawmsg)) #TODO: debug
parsed_msg = parse_message(rawmsg)
# send message to dispatcher for handling
retval = dispatcher(parsed_msg['path'],parsed_msg['cmd'],parsed_msg['args'],parsed_msg['data'])
if parsed_msg['resp_path']:
#print "DEBUG: Resp Path present.. returing message.. data={0}".format(retval)
messaging.publish(parsed_msg['resp_path'],'DATA',retval)
return True # Important! Returning true re-enables idle routine.
# ********************************************************************************
# Save resume file
#
# todo: consider splitting this method in two
# todo: consider writing to the end of the file and reading backwards instead
#
def save_resume():
cur_comp_subsource = sc_sources.composite()
if cur_comp_subsource is False or cur_comp_subsource is None:
return cur_comp_subsource
# TODO: check if dir. present, create if not
# Save System resume source indicator
resume_file = os.path.join(configuration['directories']['resume'],configuration['files']['resume'])
printer('Saving resume file to: {0}'.format(resume_file))
with open(resume_file, 'wb') as f_resume_file:
f_resume_file.write('{0}\n'.format( cur_comp_subsource['name'] ))
# sub-source
ss_resume_file = os.path.join(configuration['directories']['resume'], cur_comp_subsource['name']+"."+cur_comp_subsource['keyvalue']+".json")
printer('Saving resume file to: {0}'.format(ss_resume_file))
state = sc_sources.source_get_state()
state = {}
state['id'] = 2
state['filename'] = 'bla.mp3'
state['time'] = 23
resume_data = {}
resume_data['id'] = state['id']
resume_data['filename'] = state['filename']
resume_data['time'] = state['time']
print resume_data
try:
json.dump( resume_data, open( ss_resume_file, "wb" ) )
except:
printer(' > ERROR saving resume file',level=LL_ERROR)
pa_sfx(LL_ERROR)
# ********************************************************************************
# Load configuration
#
def load_configuration():
# utils # todo, present with logger
configuration = configuration_load(LOGGER_NAME,args.config)
if not configuration or not 'zeromq' in configuration:
printer('Error: Configuration not loaded or missing ZeroMQ, using defaults:')
printer('Default Pub port: {0}'.format(DEFAULT_PORT_PUB))
printer('Default Sub port: {0}'.format(DEFAULT_PORT_SUB))
configuration = { "zeromq": { "port_subscriber": DEFAULT_PORT_SUB, "port_publisher":DEFAULT_PORT_PUB } }
return configuration
# ********************************************************************************
# Execute a check_availability() on all sources
#
def check_all_sources_send_event():
all_sources = sc_sources.source_all()
i=0
for source in all_sources:
check_result = sc_sources.check(i)