-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsms_shell.py
executable file
·84 lines (67 loc) · 1.97 KB
/
sms_shell.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4
import sys
import os
import struct
from cmd import Cmd
from subprocess import Popen
p = Popen(['watch', 'ls']) # something long running
# ... do other stuff while subprocess is running
p.terminate()
class SmsShell(Cmd):
"""
The shell that prompt for an SMS to send
"""
@staticmethod
def get_terminal_size():
"""
Try to get the terminal size in to allow left and top
align
"""
def ioctl_GWINSZ(fd):
try:
import fcntl, termios
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
except ImportError:
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
try:
cr = (env['LINES'], env['COLUMNS'])
except:
cr = (25, 80)
return int(cr[1]), int(cr[0])
def __init__(self, phone_number="+1234567890", *args, **kwargs):
Cmd.__init__(self, *args, **kwargs)
self.phone_number = phone_number
self.prompt = "%s >>> " % phone_number
self.p = Popen(['tail', '-f', '/home/kevin/Bureau/test.txt'])
def do_EOF(self, command):
"""
Exit the shell.
"""
print
self.p.terminate()
sys.exit(0)
def default(self, command):
"""
Send the message as an sms
"""
print "<<< %s" % command
def emptyline(self):
"""
Do nothing if the user enter nothing.
"""
if __name__ == "__main__":
shell = SmsShell()
shell.cmdloop()