dringctrl.py 7.42 KB
Newer Older
1
2
#!/usr/bin/env python3
#
Sébastien Blin's avatar
Sébastien Blin committed
3
# Copyright (C) 2015-2019 Savoir-faire Linux Inc.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.

import sys
import os
import random
import time
import argparse
25
import signal
26

27
28
29
30
31
32
33
try:
    from gi.repository import GObject
except ImportError as e:
    import gobject as GObject
except Exception as e:
    print(str(e))
    exit(1)
34

Mohamed Fenjiro's avatar
Mohamed Fenjiro committed
35

Hugo Lefeuvre's avatar
Hugo Lefeuvre committed
36
from controller import DRingCtrl
Eloi Bail's avatar
Eloi Bail committed
37
from tester import DRingTester
38
39
40
41

if __name__ == "__main__":
    parser = argparse.ArgumentParser()

42
43
44
45
46
47
48
49
50
51
52
53
54
55
    parser.add_argument('--get-all-accounts', help='Get all accounts (of optionaly given type)',
                        nargs='?', metavar='<type>', type=str, default=argparse.SUPPRESS)
    parser.add_argument('--get-registered-accounts', help='Get all registered accounts',
                        action='store_true')
    parser.add_argument('--get-enabled-accounts', help='Get all enabled accounts',
                        action='store_true')
    parser.add_argument('--get-all-accounts-details', help='Get all accounts details',
                        action='store_true')

    parser.add_argument('--add-ring-account', help='Add new Ring account',
                        metavar='<account>', type=str)
    parser.add_argument('--remove-ring-account', help='Remove Ring account',
                        metavar='<account>', type=str)
    parser.add_argument('--get-account-details', help='Get account details',
56
57
58
59
60
61
62
63
64
65
66
                        metavar='<account>', type=str)
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--enable', help='Enable the account',
                       metavar='<account>', type=str)
    group.add_argument('--disable', help='Disable the account',
                       metavar='<account>', type=str)
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--register', help='Register the account',
                       metavar='<account>', type=str)
    group.add_argument('--unregister', help='Unregister the account',
                       metavar='<account>', type=str)
67
    parser.add_argument('--set-active-account', help='Set active account',
68
69
                        metavar='<account>', type=str)

70
71
    parser.add_argument('--get-all-codecs', help='Get all codecs', action='store_true')
    parser.add_argument('--get-active-codecs', help='Get active codecs for the account',
72
                        nargs='?', metavar='<account>', type=str, default=argparse.SUPPRESS)
73
    parser.add_argument('--get-active-codecs-details', help='Get active codecs details for the account',
74
                        metavar='<account>',type=str)
75
76
    parser.add_argument('--set-active-codecs', help='Set active codecs for active account',
                        metavar='<codec list>', type=str)
77

78
    parser.add_argument('--get-call-list', help='Get call list', action='store_true')
79
80
81
82
83
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--call', help='Call to number', metavar='<destination>')
    #group.add_argument('--transfer', help='Transfer active call', metavar='<destination>')

    group = parser.add_mutually_exclusive_group()
Alexandre Lision's avatar
Alexandre Lision committed
84
85
86
    group.add_argument('--accept', help='Accept the call', metavar='<call>')
    group.add_argument('--hangup', help='Hangup the call', metavar='<call>')
    group.add_argument('--refuse', help='Refuse the call', metavar='<call>')
87
88
89
90
91
92

    group = parser.add_mutually_exclusive_group()
    group.add_argument('--hold', help='Hold the call', metavar='<call>')
    group.add_argument('--unhold', help='Unhold the call', metavar='<call>')

    parser.add_argument('--dtmf', help='Send DTMF', metavar='<key>')
Alexandre Lision's avatar
Alexandre Lision committed
93
    parser.add_argument('--toggle-video', help='Launch toggle video  tests', action='store_true')
Eloi Bail's avatar
Eloi Bail committed
94

95
    parser.add_argument('--test', help=' '.join(str(test) for test in DRingTester().getTestName() ), metavar='<testName>')
96
    parser.add_argument('--auto-answer', help='Keep running and auto-answer the calls', action='store_true')
97
98
99

    args = parser.parse_args()

100
    ctrl = DRingCtrl(sys.argv[0], args.auto_answer)
101

