Translated using Weblate.
[wammu.git] / Wammu / ErrorLog.py
blob1f739334495de6a24a4a89e9b58f507fc3f6b184
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Error log handling
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import Wammu
27 import tempfile
28 import wx
29 import sys
30 import os
31 import locale
32 if Wammu.gammu_error == None:
33 import gammu
35 # set later in Wammu.Main to have correct debug filename
36 DEBUG_LOG_FILENAME = None
38 # Template for system information
39 SYSTEM_TEMPLATE = """
40 --------------- System information ----------------
41 Platform %s
42 Python %s
43 wxPython %s
44 Wammu %s
45 python-gammu %s
46 Gammu %s
47 Bluetooth %s
48 locales %s (%s)
49 """
51 def GetSystemInfo():
52 """
53 Returns system information in text form.
54 """
55 pyver = sys.version.split()[0]
56 wxver = wx.VERSION_STRING
57 wammuver = Wammu.__version__
58 try:
59 (gammuver, pgammuver) = gammu.Version()
60 except:
61 try:
62 (gammuver, pgammuver, ignore) = gammu.Version()
63 except:
64 (gammuver, pgammuver) = ('Unknown', 'Unknown')
65 (loc, charset) = locale.getdefaultlocale()
66 bluez = 'None'
67 try:
68 import bluetooth
69 bluez = 'PyBluez'
70 except ImportError:
71 pass
73 result = SYSTEM_TEMPLATE % (
74 sys.platform,
75 pyver,
76 wxver,
77 wammuver,
78 pgammuver,
79 gammuver,
80 bluez,
81 loc,
82 charset)
84 if Wammu.configuration is not None:
85 section = Wammu.configuration.ReadInt('/Gammu/Section')
86 config = Wammu.configuration.gammu.GetConfig(section)
87 result += 'connection %s\n' % config['Connection']
88 result += 'device %s\n' % config['Device']
89 result += 'model %s\n' % config['Model']
90 return result
92 def SaveLog(outf = None, filename = None):
93 """
94 Saves debug log to filename or handle. If none specified
95 """
96 if DEBUG_LOG_FILENAME is None:
97 return None, None
98 if outf is None:
99 if filename is None:
100 handle, name = tempfile.mkstemp('.log', 'wammu-crash-')
101 outf = os.fdopen(handle, 'w+')
102 else:
103 name = filename
104 outf = open(filename, 'w+')
106 inf = open(DEBUG_LOG_FILENAME, 'r')
107 outf.write(GetSystemInfo())
108 outf.write(inf.read())
109 inf.close()
110 if filename is not None:
111 outf.close()
112 return outf, name