dringctrl.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2015-2017 Savoir-faire Linux Inc.
  4. # Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import sys
  20. import os
  21. import random
  22. import time
  23. import argparse
  24. import signal
  25. try:
  26. from gi.repository import GObject
  27. except ImportError as e:
  28. import gobject as GObject
  29. except Exception as e:
  30. print(str(e))
  31. exit(1)
  32. from errors import *
  33. from controler import DRingCtrl
  34. from tester import DRingTester
  35. if __name__ == "__main__":
  36. parser = argparse.ArgumentParser()
  37. parser.add_argument('--get-all-accounts', help='Get all accounts (of optionaly given type)',
  38. nargs='?', metavar='<type>', type=str, default=argparse.SUPPRESS)
  39. parser.add_argument('--get-registered-accounts', help='Get all registered accounts',
  40. action='store_true')
  41. parser.add_argument('--get-enabled-accounts', help='Get all enabled accounts',
  42. action='store_true')
  43. parser.add_argument('--get-all-accounts-details', help='Get all accounts details',
  44. action='store_true')
  45. parser.add_argument('--add-ring-account', help='Add new Ring account',
  46. metavar='<account>', type=str)
  47. parser.add_argument('--remove-ring-account', help='Remove Ring account',
  48. metavar='<account>', type=str)
  49. parser.add_argument('--get-account-details', help='Get account details',
  50. metavar='<account>', type=str)
  51. group = parser.add_mutually_exclusive_group()
  52. group.add_argument('--enable', help='Enable the account',
  53. metavar='<account>', type=str)
  54. group.add_argument('--disable', help='Disable the account',
  55. metavar='<account>', type=str)
  56. group = parser.add_mutually_exclusive_group()
  57. group.add_argument('--register', help='Register the account',
  58. metavar='<account>', type=str)
  59. group.add_argument('--unregister', help='Unregister the account',
  60. metavar='<account>', type=str)
  61. parser.add_argument('--set-active-account', help='Set active account',
  62. metavar='<account>', type=str)
  63. parser.add_argument('--get-all-codecs', help='Get all codecs', action='store_true')
  64. parser.add_argument('--get-active-codecs', help='Get active codecs for the account',
  65. nargs='?', metavar='<account>', type=str, default=argparse.SUPPRESS)
  66. parser.add_argument('--get-active-codecs-details', help='Get active codecs details for the account',
  67. metavar='<account>',type=str)
  68. parser.add_argument('--set-active-codecs', help='Set active codecs for active account',
  69. metavar='<codec list>', type=str)
  70. parser.add_argument('--get-call-list', help='Get call list', action='store_true')
  71. group = parser.add_mutually_exclusive_group()
  72. group.add_argument('--call', help='Call to number', metavar='<destination>')
  73. #group.add_argument('--transfer', help='Transfer active call', metavar='<destination>')
  74. group = parser.add_mutually_exclusive_group()
  75. group.add_argument('--accept', help='Accept the call', metavar='<call>')
  76. group.add_argument('--hangup', help='Hangup the call', metavar='<call>')
  77. group.add_argument('--refuse', help='Refuse the call', metavar='<call>')
  78. group = parser.add_mutually_exclusive_group()
  79. group.add_argument('--hold', help='Hold the call', metavar='<call>')
  80. group.add_argument('--unhold', help='Unhold the call', metavar='<call>')
  81. parser.add_argument('--dtmf', help='Send DTMF', metavar='<key>')
  82. parser.add_argument('--toggle-video', help='Launch toggle video tests', action='store_true')
  83. parser.add_argument('--test', help=' '.join(str(test) for test in DRingTester().getTestName() ), metavar='<testName>')
  84. parser.add_argument('--auto-answer', help='Keep running and auto-answer the calls', action='store_true')
  85. args = parser.parse_args()
  86. ctrl = DRingCtrl(sys.argv[0], args.auto_answer)
  87. if args.add_ring_account:
  88. accDetails = {'Account.type':'RING', 'Account.alias':args.add_ring_account if args.add_ring_account!='' else 'RingAccount'}
  89. accountID = ctrl.addAccount(accDetails)
  90. if args.remove_ring_account and args.remove_ring_account != '':
  91. ctrl.removeAccount(args.remove_ring_account)
  92. if args.get_all_codecs:
  93. print(ctrl.getAllCodecs())
  94. if hasattr(args, 'get_all_accounts'):
  95. for account in ctrl.getAllAccounts(args.get_all_accounts):
  96. print(account)
  97. if args.get_registered_accounts:
  98. for account in ctrl.getAllRegisteredAccounts():
  99. print(account)
  100. if args.get_enabled_accounts:
  101. for account in ctrl.getAllEnabledAccounts():
  102. print(account)
  103. if args.get_all_accounts_details:
  104. for account in ctrl.getAllAccounts():
  105. ctrl.printAccountDetails(account)
  106. if args.get_active_codecs_details:
  107. for codecId in ctrl.getActiveCodecs(args.get_active_codecs_details):
  108. print("# codec",codecId,"-------------")
  109. print(ctrl.getCodecDetails(args.get_active_codecs_details, codecId))
  110. print("#-- ")
  111. if args.set_active_account:
  112. ctrl.setAccount(args.set_active_account)
  113. if args.get_account_details:
  114. ctrl.printAccountDetails(args.get_account_details)
  115. if hasattr(args, 'get_active_codecs'):
  116. print(ctrl.getActiveCodecs(args.get_active_codec))
  117. if args.set_active_codecs:
  118. ctrl.setActiveCodecList(codec_list=args.set_active_codecs)
  119. if args.enable:
  120. ctrl.setAccountEnable(args.enable, True)
  121. if args.disable:
  122. ctrl.setAccountEnable(args.enable, False)
  123. if args.register:
  124. ctrl.setAccountRegistered(args.register, True)
  125. if args.unregister:
  126. ctrl.setAccountRegistered(args.unregister, False)
  127. if args.get_call_list:
  128. for call in ctrl.getAllCalls():
  129. print(call)
  130. if args.call:
  131. ctrl.Call(args.call)
  132. if args.accept:
  133. ctrl.Accept(args.accept)
  134. if args.refuse:
  135. ctrl.Refuse(args.refuse)
  136. if args.hangup:
  137. ctrl.HangUp(args.hangup)
  138. if args.hold:
  139. ctrl.Hold(args.hold)
  140. if args.unhold:
  141. ctrl.UnHold(args.unhold)
  142. if args.dtmf:
  143. ctrl.Dtmf(args.dtmf)
  144. if args.test:
  145. DRingTester().start(ctrl, args.test)
  146. if args.toggle_video:
  147. if not ctrl.videomanager:
  148. print("Error: daemon without video support")
  149. sys.exit(1)
  150. import time
  151. while True:
  152. time.sleep(2)
  153. ctrl.videomanager.startCamera()
  154. time.sleep(2)
  155. ctrl.videomanager.stopCamera()
  156. if len(sys.argv) == 1 or ctrl.autoAnswer:
  157. signal.signal(signal.SIGINT, ctrl.interruptHandler)
  158. ctrl.run()
  159. sys.exit(0)