Commit 131301b4 authored by Patrick Keroulas's avatar Patrick Keroulas Committed by gerrit2

tools: add/remove DHT account from Python interface

When the daemon is installed on multiple targets with no interface except
the Python control utility, no Ring account should pre-exist so
the Python client should be able to create a new one on first boot.
Rename long arguments.

Tuleap: #365
Change-Id: Ie78401e35aafd8ea656f001928f0a94154352752
parent 5b894056
......@@ -117,13 +117,14 @@ class DRingCtrl(Thread):
self.registered = True
except dbus.DBusException as e:
raise DRingCtrlDeamonError("Client registration failed")
proxy_callmgr.connect_to_signal('incomingCall', self.onIncomingCall)
proxy_callmgr.connect_to_signal('callStateChanged', self.onCallStateChanged)
proxy_callmgr.connect_to_signal('conferenceCreated', self.onConferenceCreated)
proxy_confmgr.connect_to_signal('accountsChanged', self.onAccountsChanged)
except dbus.DBusException as e:
raise DRingCtrlDBusError("Unable to connect to dring DBus signals")
......@@ -226,7 +227,6 @@ class DRingCtrl(Thread):
""" On call state changed event, set the values for new calls,
or delete the call from the list of active calls
print(("On call state changed " + callid + " " + state))
if callid not in self.activeCalls:
......@@ -236,7 +236,6 @@ class DRingCtrl(Thread):
'To': callDetails['PEER_NUMBER'],
'State': state }
self.currentCallId = callid
if state == "HUNGUP":
......@@ -252,7 +251,7 @@ class DRingCtrl(Thread):
elif state == "FAILURE":
self.onCallFailure(callid, state)
print("unknown state")
print("unknown state:" + str(state))
def onConferenceCreated_cb(self):
......@@ -336,7 +335,7 @@ class DRingCtrl(Thread):
def addAccount(self, details=None):
"""Add a new account account
Add a new account to the SFLphone-daemon. Default parameters are \
Add a new account to the Ring-daemon. Default parameters are \
used for missing account configuration field.
Required parameters are type, alias, hostname, username and password
......@@ -349,7 +348,7 @@ class DRingCtrl(Thread):
username and password in \
order to create a new account")
return self.configurationmanager.addAccount(details)
return str(self.configurationmanager.addAccount(details))
def removeAccount(self, accountID=None):
"""Remove an account from internal list"""
......@@ -432,6 +431,9 @@ class DRingCtrl(Thread):
account = self._valid_account(account)
self.configurationmanager.sendRegister(account, register)
def onAccountsChanged(self):
print("Accounts changed")
# Codec manager
......@@ -38,43 +38,44 @@ def printAccountDetails(account):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--gaa', help='Get all accounts (of optionaly given type)',
nargs='?', metavar='<type>', type=str, default=argparse.SUPPRESS)
parser.add_argument('--gara', help='Get all registered accounts', action='store_true')
parser.add_argument('--gaea', help='Get all enabled accounts', action='store_true')
parser.add_argument('--gaad', help='Get all account details', action='store_true')
parser.add_argument('--gac', help='Get all codecs', action='store_true')
parser.add_argument('--gad', help='Get account details',
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',
parser.add_argument('--get-enabled-accounts', help='Get all enabled accounts',
parser.add_argument('--get-all-accounts-details', help='Get all accounts details',
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',
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)
parser.add_argument('--sac', help='Set active account',
parser.add_argument('--set-active-account', help='Set active account',
metavar='<account>', type=str)
parser.add_argument('--gacl', help='Get active codecs for the account',
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',
nargs='?', metavar='<account>', type=str, default=argparse.SUPPRESS)
parser.add_argument('--sacl', help='Set active codecs for active account',
metavar='<codec list>', type=str)
parser.add_argument('--gacd', help='Get active codecs details for the account',
parser.add_argument('--get-active-codecs-details', help='Get active codecs details for the account',
parser.add_argument('--set-active-codecs', help='Set active codecs for active account',
metavar='<codec list>', type=str)
#parser.add_argument('--gcc', help='Get current callid', action='store_true')
parser.add_argument('--gcl', help='Get call list', action='store_true')
parser.add_argument('--get-call-list', help='Get call list', action='store_true')
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>')
......@@ -101,42 +102,49 @@ if __name__ == "__main__":
if args.gac:
if args.add-ring-account:
accDetails = {'Account.type':'RING', 'Account.alias':args.add-ring-account if args.add-ring-account!='' else 'RingAccount'}
accountID = ctrl.addAccount(accDetails)
if args.remove-ring-account and args.remove-ring-account != '':
if args.get-all-codecs:
if hasattr(args, 'gaa'):
for account in ctrl.getAllAccounts(args.gaa):
if hasattr(args, 'get-all-accounts'):
for account in ctrl.getAllAccounts(args.get-all-accounts):
if args.gara:
if args.get-registered-accounts:
for account in ctrl.getAllRegisteredAccounts():
if args.gaea:
if args.get-enabled-accounts:
for account in ctrl.getAllEnabledAccounts():
if args.gaad:
if args.get-all-accounts-details:
for account in ctrl.getAllAccounts():
if args.gacd:
for codecId in ctrl.getActiveCodecs(args.gacd):
if args.get-active-codecs-details:
for codecId in ctrl.getActiveCodecs(args.get-active-codecs-details):
print("# codec",codecId,"-------------")
print(ctrl.getCodecDetails(args.gacd, codecId))
print(ctrl.getCodecDetails(args.get-active-codecs-details, codecId))
print("#-- ")
if args.sac:
if args.set-active-account:
if args.gad:
if args.get-account-details:
if hasattr(args, 'gacl'):
if hasattr(args, 'get-active-codecs'):
if args.sacl:
if args.set-active-codecs:
if args.enable:
ctrl.setAccountEnable(args.enable, True)
......@@ -150,7 +158,7 @@ if __name__ == "__main__":
if args.unregister:
ctrl.setAccountRegistered(args.unregister, False)
if args.gcl:
if args.get-call-list:
for call in ctrl.getAllCalls():
......@@ -188,49 +196,3 @@ if __name__ == "__main__":
# Get call details
elif opt == "--gcd":
if arg == "current": arg = sflphone.getCurrentCallID()
details = sflphone.getCallDetails(arg)
if details:
print "Call: " + arg
print "Account: " + details['ACCOUNTID']
print "Peer: " + details['PEER_NAME'] + "<" + details['PEER_NUMBER'] + ">"
# Transfer the current call
elif opt == "--transfer":
call = sflphone.callmanager.getCurrentCallID()
sflphone.Transfert(call, arg)
# account options
# Register an account
elif opt == "--register":
if not sflphone.checkAccountExists(arg):
print "Account " + arg + ": no such account."
elif arg in sflphone.getAllRegisteredAccounts():
print "Account " + arg + ": already registered."
sflphone.setAccountRegistered(arg, True)
print arg + ": Sent register request."
# Unregister an account
elif opt == "--unregister":
if not sflphone.checkAccountExists(arg):
print "Account " + arg + ": no such account."
elif arg not in sflphone.getAllRegisteredAccounts():
print "Account " + arg + ": is not registered."
sflphone.setAccountRegistered(arg, False)
print arg + ": Sent unregister request."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment