summaryrefslogtreecommitdiffstats
path: root/clients/ivam-autobox
blob: 4b043d2cd6706fc85ae55554bd7aca289881c6b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python

import sys, os, getopt

from ivamCore import log
import ivamCore, ivamVoiceBox
from optparse import OptionParser

def usage():
    log("%s [--record-time=SECS] [--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=", "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 = "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)

        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 ("--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()