#!/usr/bin/python # $Id$ # # This file is part of ivam2. # # ivam2 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 2 of the License, or # (at your option) any later version. # # ivam2 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 ivam2; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import sys, os, getopt from ivamCore import log from ivamUtil import getContents, setContents import ivamCore, ivamVoiceBox def usage(): log("%s [--record-time=SECS] [--welcome-message=MESSAGE] [--pin=PIN] [--pin-file=PINFILE] [--default-record-time=SECS] [--default-pin=PIN] [--default-pin-file=PINFILE] [--record-only] [--no-record] [--debug] [--notify-script=PATH] [--email=EMAIL] [DIRECTORY]" % sys.argv[0]) def parseArgs(vb, argv): try: opts, args = getopt.getopt(argv[1:], "dh", ["help", "record-time=", "welcome-message=", "pin=", "pin-file=", "default-record-time=", "default-pin=", "default-pin-file=", "debug", "record-only", "no-record", "email=", "notify-script="]) except getopt.GetoptError: usage() sys.exit(1) recordTime = 60 pin = "-" email = "root" notifyScript = "ivam-newvoicebox" for o, a in opts: if o in ("-d", "--debug",): ivamCore.DEBUG = True elif o in ("-h", "--help",): usage() sys.exit() elif o in ("--default-record-time",): recordTime = int(a) elif o in ("--default-pin",): pin = a elif o in ("--default-pin-file",): pin = getContents(a) elif o in ("--notify-script",): notifyScript = a elif o in ("--email",): email = a dname = "msn-" + os.getenv("RINGMSN") if len(args): dname = args[0] + "/" + dname try: dname = ivamVoiceBox.setupVoiceBox(dname, pin, recordTime, email) ivamCore.log("Created new voice box, calling notification script. ('%s %s %s')" % (notifyScript, dname, email)) r=os.spawnvp(os.P_WAIT, notifyScript, (notifyScript, dname, email)) ivamCore.log("Program finished (return value is %i)." % r) except OSError: pass vb.setDirectory(dname) for o, a in opts: if o in ("--record-time",): vb.recordTime = int(a) elif o in ("--pin",): vb.setPin(a) elif o in ("--welcome-message",): vb.setWelcomeMessage(a) elif o in ("--pin-file",): vb.setPin(getContents(a)) elif o in ("--record-only",): vb.recordOnly = True elif o in ("--no-record",): vb.noRecord = True def main(): vb = ivamVoiceBox.VoiceBox() parseArgs(vb, sys.argv) ivamCore.newConnector(vb).run() sys.exit() if __name__ == "__main__": main()