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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/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
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 = "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)
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()
|