Adjust URLs to match new website.
[wammu.git] / wammu.py
blobd91151779384057ee05e8f5bcb810589689dbbdb
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # vim: expandtab sw=4 ts=4 sts=4:
4 '''
5 Wammu - Phone manager
6 Execution script
7 '''
8 __author__ = 'Michal Čihař'
9 __email__ = 'michal@cihar.com'
10 __license__ = '''
11 Copyright © 2003 - 2009 Michal Čihař
13 This program is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License version 2 as published by
15 the Free Software Foundation.
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 more details.
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 '''
27 import os
28 import sys
29 import getopt
30 import Wammu
31 import Wammu.Locales
33 # Try to import iconv_codec to allow working on chinese windows
34 try:
35 import iconv_codec
36 except ImportError:
37 pass
39 # Disable warning about missing files
40 # This can be caused by attempt to import Python modules, which don't
41 # have all DLLs satisfied.
42 if sys.platform.startswith('win'):
43 import win32api
44 import win32con
45 win32api.SetErrorMode(win32con.SEM_NOOPENFILEERRORBOX)
47 def version():
48 '''
49 Displays version information.
50 '''
51 print _('Wammu - Windowed Gammu version %s') % Wammu.__version__
53 def usage():
54 '''
55 Shows program usage.
56 '''
57 version()
58 print _('Usage: %s [OPTION...]' % os.path.basename(__file__))
59 print
60 print _('Options:')
61 print '%-20s ... %s' % (
62 '-h/--help',
63 _('show this help'))
64 print '%-20s ... %s' % (
65 '-v/--version',
66 _('show program version'))
67 print '%-20s ... %s' % (
68 '-l/--local-locales',
69 _('force using of locales from current directory rather than system ones'))
70 print '%-20s ... %s' % (
71 '-i/--info',
72 _('prints connection settings and tries to connect the phone'))
73 print '%-20s ... %s' % (
74 '-d/--debug',
75 _('enables debug output to stderr'))
76 print
78 def info():
79 '''
80 Displays configuration summary and tries to connect to phone.
81 '''
82 import Wammu.WammuSettings
83 import gammu
85 settings = Wammu.WammuSettings.WammuConfig()
86 section = settings.ReadInt('/Gammu/Section')
87 config = settings.gammu.GetConfig(section)
88 if config['Connection'] == '' or config['Device'] == '':
89 print _('Wammu is not configured!')
90 cfg = {
91 'StartInfo': settings.Read('/Gammu/StartInfo'),
92 'UseGlobalDebugFile': 1,
93 'DebugFile': None, # Set on other place
94 'SyncTime': settings.Read('/Gammu/SyncTime'),
95 'Connection': config['Connection'],
96 'LockDevice': settings.Read('/Gammu/LockDevice'),
97 'DebugLevel': 'textalldate', # Set on other place
98 'Device': config['Device'],
99 'Localize': None, # Set automatically by python-gammu
100 'Model': config['Model'],
102 if cfg['Model'] == 'auto':
103 cfg['Model'] = ''
104 print _('Wammu configuration:')
105 print '%-15s: %s' % (_('Connection'), cfg['Connection'])
106 print '%-15s: %s' % (_('Model'), cfg['Model'])
107 print '%-15s: %s' % (_('Device'), cfg['Device'])
108 print _('Connecting...')
109 if Wammu.debug:
110 gammu.SetDebugFile(sys.stderr)
111 gammu.SetDebugLevel('textalldate')
112 sm = gammu.StateMachine()
113 sm.SetConfig(0, cfg)
114 sm.Init()
115 print _('Getting phone information...')
116 Manufacturer = sm.GetManufacturer()
117 Model = sm.GetModel()
118 IMEI = sm.GetIMEI()
119 Firmware = sm.GetFirmware()
120 print _('Phone infomation:')
121 print '%-15s: %s' % (_('Manufacturer'), Manufacturer)
122 print '%-15s: %s (%s)' % (_('Model'), Model[0], Model[1])
123 print '%-15s: %s' % (_('IMEI'), IMEI)
124 print '%-15s: %s' % (_('Firmware'), Firmware[0])
126 def parse_options():
128 Processes program options.
130 try:
131 opts, args = getopt.getopt(sys.argv[1:],
132 'hvlid',
133 ['help', 'version', 'local-locales', 'info', 'debug'])
134 except getopt.GetoptError, val:
135 usage()
136 print _('Command line parsing failed with error:')
137 print val
138 sys.exit(2)
140 if len(args) != 0:
141 usage()
142 print _('Extra unrecognized parameters passed to program')
143 sys.exit(3)
145 do_info = False
147 for opt, dummy in opts:
148 if opt in ('-l', '--local-locales'):
149 Wammu.Locales.UseLocal()
150 print _('Using local built locales!')
151 if opt in ('-h', '--help'):
152 usage()
153 sys.exit()
154 if opt in ('-v', '--version'):
155 version()
156 sys.exit()
157 if opt in ('-i', '--info'):
158 do_info = True
159 if opt in ('-d', '--debug'):
160 Wammu.debug = True
162 if do_info:
163 info()
164 sys.exit()
166 if __name__ == '__main__':
167 Wammu.Locales.Init()
168 parse_options()
169 # need to be imported after locales are initialised
170 import Wammu.App
171 Wammu.App.Run()