def check_incoming_call(self): """Checks whether incoming call faking is supported""" current = tuple([int(x) for x in gammu.Version()[2].split('.')]) if current < (1, 37, 91): raise unittest.SkipTest( 'Not supported in version {0}'.format(gammu.Version()[2]) )
def GetSystemInfo(): """ Returns system information in text form. """ pyver = sys.version.split()[0] wxver = wx.VERSION_STRING wammuver = Wammu.__version__ try: (gammuver, pgammuver) = gammu.Version() except: try: (gammuver, pgammuver, ignore) = gammu.Version() except: (gammuver, pgammuver) = ('Unknown', 'Unknown') (loc, charset) = locale.getdefaultlocale() bluez = 'None' try: import bluetooth bluez = 'PyBluez' except ImportError: pass result = SYSTEM_TEMPLATE % (sys.platform, pyver, wxver, wammuver, pgammuver, gammuver, bluez, loc, charset) if Wammu.configuration is not None: section = Wammu.configuration.ReadInt('/Gammu/Section') config = Wammu.configuration.gammu.GetConfig(section) result += 'connection %s\n' % config['Connection'] result += 'device %s\n' % config['Device'] result += 'model %s\n' % config['Model'] return result
def __init__(self, parent, config, phoneid=0, *args, **kwds): # begin wxGlade: TalkbackDialog.__init__ kwds["style"] = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.THICK_FRAME wx.Dialog.__init__(self, parent, *args, **kwds) self.main_panel = wx.Panel(self, -1) self.info_label = wx.StaticText(self, -1, _("Please share your experiences with Wammu and Gammu which is backend library. When you fill in following form, other users can benefit from your experiences in Gammu Phone Database. Only information you see here will be submited.")) self.top_static_line = wx.StaticLine(self, -1) self.manufacturer_label = wx.StaticText(self.main_panel, -1, _("Manufacturer:"), style=wx.ALIGN_CENTRE) self.manufacturer_choice = wx.Choice(self.main_panel, -1, choices=[]) self.model_label = wx.StaticText(self.main_panel, -1, _("Phone model:")) self.model_text_ctrl = wx.TextCtrl(self.main_panel, -1, "") self.connection_label = wx.StaticText(self.main_panel, -1, _("Connection type:")) self.connection_combo_box = wx.ComboBox(self.main_panel, -1, choices=[], style=wx.CB_DROPDOWN) self.gammu_model_label = wx.StaticText(self.main_panel, -1, _("Model in gammu configuration:")) self.model_combo_box = wx.ComboBox(self.main_panel, -1, choices=[], style=wx.CB_DROPDOWN) self.features_label = wx.StaticText(self.main_panel, -1, _("Working features:")) self.features_button = wx.Button(self.main_panel, -1, _("Please select features…")) self.gammu_version_text_label = wx.StaticText(self.main_panel, -1, _("Gammu version:")) self.gammu_version_label = wx.StaticText(self.main_panel, -1, "") self.note_label = wx.StaticText(self.main_panel, -1, _("Note:")) self.note_text_ctrl = wx.TextCtrl(self.main_panel, -1, "", style=wx.TE_MULTILINE) self.name_label = wx.StaticText(self.main_panel, -1, _("Your name:")) self.name_text_ctrl = wx.TextCtrl(self.main_panel, -1, "") self.email_label = wx.StaticText(self.main_panel, -1, _("Your email:")) self.email_text_ctrl = wx.TextCtrl(self.main_panel, -1, "") self.mangle_label = wx.StaticText(self.main_panel, -1, _("Email displaying:"), style=wx.ALIGN_CENTRE) self.mangle_choice = wx.Choice(self.main_panel, -1, choices=[_("Use [at] and [dot]"), _("Insert NOSPAM text at random position"), _("Display it normally"), _("Don't show email at all")]) self.bottom_static_line = wx.StaticLine(self, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.OnFeatures, self.features_button) # end wxGlade self.ns_string = '<%s>' % _('Not supported') self.connection_combo_box.Append(self.ns_string) for x in Wammu.Data.Connections: self.connection_combo_box.Append(x) for x in Wammu.Data.Models: self.model_combo_box.Append(x) for x in Wammu.Data.ManufacturerMap.keys(): self.manufacturer_choice.Append(x) self.wammu_cfg = config self.phoneid = phoneid self.features = [] self.gammu_version_label.SetLabel(gammu.Version()[0]) self.note_text_ctrl.SetValue('Report has been created using Wammu %s.\n' % Wammu.__version__) # Read phone name and manufacturer manufacturer = self.wammu_cfg.Read('/Phone-%d/Manufacturer' % phoneid) self.manufacturer_choice.SetStringSelection(manufacturer) model = self.wammu_cfg.Read('/Phone-%d/Model' % phoneid) self.model_text_ctrl.SetValue(model) # Set connection type which is being used section = self.wammu_cfg.ReadInt('/Gammu/Section') config = self.wammu_cfg.gammu.GetConfig(section) self.connection_combo_box.SetValue(config['Connection']) self.model_combo_box.SetValue(config['Model']) self.name_text_ctrl.SetValue(self.wammu_cfg.Read('/User/Name')) self.email_text_ctrl.SetValue(self.wammu_cfg.Read('/User/Email'))
def CompatConfig(cfg): ''' Adjust configuration for possible changes in Gammu history. ''' # 1.27.0 changed handling of boolean options # Pre 1.27.0 used strings if tuple(map(int, gammu.Version()[1].split('.'))) < (1, 27, 0): if cfg['SyncTime']: cfg['SyncTime'] = 'yes' else: cfg['SyncTime'] = 'no' if cfg['LockDevice']: cfg['LockDevice'] = 'yes' else: cfg['LockDevice'] = 'no' if cfg['StartInfo']: cfg['StartInfo'] = 'yes' else: cfg['StartInfo'] = 'no' # 1.27.0 accepted only numbers if tuple(map(int, gammu.Version()[1].split('.'))) == (1, 27, 0): if cfg['SyncTime']: cfg['SyncTime'] = 1 else: cfg['SyncTime'] = 0 if cfg['LockDevice']: cfg['LockDevice'] = 1 else: cfg['LockDevice'] = 0 if cfg['StartInfo']: cfg['StartInfo'] = 1 else: cfg['StartInfo'] = 0 # Older versions did not use model auto if cfg['Model'] == 'auto': cfg['Model'] = '' return cfg
def check_requirements(self): print 'Checking for python-gammu ...', try: import gammu version = gammu.Version() print 'found version %s using Gammu %s ...' % (version[1], version[0]), pygver = tuple(map(int, version[1].split('.'))) if pygver < PYTHONGAMMU_REQUIRED: print 'too old!' print 'You need python-gammu at least %s!' % '.'.join( map(str, PYTHONGAMMU_REQUIRED)) print 'You can get it from <http://wammu.eu/python-gammu/>' else: print 'OK' except ImportError, message: print print 'Could not import python-gammu!' print 'You can get it from <http://wammu.eu/python-gammu/>' print 'Import failed with following error: %s' % message
def Okay(self, evt): connection = self.connection_combo_box.GetValue() if connection == self.ns_string: connection = 'NULL' if len(self.features) == 0 and connection != 'NULL': wx.MessageDialog( self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'), _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return elif len(self.features) != 0 and connection == 'NULL': wx.MessageDialog( self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'), _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return man_str = self.manufacturer_choice.GetStringSelection() try: man_id = Wammu.Data.ManufacturerMap[man_str] except: wx.MessageDialog( self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Manufacturer'), _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return garble_id = self.mangle_choice.GetSelection() try: garble_text = Wammu.Data.GarbleMap[garble_id] except: wx.MessageDialog( self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Email displaying'), _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return # Remember user information for next run self.wammu_cfg.Write('/User/Name', self.name_text_ctrl.GetValue()) self.wammu_cfg.Write('/User/Email', self.email_text_ctrl.GetValue()) # Prepare data to post params_dict = { 'irobot': 'wammu', 'version': '2', 'manufacturer': man_id, 'name': self.model_text_ctrl.GetValue(), 'model': self.model_combo_box.GetValue(), 'connection': connection, 'note': self.note_text_ctrl.GetValue(), 'author_name': self.name_text_ctrl.GetValue(), 'author_email': self.email_text_ctrl.GetValue(), 'email_garble': garble_text, 'gammu_version': gammu.Version()[0], } for x in self.features: params_dict['fts[%s]' % x] = 1 # Convert unicode to raw utf-8 strigns so that they can be properly # handled by urllib and later by website for x in params_dict.keys(): if type(params_dict[x]) == unicode: params_dict[x] = params_dict[x].encode('utf-8') # Encode request and prepare headers params = urllib.urlencode(params_dict) headers = { 'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain' } # Perform request conn = httplib.HTTPConnection('wammu.eu') try: conn.request('POST', '/api/phones/new/', params, headers) # Check request response response = conn.getresponse() if response.status != 200: wx.MessageDialog( self, _('HTTP request failed with status %(code)d (%(text)s), please retry later or create entry manually.') % { 'code': response.status, 'text': response.reason, }, _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return except Exception as e: if hasattr(e, 'message') and e.message != '': msg = e.message elif hasattr(e, 'args') and len(e.args) > 0: msg = e.args[-1] else: msg = str(e) wx.MessageDialog( self, _('HTTP request failed with exception:\n%(exception)s\nPlease retry later or create entry manually.') % { 'exception': StrConv(msg), }, _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return # Verify acquired data data = response.read() conn.close() ok_test = OK_MATCHER.match(data) if ok_test is not None: url = 'https://%swammu.eu%s' % (Wammu.Utils.GetWebsiteLang(), ok_test.groups()[1]) result = wx.MessageDialog( self, _('Entry in Gammu Phone Database has been created, you can see it on <%s> URL.\nDo you want to open it in browser now?') % url, _('Entry created!'), wx.YES_NO | wx.ICON_INFORMATION ).ShowModal() if result == wx.ID_YES: Wammu.Webbrowser.Open(url) self.wammu_cfg.Write('/Wammu/TalkbackDone', 'yes') self.EndModal(wx.ID_OK) fail_test = FAIL_MATCHER.match(data) if fail_test is not None: wrong_fields = fail_test.groups()[0].split(',') fields_msg = '' for field in wrong_fields: if field == 'manufacturer': fields_msg += _('Manufacturer') + '\n' elif field == 'name': fields_msg += _('Phone model') + '\n' elif field == 'model': fields_msg += _('Model in gammu configuration') + '\n' elif field == 'connection': fields_msg += _('Connection type') + '\n' elif field == 'note': fields_msg += _('Note') + '\n' elif field == 'author_name': fields_msg += _('Your name') + '\n' elif field == 'author_email': fields_msg += _('Your email') + '\n' elif field == 'email_garble': fields_msg += _('Email displaying') + '\n' elif field == 'gammu_version': fields_msg += _('Gammu version') + '\n' else: fields_msg += _('Field: %s') % field + '\n' wx.MessageDialog( self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % fields_msg, _('Entry not created!'), wx.OK | wx.ICON_ERROR ).ShowModal() return
def Okay(self, evt): connection = self.connection_combo_box.GetValue() if connection == self.ns_string: connection = 'NULL' if len(self.features) == 0 and connection != 'NULL': wx.MessageDialog(self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'), _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return elif len(self.features) != 0 and connection == 'NULL': wx.MessageDialog(self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Supported features'), _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return man_str = self.manufacturer_choice.GetStringSelection() try: man_id = Wammu.Data.ManufacturerMap[man_str] except: wx.MessageDialog(self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Manufacturer'), _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return garble_id = self.mangle_choice.GetSelection() try: garble_text = Wammu.Data.GarbleMap[garble_id] except: wx.MessageDialog(self, _('Entry in Gammu Phone Database was not created, following fields are invalid:\n%s') % _('Email displaying'), _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return # Remember user information for next run self.wammu_cfg.Write('/User/Name', self.name_text_ctrl.GetValue()) self.wammu_cfg.Write('/User/Email', self.email_text_ctrl.GetValue()) # Prepare data to post params_dict = { 'irobot': 'wammu', 'version': '2', 'manufacturer': man_id, 'name': self.model_text_ctrl.GetValue(), 'model': self.model_combo_box.GetValue(), 'connection': connection, 'note': self.note_text_ctrl.GetValue(), 'author_name': self.name_text_ctrl.GetValue(), 'author_email': self.email_text_ctrl.GetValue(), 'email_garble': garble_text, 'gammu_version': gammu.Version()[0], } for x in self.features: params_dict['fts[%s]' % x] = 1 # Convert unicode to raw utf-8 strigns so that they can be properly # handled by urllib and later by website for x in params_dict.keys(): if type(params_dict[x]) == unicode: params_dict[x] = params_dict[x].encode('utf-8') # Encode request and prepare headers params = urllib.urlencode(params_dict) headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'} # Perform request conn = httplib.HTTPConnection('wammu.eu') try: conn.request('POST', '/api/phones/new/', params, headers) # Check request response response = conn.getresponse() if response.status != 200: wx.MessageDialog(self, _('HTTP request failed with status %(code)d (%(text)s), please retry later or create entry manually.') % { 'code': response.status, 'text': response.reason, }, _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return except Exception, e: if hasattr(e, 'message') and e.message != '': msg = e.message elif hasattr(e, 'args') and len(e.args) > 0: msg = e.args[-1] else: msg = str(e) wx.MessageDialog(self, _('HTTP request failed with exception:\n%(exception)s\nPlease retry later or create entry manually.') % { 'exception': StrConv(msg), }, _('Entry not created!'), wx.OK | wx.ICON_ERROR).ShowModal() return
def __init__(self, parent): wx.Dialog.__init__(self, parent, -1, _('About Wammu')) copyrightline = u'Copyright © 2003 - 2011 Michal Čihař' # default system colours bgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE) fgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT) hfgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT) colours = 'text="#%02x%02x%02x" bgcolor="#%02x%02x%02x" link="#%02x%02x%02x"' % ( fgc.Red(), fgc.Green(), fgc.Blue(), bgc.Red(), bgc.Green(), bgc.Blue(), hfgc.Red(), hfgc.Green(), hfgc.Blue()) text = ''' <html> <body %s> <center><font color="#ffffff"><table bgcolor="#458154" width="100%%" cellspacing="0" cellpadding="0" border="1"> <tr> <td align="center"> %s </td> </tr> </table></font> <p>%s</p> <p> <font size=-3> %s <br><br> %s <br><br> %s </font> </p> <p> <wxp module="wx" class="Button"> <param name="id" value="ID_OK"> </wxp> </p> </center> </body> </html> ''' % (colours, '''<img src="%s"><br><h2> Wammu %s</h2> %s<br> %s<br> %s<br> ''' % (Wammu.Paths.AppIconPath('wammu'), Wammu.__version__, _('Running on Python %s') % sys.version.split()[0], _('Using wxPython %s') % wx.VERSION_STRING, _('Using python-gammu %(python_gammu_version)s and Gammu %(gammu_version)s') % { 'python_gammu_version': gammu.Version()[1], 'gammu_version': gammu.Version()[0] }), _('<b>Wammu</b> is a wxPython based GUI for Gammu.'), copyrightline, _(''' This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. '''), _(''' 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. ''')) html = wx.html.HtmlWindow(self, -1, size=(500, -1)) html.SetPage(text) btn = html.FindWindowById(wx.ID_OK) if btn is not None: btn.SetDefault() representation = html.GetInternalRepresentation() html.SetSize( (representation.GetWidth() + 25, representation.GetHeight() + 25) ) self.SetClientSize(html.GetSize()) self.CentreOnParent(wx.BOTH)
import threading from wsgiref import simple_server from urlparse import parse_qs from time import sleep from Queue import Queue, Empty from urllib import urlencode, urlopen import logging import random import gammu from settings import * logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) gammu_version = float(gammu.Version()[0].rpartition('.')[0]) logger.info(u"Gammu Version: %s" % gammu_version) class WsgiThread(threading.Thread): """ HTTP Web Server receiving Outgoing SMS requests """ def __init__(self, to_modem): threading.Thread.__init__(self, name='wsgi') self.to_modem = to_modem self.server = simple_server.make_server('', LISTENING_PORT, self.app) def run(self): self.server.serve_forever(poll_interval=0.5) def app(self, environ, start_response):