From 6f5bfca232c6d9691f88f34e03fdf4daeb4adeed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 25 Sep 2008 12:53:04 +0000 Subject: [PATCH] Add --info command line option to show connection info (bug #426). --- ChangeLog | 1 + wammu.1 | 4 ++++ wammu.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0890ec9e..24c61ed8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ two versions can be retrieved from Subversion. * Properly skip corrupted entries (bug #467). * Added export of messages to XML (thanks to Florent Kaisser). * Properly report failures when importing backup (bug #303). +* Add --info command line option to show connection info (bug #426). 0.28 ==== (2008-07-22) diff --git a/wammu.1 b/wammu.1 index 7abeb258..45065032 100644 --- a/wammu.1 +++ b/wammu.1 @@ -28,6 +28,10 @@ Show version of program. Use locales from current directory rather than system ones. This is mostly useful for development or when running from unpacked tarball without installation. +.TP +.B \-i, \-\-info +Prints connection settings and tries to connect the phone and display +some basic information about it. This does not use GUI. .SH LICENCE This program is licensed under GNU/GPL version 2. diff --git a/wammu.py b/wammu.py index c334878b..fb712474 100755 --- a/wammu.py +++ b/wammu.py @@ -67,16 +67,64 @@ def usage(): print '%-20s ... %s' % ( '-l/--local-locales', _('force using of locales from current directory rather than system ones')) + print '%-20s ... %s' % ( + '-i/--info', + _('prints connection settings and tries to connect the phone')) print +def info(): + ''' + Displays configuration summary and tries to connect to phone. + ''' + import Wammu.WammuSettings + import gammu + + settings = Wammu.WammuSettings.WammuConfig() + section = settings.ReadInt('/Gammu/Section') + config = settings.gammu.GetConfig(section) + if config['Connection'] == '' or config['Device'] == '': + print _('Wammu is not configured!') + cfg = { + 'StartInfo': settings.Read('/Gammu/StartInfo'), + 'UseGlobalDebugFile': 1, + 'DebugFile': None, # Set on other place + 'SyncTime': settings.Read('/Gammu/SyncTime'), + 'Connection': config['Connection'], + 'LockDevice': settings.Read('/Gammu/LockDevice'), + 'DebugLevel': 'textalldate', # Set on other place + 'Device': config['Device'], + 'Localize': None, # Set automatically by python-gammu + 'Model': config['Model'], + } + if cfg['Model'] == 'auto': + cfg['Model'] = '' + print _('Wammu configuration:') + print '%-15s: %s' % (_('Connection'), cfg['Connection']) + print '%-15s: %s' % (_('Model'), cfg['Model']) + print '%-15s: %s' % (_('Device'), cfg['Device']) + print _('Connecting...') + sm = gammu.StateMachine() + sm.SetConfig(0, cfg) + sm.Init() + print _('Getting phone information...') + Manufacturer = sm.GetManufacturer() + Model = sm.GetModel() + IMEI = sm.GetIMEI() + Firmware = sm.GetFirmware() + print _('Phone infomation:') + print '%-15s: %s' % (_('Manufacturer'), Manufacturer) + print '%-15s: %s (%s)' % (_('Model'), Model[0], Model[1]) + print '%-15s: %s' % (_('IMEI'), IMEI) + print '%-15s: %s' % (_('Firmware'), Firmware[0]) + def parse_options(): ''' Processes program options. ''' try: opts, args = getopt.getopt(sys.argv[1:], - 'hvl', - ['help', 'version', 'local-locales']) + 'hvli', + ['help', 'version', 'local-locales', 'info']) except getopt.GetoptError, val: usage() print _('Command line parsing failed with error:') @@ -98,6 +146,9 @@ def parse_options(): if opt in ('-v', '--version'): version() sys.exit() + if opt in ('-i', '--info'): + info() + sys.exit() if __name__ == '__main__': Wammu.Locales.Init() -- 2.11.4.GIT