raise RuntimeError("Failed to load sipclient's configuration: %s\nIf an old configuration file is in place, delete it or move it and recreate the configuration using the sip_settings script." % str(e))
account_manager.load()
if self.account_name is None:
self.account = account_manager.default_account
else:
possible_accounts = [account for account in account_manager.iter_accounts() if self.account_name in account.id and account.enabled]
if len(possible_accounts) > 1:
raise RuntimeError("More than one account exists which matches %s: %s" % (self.account_name, ", ".join(sorted(account.id for account in possible_accounts))))
if len(possible_accounts) == 0:
raise RuntimeError("No enabled account that matches %s was found. Available and enabled accounts: %s" % (self.account_name, ", ".join(sorted(account.id for account in account_manager.get_accounts() if account.enabled))))
self.account = possible_accounts[0]
if self.account is None:
raise RuntimeError("Unknown account %s. Available enabled accounts: %s" % (self.account_name, ', '.join(sorted(account.id for account in account_manager.iter_accounts() if account.enabled))))
elif self.account == BonjourAccount():
raise RuntimeError("Cannot use bonjour account to publish presence information")
elif not self.account.presence.enabled:
raise RuntimeError("Presence is not enabled for account %s" % self.account.id)
self.output.put("PIDF as currently defined is invalid: %s" % str(e))
self.publishing = False
except PJSIPError as e:
self.output.put("Publish failed: %s" % str(e))
except:
traceback.print_exc()
self.publishing = False
def _output_handler(self, event):
event = event.decode() if isinstance(event, bytes) else event
if isinstance(event, Prompt):
sys.stdout.write(event+'> ')
sys.stdout.flush()
else:
sys.stdout.write(event+'\n')
if __name__ == "__main__":
description = "This script publishes the presence event package to a SIP Presence Agent for the given SIP account, the presence information can be changed using a menu-driven interface."
parser.add_option("-a", "--account-name", type="string", dest="account_name", help="The name of the account to use.")
parser.add_option("-s", "--trace-sip", action="store_true", dest="trace_sip", default=False, help="Dump the raw contents of incoming and outgoing SIP messages (disabled by default).")