/usr/share/pyshared/Wammu/Logger.py is in wammu 0.36-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | # -*- coding: UTF-8 -*-
# vim: expandtab sw=4 ts=4 sts=4:
'''
Wammu - Phone manager
Logging window and thread for log reading
'''
__author__ = 'Michal Čihař'
__email__ = 'michal@cihar.com'
__license__ = '''
Copyright © 2003 - 2010 Michal Čihař
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.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
'''
import threading
import wx
import os
import sys
import time
import Wammu.Events
class LoggerDebug(threading.Thread):
'''
Thread which reads defined files and prints it to stderr.
'''
def __init__(self, filename):
'''
Initializes reader on filename, text will be printed to stderr.
'''
threading.Thread.__init__(self)
self.file_descriptor = open(filename, 'r')
self.filename = filename
self.canceled = False
def run(self):
"""
This is basically tail -f reimplementation
"""
while not self.canceled:
where = self.file_descriptor.tell()
txt = self.file_descriptor.readlines()
if len(txt) == 0:
fd_results = os.fstat(self.file_descriptor.fileno())
try:
st_results = os.stat(self.filename)
except OSError:
st_results = fd_results
if st_results[1] == fd_results[1] or sys.platform == 'win32':
time.sleep(1)
self.file_descriptor.seek(where)
else:
self.file_descriptor = open(self.filename, 'r')
else:
sys.stderr.write(''.join(txt))
self.file_descriptor.close()
class Logger(threading.Thread):
'''
Thread which reads defined files and posts events on change.
'''
def __init__(self, win, filename):
'''
Initializes reader on filename, events will be sent to win.
'''
threading.Thread.__init__(self)
self.win = win
self.file_descriptor = open(filename, 'r')
self.filename = filename
self.canceled = False
def run(self):
"""
This is basically tail -f reimplementation
"""
while not self.canceled:
where = self.file_descriptor.tell()
txt = self.file_descriptor.readlines()
if len(txt) == 0:
fd_results = os.fstat(self.file_descriptor.fileno())
try:
st_results = os.stat(self.filename)
except OSError:
st_results = fd_results
if st_results[1] == fd_results[1] or sys.platform == 'win32':
time.sleep(1)
self.file_descriptor.seek(where)
else:
self.file_descriptor = open(self.filename, 'r')
else:
evt = Wammu.Events.LogEvent(txt = ''.join(txt))
wx.PostEvent(self.win, evt)
self.file_descriptor.close()
class LogFrame(wx.Frame):
'''
Window with debug log.
'''
def __init__(self, parent, cfg):
'''
Creates window and initializes event handlers.
'''
self.cfg = cfg
if cfg.HasEntry('/Debug/X') and cfg.HasEntry('/Debug/Y'):
pos = wx.Point(
cfg.ReadInt('/Debug/X'),
cfg.ReadInt('/Debug/Y'))
else:
pos = wx.DefaultPosition
size = wx.Size(
cfg.ReadInt('/Debug/Width'),
cfg.ReadInt('/Debug/Height'))
wx.Frame.__init__(
self,
parent,
-1,
_('Wammu debug log'),
pos,
size,
wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER)
self.txt = wx.TextCtrl(
self,
-1,
_('Here will appear debug messages from Gammu...\n'),
style = wx.TE_MULTILINE | wx.TE_READONLY)
self.txt.SetFont(wx.Font(9, wx.MODERN, wx.NORMAL, wx.NORMAL))
Wammu.Events.EVT_LOG(self, self.OnLog)
wx.EVT_SIZE(self, self.OnSize)
self.OnSize(None)
def OnLog(self, evt):
'''
Event handler for text events from Logger.
'''
self.txt.AppendText(evt.txt)
def OnSize(self, evt):
'''
Resize handler to correctly resize text area.
'''
width, height = self.GetClientSizeTuple()
self.txt.SetDimensions(0, 0, width, height)
|