guru.py 4.12 KB
Newer Older
1
2
#!/usr/bin/python3

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
3
# python libs
4
import time
5
import sys
6
7
8

from argparse import ArgumentParser

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
9
# own libs
10
from libraries.base.config import ConfigReader
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
11
12
from modules.tools.padavan import Padavan

13
14
15
16
17
18
19
20
21
class Guru:
    config = ConfigReader()
    config.loadConfig()

    def __init__(self):
        try:
            parser = ArgumentParser()

            # commands
22
            parser.add_argument("-fnp", "--fetch-new-programmes", action="store_true", dest="fetch_new_programme",
23
                                default=False, help="Fetch new programmes from calendarurl in comba.ini")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
24
            parser.add_argument("-ip", "--init-player", action="store_true", dest="init_player", default=False,
25
                                help="Checks what is the active source and stops everything else")
26

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
27
28
29
30
            # options
            parser.add_argument("-sep", "--stop-execution-time", action="store_true", dest="stoptime", default=False,
                                help="Prints the execution time at the end of the skript")

31
            # getter
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
32
            parser.add_argument("-gam", "--get-active-mixer", action="store_true", dest="get_active_mixer", default=False,
33
                                help="Which mixer is activated?")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
34
            parser.add_argument("-pms", "--print-mixer-status", action="store_true", dest="print_mixer_status", default=False,
35
                                help="Prints all mixer sources and their states")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
36
            parser.add_argument("-pap", "--print-act-programme", action="store_true", dest="print_act_prog", default=False,
37
                                help="Prints the actual Programme, the controller holds")
38
39

            # manipulation
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
40
            parser.add_argument("-am", "--select-mixer", action="store", dest="select_mixer", default=-1, metavar="MIXERNUM",
41
42
                                help="Which mixer should be activated?", type=int)

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
43
            parser.add_argument("-dm", "--de-select-mixer", action="store", dest="deselect_mixer", default=-1, metavar="MIXERNUM",
44
45
                                help="Which mixer should be activated?", type=int)

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
46
            parser.add_argument("-vm", "--volume", action="store", dest="set_volume", default=0, metavar=("MIXERNUM","VOLUME"), nargs=2,
47
48
                                help="Set volume of a mixer source", type=int)

49
            parser.add_argument("-as", "--add-source", action="store", dest="add_source", default=False,
50
51
                                help="Add new source to LiquidSoap mixer [Experimental]")

52
53
54
55
            # redis comm. test
            parser.add_argument("-rm", "--redis-message", action="store", dest="redis_message", default=False, metavar=("CHANNEL", "MESSAGE"), nargs=2,
                                help="Send a redis message to the Listeners")

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
56
57
            # calls from liquidsoap
            parser.add_argument("-gnft", "--get-next-for-fallback-file", action="store", dest="type", default=False,
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
58
                                help="For which type you wanna have a next audio file?")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
59
            parser.add_argument("-snft", "--select-next-for-fallback-file", action="store", dest="type", default=False,
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
60
                                help="For which type you wanna select a next audio file?")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
61
62
63
            parser.add_argument("-ls", "--liquid-startup", action="store_true", dest="liquid_startup", default=False,
                                help="Reset liquidsoap volume and mixer activations?")

64
65
            args = parser.parse_args()

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
66
67
68
            if len(sys.argv) == 1:
                raise ValueError("No Argument passed!")

69
70
71
        except ValueError:
            parser.print_help()
            exit(1)
72
73
74
        except TypeError:
            parser.print_help()
            exit(2)
75

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
76
77
78
        if args.stoptime:
            start = time.time()

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
79
80
        p = Padavan(args, self.config)
        p.meditate()
81

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
82
83
84
85
86
87
        if args.stoptime:
            end = time.time()
            exectime = end-start

            print("execution time: "+str(exectime)+"s")

88
89
90
91
92

# # ## ## ## ## ## # #
# # ENTRY FUNCTION # #
# # ## ## ## ## ## # #
def main():
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
93
    Guru()
94
95
96
97
# # ## ## ## ## ## ## # #
# # End ENTRY FUNCTION # #
# # ## ## ## ## ## ## # #

98

99
100
if __name__ == "__main__":
    main()