Tagging the 0.3c release - Release from 06-Oct-2007
git-svn-id: http://www.neo1973-germany.de/svn@40 46df4e5c-bc4e-4628-a0fc-830ba316316dmain
parent
a273e076e3
commit
2fca8a9974
@ -0,0 +1,241 @@
|
|||||||
|
"""
|
||||||
|
* ProcessInterface.py - SettingsGUI -
|
||||||
|
* Interface to interactive userspace processes
|
||||||
|
*
|
||||||
|
* Based on code from Jens Diemer <- ToDo - License
|
||||||
|
*
|
||||||
|
* Using libgsm_tool until there is a python bindung available
|
||||||
|
*
|
||||||
|
* (C) 2007 by Kristian Mueller <kristian-m@kristian-m.de>
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
import signal
|
||||||
|
import time
|
||||||
|
|
||||||
|
class error_poller(threading.Thread):
|
||||||
|
def __init__(self, error_stream):
|
||||||
|
self.error_stream = error_stream
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
## init
|
||||||
|
self.out_data = []
|
||||||
|
self.keep_going = True
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while self.keep_going:
|
||||||
|
self.error_stream.flush()
|
||||||
|
line = self.error_stream.readline()
|
||||||
|
if line == "": break
|
||||||
|
self.out_data.append(line)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
"""
|
||||||
|
kills process if still running
|
||||||
|
"""
|
||||||
|
if self.process.poll() != None:
|
||||||
|
print " already killed"
|
||||||
|
return
|
||||||
|
|
||||||
|
self.killed = True
|
||||||
|
os.kill(self.process.pid, signal.SIGQUIT)
|
||||||
|
## gice it a second
|
||||||
|
time.sleep(1)
|
||||||
|
## have to kill - as readline is blocking.
|
||||||
|
os.kill( self.process.pid, signal.SIGKILL )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class async_process(threading.Thread):
|
||||||
|
"""
|
||||||
|
asynchronous subprocess handler
|
||||||
|
|
||||||
|
used to read the output - access through out_data
|
||||||
|
|
||||||
|
not working with Windows - as there is no os.kill() available
|
||||||
|
command - the command to be started
|
||||||
|
cwd - directory for execution
|
||||||
|
timeout - timeout for stop -
|
||||||
|
0 to execution until self.keep_going is set to False
|
||||||
|
"""
|
||||||
|
def __init__(self, command, options, cwd, timeout):
|
||||||
|
self.command = command
|
||||||
|
self.options = options
|
||||||
|
self.cwd = cwd
|
||||||
|
self.timeout = timeout
|
||||||
|
self.process_created = False ## find out when subprocess() finished
|
||||||
|
self.keep_going = True
|
||||||
|
|
||||||
|
self.killed = False
|
||||||
|
self.out_data = [] # output buffer <- ToDo use a list - for now '\n's
|
||||||
|
self.events = []
|
||||||
|
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
# print "COMMAND was >>%s<<" % self.command
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
"""
|
||||||
|
if timeout > 0:
|
||||||
|
self.join( self.timeout )
|
||||||
|
else:
|
||||||
|
self.keep_going = True
|
||||||
|
while self.keep_going == True:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
self.join()
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
"""
|
||||||
|
# provide return code
|
||||||
|
#self.returncode = self.process.returncode
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print "Executes subprocess [%s]" % " ".join([self.command] + self.options)
|
||||||
|
self.process = subprocess.Popen(
|
||||||
|
# ["libgsmd-tool", "-mshell"], cwd="/usr/bin/",
|
||||||
|
[self.command] + self.options,
|
||||||
|
cwd = self.cwd,
|
||||||
|
bufsize = 1, # no (line) buffer
|
||||||
|
shell = False,
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE,
|
||||||
|
stdin = subprocess.PIPE
|
||||||
|
)
|
||||||
|
self.process_created = True
|
||||||
|
# save output
|
||||||
|
while self.keep_going:
|
||||||
|
self.process.stdout.flush()
|
||||||
|
line = self.process.stdout.readline()
|
||||||
|
if line == "": break
|
||||||
|
self.out_data.append(line)
|
||||||
|
for event in self.events:
|
||||||
|
if line.find(event[0]) >= 0:
|
||||||
|
event[1](line)
|
||||||
|
|
||||||
|
print "Subprocess terminated"
|
||||||
|
|
||||||
|
## event_name <- string to search for (e.g. EVENT: blah changed...)
|
||||||
|
## function <- function to call
|
||||||
|
def register_event_handler(self, event_name, function, args, kwargs):
|
||||||
|
self.events.append([event_name, function, args, kwargs])
|
||||||
|
|
||||||
|
def stop( self ):
|
||||||
|
"""
|
||||||
|
kills process if still running
|
||||||
|
"""
|
||||||
|
if self.process.poll() != None:
|
||||||
|
print " already killed"
|
||||||
|
return
|
||||||
|
|
||||||
|
self.killed = True
|
||||||
|
os.kill( self.process.pid, signal.SIGQUIT )
|
||||||
|
## gice it a second
|
||||||
|
time.sleep(1)
|
||||||
|
## have to kill - as readline is blocking.
|
||||||
|
os.kill( self.process.pid, signal.SIGKILL )
|
||||||
|
|
||||||
|
class ProcessInterface:
|
||||||
|
def __init__(self, command):
|
||||||
|
self.command = command.split()[0]
|
||||||
|
self.options = [command.split()[x] for x in range(1,len(command.split()))]
|
||||||
|
self.process = async_process(self.command, self.options, "/", timeout = 0)
|
||||||
|
# print "starting <%s>" %self.command
|
||||||
|
while self.process.process_created == False:
|
||||||
|
time.sleep(0.1)
|
||||||
|
self.error_poller = error_poller(self.process.process.stderr)
|
||||||
|
|
||||||
|
## write string to buffer - new line is attached string
|
||||||
|
def write_to_process(self, string):
|
||||||
|
## find out if process is still running before wire
|
||||||
|
if self.process.process.poll() == None:
|
||||||
|
self.process.process.stdin.write("%s\n" % string)
|
||||||
|
|
||||||
|
## read back string with all output lines currently in buffer
|
||||||
|
def read_from_process(self):
|
||||||
|
out_string = ""
|
||||||
|
for x in self.process.out_data:
|
||||||
|
out_string += x
|
||||||
|
return out_string
|
||||||
|
|
||||||
|
## read back string with all error lines currently in buffer
|
||||||
|
def read_error_from_process(self):
|
||||||
|
out_string = ""
|
||||||
|
for x in self.error_poller.out_data:
|
||||||
|
out_string += x
|
||||||
|
return out_string
|
||||||
|
|
||||||
|
## removes first error in list
|
||||||
|
def get_error(self):
|
||||||
|
if len(self.error_poller.out_data) > 0:
|
||||||
|
out_string = self.error_poller.out_data[0]
|
||||||
|
self.error_poller.out_data.remove(out_string)
|
||||||
|
out_string = out_string.split("\n")[0]
|
||||||
|
return out_string
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
## removes first output in list
|
||||||
|
def get_output(self):
|
||||||
|
if len(self.process.out_data) > 0:
|
||||||
|
out_string = self.process.out_data[0]
|
||||||
|
self.process.out_data.remove(out_string)
|
||||||
|
out_string = out_string.split("\n")[0]
|
||||||
|
return out_string
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def register_event_handler(self, event_name, function, args = [], kwargs = {}):
|
||||||
|
self.process.register_event_handler(event_name, function, args, kwargs)
|
||||||
|
|
||||||
|
def close_process(self):
|
||||||
|
print "trying to kill process"
|
||||||
|
self.process.keep_going = False
|
||||||
|
self.process.join(1)
|
||||||
|
self.process.stop()
|
||||||
|
|
||||||
|
|
||||||
|
class test:
|
||||||
|
def do_test(self):
|
||||||
|
print "Test interface"
|
||||||
|
bash = ProcessInterface("/bin/sh")
|
||||||
|
print "subprocess created"
|
||||||
|
|
||||||
|
time_running = 0
|
||||||
|
while time_running < 5:
|
||||||
|
print "\nEntering while loop"
|
||||||
|
time_running = time_running + 1
|
||||||
|
bash.write_to_process("echo hello")
|
||||||
|
bash.write_to_process("echo error > /dev/stderr")
|
||||||
|
time.sleep(0.2)
|
||||||
|
print "next output<%s>" % bash.get_output()
|
||||||
|
# print "===\nstdout: <%s> \n===" % bash.read_from_process()
|
||||||
|
print "next error<%s>" % bash.get_error()
|
||||||
|
# print "===\nstderr: <%s> \n===" % bash.read_error_from_process()
|
||||||
|
# time.sleep(0.2)
|
||||||
|
|
||||||
|
bash.close_process()
|
||||||
|
print "halllooo"
|
||||||
|
|
||||||
|
# ToDo remove
|
||||||
|
## self.process = subprocess.Popen(self.command, cwd = self.cwd, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE)
|
||||||
|
|
||||||
|
#test = test()
|
||||||
|
#test.do_test()
|
@ -0,0 +1,176 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
"""
|
||||||
|
* SMSTool.py - Tool to send SMS - using libgsmd-tool
|
||||||
|
*
|
||||||
|
* ProcessInterface copied from SettingsGUI
|
||||||
|
*
|
||||||
|
* (C) 2007 by Kristian Mueller <kristian-m@kristian-m.de>
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import gtk
|
||||||
|
import gobject
|
||||||
|
import time
|
||||||
|
|
||||||
|
from smstool.ProcessInterface import *
|
||||||
|
|
||||||
|
LIBGSM_TOOL = "/usr/bin/libgsmd-tool"
|
||||||
|
|
||||||
|
|
||||||
|
class SMSTool:
|
||||||
|
def delete_event(self, widget, event, data=None):
|
||||||
|
gtk.main_quit()
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def update_ui(self):
|
||||||
|
if self.message_box_activated:
|
||||||
|
self.message_box_activated = False
|
||||||
|
gtk.gdk.threads_enter()
|
||||||
|
try:
|
||||||
|
mbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
|
||||||
|
gtk.BUTTONS_OK, self.message_box_text);
|
||||||
|
response = mbox.run()
|
||||||
|
mbox.hide()
|
||||||
|
mbox.destroy()
|
||||||
|
finally:
|
||||||
|
gtk.gdk.threads_leave()
|
||||||
|
if self.close_application:
|
||||||
|
exit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
|
self.window.set_title("SMS Tool")
|
||||||
|
self.window.connect("delete_event", self.delete_event)
|
||||||
|
self.window.set_border_width(0)
|
||||||
|
self.message_box_activated = False
|
||||||
|
self.close_application = False
|
||||||
|
|
||||||
|
if not self.connect_to_gsmdtool(None):
|
||||||
|
self.message_box_text = "Could not connect to the GSM daemon.\n\
|
||||||
|
SMSTool will quit now."
|
||||||
|
# self.message_box_activated = True
|
||||||
|
# self.close_application = True
|
||||||
|
|
||||||
|
main_box = gtk.VBox()
|
||||||
|
main_box.set_border_width(10)
|
||||||
|
|
||||||
|
text_frame = gtk.Frame("Message Content")
|
||||||
|
SMS_text_view = gtk.TextView()
|
||||||
|
self.SMS_text_buffer = SMS_text_view.get_buffer()
|
||||||
|
self.SMS_text_buffer.set_text("Hello mobile World!")
|
||||||
|
text_frame.add(SMS_text_view)
|
||||||
|
main_box.add(text_frame)
|
||||||
|
|
||||||
|
number_frame = gtk.Frame("Telephone Number")
|
||||||
|
self.number_entry = gtk.Entry()
|
||||||
|
self.number_entry.set_text("00491706692447")
|
||||||
|
# number_frame.set_spacing(15)
|
||||||
|
number_frame.add(self.number_entry)
|
||||||
|
main_box.pack_start(number_frame, False, False, 0)
|
||||||
|
|
||||||
|
|
||||||
|
btn_box = gtk.HBox()
|
||||||
|
|
||||||
|
"""
|
||||||
|
gsm_btn = gtk.Button("Connect\nto gsmd")
|
||||||
|
gsm_btn.connect("clicked", self.connect_to_gsmdtool)
|
||||||
|
btn_box.add(gsm_btn)
|
||||||
|
"""
|
||||||
|
|
||||||
|
send_btn = gtk.Button("Send\nSMS")
|
||||||
|
send_btn.connect("clicked", self.send_sms)
|
||||||
|
btn_box.add(send_btn)
|
||||||
|
|
||||||
|
main_box.pack_start(btn_box, False, False, 0)
|
||||||
|
|
||||||
|
self.window.add(main_box)
|
||||||
|
self.window.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def update_state(self, text):
|
||||||
|
print ("state: %s" % text).rstrip("\n")
|
||||||
|
|
||||||
|
def message_was_send(self, text):
|
||||||
|
self.message_box_text = "Message send.\nModem: %s" % text
|
||||||
|
self.message_box_activated = True
|
||||||
|
|
||||||
|
|
||||||
|
def send_sms(self, widget):
|
||||||
|
text = self.SMS_text_buffer.get_text(
|
||||||
|
self.SMS_text_buffer.get_start_iter(),
|
||||||
|
self.SMS_text_buffer.get_end_iter())
|
||||||
|
number = self.number_entry.get_text()
|
||||||
|
|
||||||
|
text = " ".join(text.split("\n"))
|
||||||
|
text = " ".join(text.split("\r"))
|
||||||
|
text = "\""+text+"\""
|
||||||
|
|
||||||
|
print "sending... \n---\n%s\n--- \nto <%s>" % (text, number)
|
||||||
|
if self.gsm_tool:
|
||||||
|
self.gsm_tool.write_to_process("ss=0,%s,%s" % (number, text))
|
||||||
|
else:
|
||||||
|
self.update_state("ERROR: Could not send you message, sorry!")
|
||||||
|
|
||||||
|
def connect_to_gsmdtool(self, widget):
|
||||||
|
if os.path.exists(LIBGSM_TOOL):
|
||||||
|
self.update_state("connection to gsmd...")
|
||||||
|
self.gsm_tool = ProcessInterface(
|
||||||
|
"%s -m shell" % LIBGSM_TOOL)
|
||||||
|
time.sleep(1) # wait for tool to connect (or not)
|
||||||
|
error_out = self.gsm_tool.read_error_from_process()
|
||||||
|
if len(error_out) > 0:
|
||||||
|
error_out = error_out.rstrip('\n').lstrip('\n').rstrip(
|
||||||
|
'\r').lstrip('\r')
|
||||||
|
print "error libgsm-tool: %s" % error_out
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.gsm_tool.register_event_handler("", self.update_state)
|
||||||
|
self.gsm_tool.register_event_handler("Send: ", self.message_was_send)
|
||||||
|
"""
|
||||||
|
this is disabled, for now - we should be connected
|
||||||
|
|
||||||
|
print "initializing gsm"
|
||||||
|
self.gsm_tool.write_to_process("O")
|
||||||
|
time.sleep(0.3)
|
||||||
|
self.gsm_tool.write_to_process("r")
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.update_state("%s not found, can not send SMS." % LIBGSM_TOOL)
|
||||||
|
self.gsm_tool = False
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
gobject.timeout_add(500, SMSTool.update_ui) # every 1/2 second
|
||||||
|
try:
|
||||||
|
if gtk.gtk_version[0] == 2:
|
||||||
|
gtk.gdk.threads_init()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
gtk.gdk.threads_enter()
|
||||||
|
gtk.main()
|
||||||
|
gtk.gdk.threads_leave()
|
||||||
|
|
||||||
|
|
||||||
|
if (__name__ == '__main__'):
|
||||||
|
SMSTool = SMSTool()
|
||||||
|
main()
|
@ -0,0 +1,14 @@
|
|||||||
|
# This config file installs SMSTool in /usr
|
||||||
|
# Replace /usr by /usr/local if you prefer
|
||||||
|
|
||||||
|
[install]
|
||||||
|
install-scripts = /usr/bin
|
||||||
|
install-data = /usr/share
|
||||||
|
|
||||||
|
[install_lib]
|
||||||
|
compile = 1
|
||||||
|
optimize = 1
|
||||||
|
|
||||||
|
[sdist]
|
||||||
|
force-manifest = 1
|
||||||
|
formats = bztar
|
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
"""
|
||||||
|
* setup.py - script to install SettingGUI
|
||||||
|
* (C) 2007 by Kristian Mueller <kristian-m@kristian-m.de>
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from distutils.core import setup
|
||||||
|
import os
|
||||||
|
|
||||||
|
setup(name='SMSTool',
|
||||||
|
description='GUI for SMS handling',
|
||||||
|
long_description='GUI to read and write SMS on FIC1973 (OpenMoko Distribution)',
|
||||||
|
author='Kristian Mueller',
|
||||||
|
author_email='kristian-m@kristian-m.de',
|
||||||
|
url='http://wiki.openmoko.org/wiki/SMSTool',
|
||||||
|
version='0.3c',
|
||||||
|
license='GPL_v2',
|
||||||
|
scripts=['SMSTool.py'],
|
||||||
|
package_dir = {"smstool" : ""},
|
||||||
|
packages = ["smstool"],
|
||||||
|
)
|
Loading…
Reference in New Issue