-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·112 lines (82 loc) · 4.11 KB
/
manage.py
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
108
109
110
111
112
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
"""
Starts the SMS router with the given settings.
"""
import sys
import os
import argparse
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Producer
def start_router(args):
try:
from pragmatic_sms.routing import SmsRouter
router = SmsRouter()
router.start()
except Exception as e:
try:
from pragmatic_sms.conf import settings
except:
sys.stderr.write("Unable to import router settings."\
" You must pass a setting module using the --setting option or"\
" set the \"PSMS_SETTINGS_MODULE\" environnement variable. If "\
" you did so, ensure your setting module contains no error "\
" and is in the Python Path. You can ask manage.py to add a "\
" directory to the Python Path with the --python_path option "\
" or you can pass to --settings a path to the *py file directly.\n")
else:
raise e
def fake_sms(args):
try:
from pragmatic_sms.transports.cmd import CmdMessageTransport
transport = CmdMessageTransport(args.transport_name, 'receive_messages')
transport.fake_sms_reception(args.phone_number, " ".join(args.text))
except Exception as e:
try:
from pragmatic_sms.conf import settings
except:
sys.stderr.write("Unable to import router settings."\
" You must pass a setting module using the --setting option or"\
" set the \"PSMS_SETTINGS_MODULE\" environnement variable. If "\
" you did so, ensure your setting module contains no error "\
" and is in the Python Path. You can ask manage.py to add a "\
" directory to the Python Path with the --python_path option "\
" or you can pass to --settings a path to the *py file directly.\n")
else:
raise e
parser = argparse.ArgumentParser(description='Manage most Pragmatic SMS actions')
subparsers = parser.add_subparsers(title='Subcommands')
# subcomand to start the router
runrouter_parser = subparsers.add_parser('runrouter',
help='Start the SMS router')
runrouter_parser.add_argument('-s', '--settings', default='settings', type=str,
help="Specified in which module to look for settings",
)
runrouter_parser.add_argument("-p", "--python-path", dest="python_path",
default='.', type=str,
help="Add the following directory to the python path")
runrouter_parser.set_defaults(func=start_router)
# subcomand to start to simulate an incoming SMS
runrouter_parser = subparsers.add_parser('fake_sms',
help='Fake an incoming message')
runrouter_parser.add_argument('text', default='settings', type=str, nargs='+',
help="The text you want to fake being received",
)
runrouter_parser.add_argument('-n', '--phone-number', default='+555555', type=str,
help="The phone number the SMS is supposed to come from",
)
runrouter_parser.add_argument('-s', '--settings', default='settings', type=str,
help="Specified in which module to look for settings",
)
runrouter_parser.add_argument("-p", "--python-path", dest="python_path",
default='.', type=str,
help="Add the following directory to the python path")
runrouter_parser.add_argument("-t", "--transport-name", dest="transport_name",
default='cmd', type=str,
help="Register the CMD transport to the router with this name")
runrouter_parser.set_defaults(func=fake_sms)
args = parser.parse_args()
os.environ['PYTHON_PATH'] = args.python_path
os.environ['PSMS_SETTINGS_MODULE'] = args.settings
args.func(args)