Alexandre Lision's avatar
Alexandre Lision committed
102
103
    if args.add_ring_account:
        accDetails = {'Account.type':'RING', 'Account.alias':args.add_ring_account if args.add_ring_account!='' else 'RingAccount'}
104
105
        accountID = ctrl.addAccount(accDetails)

Alexandre Lision's avatar
Alexandre Lision committed
106
107
    if args.remove_ring_account and args.remove_ring_account != '':
        ctrl.removeAccount(args.remove_ring_account)
108

Alexandre Lision's avatar
Alexandre Lision committed
109
    if args.get_all_codecs:
110
111
        print(ctrl.getAllCodecs())

Alexandre Lision's avatar
Alexandre Lision committed
112
113
    if hasattr(args, 'get_all_accounts'):
        for account in ctrl.getAllAccounts(args.get_all_accounts):
114
115
            print(account)

Alexandre Lision's avatar
Alexandre Lision committed
116
    if args.get_registered_accounts:
117
118
119
        for account in ctrl.getAllRegisteredAccounts():
            print(account)

Alexandre Lision's avatar
Alexandre Lision committed
120
    if args.get_enabled_accounts:
121
122
123
        for account in ctrl.getAllEnabledAccounts():
            print(account)

Alexandre Lision's avatar
Alexandre Lision committed
124
    if args.get_all_accounts_details:
125
        for account in ctrl.getAllAccounts():
126
            ctrl.printAccountDetails(account)
127

Alexandre Lision's avatar
Alexandre Lision committed
128
129
    if args.get_active_codecs_details:
        for codecId in ctrl.getActiveCodecs(args.get_active_codecs_details):
130
            print("# codec",codecId,"-------------")
Alexandre Lision's avatar
Alexandre Lision committed
131
            print(ctrl.getCodecDetails(args.get_active_codecs_details, codecId))
132
133
            print("#-- ")

Alexandre Lision's avatar
Alexandre Lision committed
134
135
    if args.set_active_account:
        ctrl.setAccount(args.set_active_account)
136

Alexandre Lision's avatar
Alexandre Lision committed
137
    if args.get_account_details:
138
        ctrl.printAccountDetails(args.get_account_details)
139

Alexandre Lision's avatar
Alexandre Lision committed
140
141
    if hasattr(args, 'get_active_codecs'):
        print(ctrl.getActiveCodecs(args.get_active_codec))
142

Alexandre Lision's avatar
Alexandre Lision committed
143
144
    if args.set_active_codecs:
        ctrl.setActiveCodecList(codec_list=args.set_active_codecs)
145
146
147
148
149
150
151
152
153
154
155
156
157

    if args.enable:
        ctrl.setAccountEnable(args.enable, True)

    if args.disable:
        ctrl.setAccountEnable(args.enable, False)

    if args.register:
        ctrl.setAccountRegistered(args.register, True)

    if args.unregister:
        ctrl.setAccountRegistered(args.unregister, False)

Alexandre Lision's avatar
Alexandre Lision committed
158
    if args.get_call_list:
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
        for call in ctrl.getAllCalls():
            print(call)

    if args.call:
        ctrl.Call(args.call)

    if args.accept:
        ctrl.Accept(args.accept)

    if args.refuse:
        ctrl.Refuse(args.refuse)

    if args.hangup:
        ctrl.HangUp(args.hangup)

    if args.hold:
        ctrl.Hold(args.hold)

    if args.unhold:
        ctrl.UnHold(args.unhold)

    if args.dtmf:
181
        ctrl.Dtmf(args.dtmf)
182

Eloi Bail's avatar
Eloi Bail committed
183
    if args.test:
184
        DRingTester().start(ctrl, args.test)
Eloi Bail's avatar
Eloi Bail committed
185

Alexandre Lision's avatar
Alexandre Lision committed
186
    if args.toggle_video:
187
188
189
190
191
192
193
194
195
        if not ctrl.videomanager:
            print("Error: daemon without video support")
            sys.exit(1)
        import time
        while True:
            time.sleep(2)
            ctrl.videomanager.startCamera()
            time.sleep(2)
            ctrl.videomanager.stopCamera()
196
197
198
199
200
201

    if len(sys.argv) == 1 or ctrl.autoAnswer:
        signal.signal(signal.SIGINT, ctrl.interruptHandler)
        ctrl.run()
        sys.exit(0)