Skip to content
Snippets Groups Projects
Commit 90204008 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

tools: bring back python daemon controler

This patch brings back an old python daemon DBus client
and update it to latest changes (API, rebranding, etc).
This version needs Python3, plus python3-dbus and
python3-gobject modules to run.

Refs #67053

Change-Id: Ia840a3547a428becd93b56a1d0e6cac4a4f3d5e5
parent 43ed62cf
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2008 by the Free Software Foundation, Inc.
# #
# This program is free software; you can redistribute it and/or # Copyright (C) 2015 Savoir-Faire Linux Inc.
# modify it under the terms of the GNU General Public License # Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. # 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, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
...@@ -12,6 +14,16 @@ ...@@ -12,6 +14,16 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Additional permission under GNU GPL version 3 section 7:
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
# grants you additional permission to convey the resulting work.
# Corresponding Source for a non-source form of such a combination
# shall include the source code for the parts of OpenSSL used as well
# as that of the covered work.
#
This diff is collapsed.
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Copyright (C) 2009 by the Free Software Foundation, Inc. # Copyright (C) 2015 Savoir-Faire Linux Inc.
# Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or modify
# modify it under the terms of the GNU General Public License # it under the terms of the GNU General Public License as published by
# as published by the Free Software Foundation; either version 2 # the Free Software Foundation; either version 3 of the License, or
# of the License, or (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
...@@ -14,151 +15,161 @@ ...@@ -14,151 +15,161 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Additional permission under GNU GPL version 3 section 7:
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
# grants you additional permission to convey the resulting work.
# Corresponding Source for a non-source form of such a combination
# shall include the source code for the parts of OpenSSL used as well
# as that of the covered work.
#
import sys import sys
import os import os
import random import random
from traceback import print_exc import time
import argparse
import gobject from gi.repository import GObject
from gobject import GObject
import getopt from errors import *
from controler import DRingCtrl
import time def printAccountDetails(account):
details = ctrl.getAccountDetails(account)
print(account)
for k in sorted(details.keys()):
print(" %s: %s" % (k, details[k]))
print()
from threading import Thread 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')
from Errors import * parser.add_argument('--gac', help='Get all codecs', action='store_true')
try: parser.add_argument('--gad', help='Get account details',
import dbus metavar='<account>', type=str)
from dbus.mainloop.glib import DBusGMainLoop
except ImportError, e:
raise SflPhoneError("No python-dbus module found")
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)
from sflphonectrl import SflPhoneCtrl 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',
# Main application metavar='<account>', type=str)
#
parser.add_argument('--sacl', 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')
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()
group.add_argument('--accept', help='Accept the call', metavar='<account>')
group.add_argument('--hangup', help='Hangup the call', metavar='<account>')
group.add_argument('--refuse', help='Refuse the call', metavar='<account>')
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>')
args = parser.parse_args()
ctrl = DRingCtrl(sys.argv[0])
def printHelp():
"""Print help"""
print sys.argv[0] + " usage:\n\
\n\
--help Print this help.\n\
\n\
--gaa Get all accounts.\n\
--gara Get all registered accounts. \n\
--gaea Get all enabled accounts. \n\
--gasa Get all SIP accounts. \n\
--gaia Get all IAX accounts. \n\
--gcc Get current callid. \n\
--gacl Get active codec list. \n\
--sac Set accout for next call \n\
\n\
--gad <account> Get account details . \n\
--enable <account> Enable the account. \n\
--disable <account> Disable the account. \n\
--register <account> Register the account. \n\
--unregister <account> Unregister the account. \n\
\n\
--call <destination> Call to number \n\
--transfer <destination> Transfer active call \n\
\n\
--gcd <callid|\"current\"> Get call details. \n\
--accept <callid|\"current\"> Accept the call \n\
--hangup <callid|\"current\"> Hangup the call \n\
--refuse <callid|\"current\"> Refuse the call \n\
--hold <callid|\"current\"> Hold the call \n\
--unhold <callid|\"current\"> Unhold the call \n\
--dtmf <key> Send DTMF\n"
# Option definition
try:
opts, args = getopt.getopt(sys.argv[1:],"",
[ "help", "gaa", "gal", "gara", "gaea", "gasa", "gaia",
"gacl", "gac", "gcc", "hangup=", "refuse=", "hold",
"unhold=", "transfer=","dtmf=", "accept=", "gcd=",
"gad=", "register=", "unregister=", "enable=", "disable=",
"call=", "sac=" ])
except getopt.GetoptError,err:
print str(err)
sys.exit(2)
# SFLPhone instance.
sflphone = SflPhoneCtrl()
# If no arguments, run the d-bus event loop.
if len(sys.argv) == 1: if len(sys.argv) == 1:
loop = gobject.MainLoop() ctrl.run()
loop.run() sys.exit(0)
# Parse all arguments if args.gac:
else: print(ctrl.getAllCodecs())
for opt, arg in opts:
if opt == "--help": if hasattr(args, 'gaa'):
printHelp() for account in ctrl.getAllAccounts(args.gaa):
print(account)
# if args.gara:
# info options for account in ctrl.getAllRegisteredAccounts():
# print(account)
# Get all accounts if args.gaea:
elif opt == "--gaa": for account in ctrl.getAllEnabledAccounts():
for account in sflphone.getAllAccounts(): print(account)
print account
if args.gaad:
# Get all registered accounts for account in ctrl.getAllAccounts():
elif opt == "--gara": printAccountDetails(account)
for account in sflphone.getAllRegisteredAccounts():
print account if args.sac:
ctrl.setAccount(args.sac)
# Get all enabled accounts
elif opt == "--gaea": if args.gad:
for account in sflphone.getAllEnabledAccounts(): printAccountDetails(args.gad)
print account
if args.sacl:
# Get all SIP accounts ctrl.setActiveCodecList(codec_list=args.sacl)
elif opt == "--gasa":
for account in sflphone.getAllSipAccounts():
print account
# Get all IAX accounts
elif opt == "--gaia":
for account in sflphone.getAllIaxAccounts():
print account
# Get current call
elif opt == "--gcc":
call = sflphone.getCurrentCallID()
if call:
print call
else:
print "No current call."
# Get account details
elif opt == "--gad":
if sflphone.checkAccountExists(arg):
details = sflphone.getAccountDetails(arg)
for var in details:
print var + ": " + details[var]
else:
print "No such account: " + arg
# Get active codec list if args.enable:
elif opt == "--gacl": ctrl.setAccountEnable(args.enable, True)
print "Not implemented."
if args.disable:
ctrl.setAccountEnable(args.enable, False)
if args.register:
ctrl.setAccountRegistered(args.register, True)
if args.unregister:
ctrl.setAccountRegistered(args.unregister, False)
if args.gcl:
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:
sflphone.Dtmf(dtmf)
"""
# Get call details # Get call details
elif opt == "--gcd": elif opt == "--gcd":
...@@ -176,33 +187,6 @@ else: ...@@ -176,33 +187,6 @@ else:
else: else:
sflphone.setAccount(arg) sflphone.setAccount(arg)
#
# call options
#
# Make a call
elif opt == "--call":
sflphone.Call(arg)
# Hangup a call
elif opt == "--hangup":
if arg == "current":
arg = sflphone.getCurrentCallID()
if arg:
sflphone.HangUp(arg)
# Refuse a call
elif opt == "--refuse":
if arg == "current": arg = sflphone.getCurrentCallID()
sflphone.Refuse(arg)
# Hold a call
elif opt == "--hold":
if arg == "current": arg = sflphone.getCurrentCallID()
sflphone.Hold(arg)
# Unhold a call # Unhold a call
elif opt == "--unhold": elif opt == "--unhold":
if arg == "current": arg = sflphone.getCurrentCallID() if arg == "current": arg = sflphone.getCurrentCallID()
...@@ -217,11 +201,6 @@ else: ...@@ -217,11 +201,6 @@ else:
elif opt == "--dtmf": elif opt == "--dtmf":
sflphone.Dtmf(arg) sflphone.Dtmf(arg)
# Accept a call
elif opt == "--accept":
if arg == "current": arg = sflphone.getCurrentCallID()
sflphone.Accept(arg)
# #
# account options # account options
...@@ -277,3 +256,4 @@ else: ...@@ -277,3 +256,4 @@ else:
print arg + ": Account disabled." print arg + ": Account disabled."
"""
# Copyright (C) 2008 by the Free Software Foundation, Inc.
# #
# This program is free software; you can redistribute it and/or # Copyright (C) 2015 Savoir-Faire Linux Inc.
# modify it under the terms of the GNU General Public License # Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. # 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, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
...@@ -12,29 +14,40 @@ ...@@ -12,29 +14,40 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Additional permission under GNU GPL version 3 section 7:
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
# grants you additional permission to convey the resulting work.
# Corresponding Source for a non-source form of such a combination
# shall include the source code for the parts of OpenSSL used as well
# as that of the covered work.
#
"""Internal exceptions"""
"""Our own Errors exceptions""" __all__ = ['DRingCtrlError',
'DRingCtrlDBusError',
'DRingCtrlDeamonError']
class DRingCtrlError(Exception):
"""Base class for all our exceptions."""
class SflPhoneError(Exception):
"""Base class for all SflPhone exceptions."""
def __init__(self, help=None): def __init__(self, help=None):
self.help=help self.help = str(help)
def __str__(self):
return repr(self.help)
def __str__(self):
return self.help
class SPdbusError(SflPhoneError): class DRingCtrlDBusError(DRingCtrlError):
"""General error for dbus communication""" """General error for dbus communication"""
class SPdaemonError(SflPhoneError): class DRingCtrlDeamonError(DRingCtrlError):
"""General error for daemon communication""" """General error for daemon communication"""
class SPserverError(SflPhoneError): class DRingCtrlAccountError(DRingCtrlError):
"""General error for server communication"""
class SPconfigurationError(SflPhoneError):
"""General error for configuration"""
class SPaccountError(SflPhoneError):
"""General error for account handling""" """General error for account handling"""
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment