Skip to content

Commit

Permalink
- applied patches from the developers
Browse files Browse the repository at this point in the history
- a lot of fixes in the example programs
- fix in output handling of popen classes
- set version to 0.9.6
  • Loading branch information
Andreas Büsching committed Jul 3, 2014
1 parent d36bda9 commit ff96ff3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 17 deletions.
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2014-07-03 Andreas Büsching <crunchy@bitkipper.net>

* notifier/version.py: set version to 0.9.6

* apply patch from Jascha Geerds <geerds@univention.de>: Fix an
erroneous handling with command output. In certain cases this
could lead to the loss of some output data.

* apply patches from Philipp Hahn <hahn@univention.de>: some
little cleanup which I collected while debugging a UMC-UVMM
problem

* apply patches from SpaceOne <space@wechall.net>: code cleanup;
remove unneeded globals; fix check for None (== None → is None)
fix stopping of loop when timer returns falsy value
fix typo in example script

2012-03-31 Andreas Büsching <crunchy@bitkipper.net>

* notifier/version.py: set version to 0.9.5
Expand Down
Empty file modified examples/log.py
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions examples/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def tail_minus_f( logfile ):

if __name__ == '__main__':
notifier.init()
log = open( '/var/log/messages', 'rb' )
log.seek( os.stat( '/var/log/messages' )[ 6 ] )
filename = '/var/log/messages'
if not os.path.isfile( filename ):
filename = '/var/log/syslog'
log = open( filename, 'rb' )
log.seek( os.stat( filename )[ 6 ] )
notifier.timer_add( 100, notifier.Callback( tail_minus_f, log ) )
notifier.loop()
4 changes: 0 additions & 4 deletions examples/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def stdout( pid, line ):
output.extend( line )
if not type( line ) in ( list, tuple ):
line = [ line ]
# for l in line:
# print "(%d>1): %s" % ( pid, l )

def stderr( pid, line ):
if not type( line ) in ( list, tuple ):
Expand All @@ -50,7 +48,6 @@ def stderr( pid, line ):
def died( pid, status ):
global output, lineno
print ">>> process %d died" % pid, status
# sys.exit( status )

if not output:
print ">>> process %d produced NO output" % pid, status
Expand All @@ -63,7 +60,6 @@ def died( pid, status ):
notifier.timer_add( 100, run_ls )

def tick():
# print 'tick'
return True

def runit():
Expand Down
7 changes: 3 additions & 4 deletions examples/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ def timer_cb( a ):

def signal_cb( signal, a, b ):
print 'signal arguments', signal, a, b
# disconnect global signal
signals.disconnect( 'test-signal', signal_cb )

notifier.init( notifier.GENERIC )

signals.new( 'test-signal' )
signals.connect( 'test-signal', notifier.Callback( signal_cb, 1, 2,
'global signal' ) )
test.signal_connect( 'test-signal',notifier.Callback( signal_cb, 1, 2,
'TestSignal signal' ) )
signals.connect( 'test-signal', notifier.Callback( signal_cb, 1, 2, 'global signal' ) )
test.signal_connect( 'test-signal',notifier.Callback( signal_cb, 1, 2, 'TestSignal signal' ) )
notifier.timer_add( 2000, notifier.Callback( timer_cb, 7 ) )

notifier.loop()
2 changes: 1 addition & 1 deletion examples/test-qt-cli.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run( self ):
# print 'wake up'

def tick( self ):
print 'ticxk me'
print 'tick my thread'
return True

if __name__ == '__main__':
Expand Down
Empty file modified examples/threads3.py
100644 → 100755
Empty file.
14 changes: 10 additions & 4 deletions notifier/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def dead( self, pid, status ):
self.__dead = True
# check io handlers if there is pending output
for output in ( self.stdout, self.stderr ):
if output: output.flush_buffer()
if output:
output._handle_input(flush_partial_lines=True)
self.signal_emit( 'killed', pid, status )

def _closed( self, name ):
Expand Down Expand Up @@ -324,13 +325,13 @@ def close( self ):
self.fp.close()
self.signal_emit( 'closed', self.name )

def _handle_input( self, socket ):
def _handle_input( self, socket=None, flush_partial_lines=False ):
"""
Handle data input from socket.
"""
try:
self.fp.flush()
data = self.fp.read( 10000 )
data = self.fp.read( 65535 )
except IOError, (errno, msg):
if errno == 11:
# Resource temporarily unavailable; if we try to read on a
Expand All @@ -339,6 +340,11 @@ def _handle_input( self, socket ):
data = None

if not data:
if self.saved:
# Although socket has no data anymore, we still have data left
# over in the buffer.
self.flush_buffer()
return True
self.close()
return False

Expand All @@ -354,7 +360,7 @@ def _handle_input( self, socket ):
lines[ 0 ] = self.saved + lines[ 0 ]
self.saved = ''
# Only one partial line?
if partial_line:
if partial_line and not flush_partial_lines:
self.saved = lines[ -1 ]
del lines[ -1 ]

Expand Down
4 changes: 3 additions & 1 deletion notifier/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def signal_emit( self, signal, *args ):

def _select_signals( signals ):
global __signals
return signals is None and __signals or signals
if signals is None:
return __signals
return signals

def new( signal, signals = None ):
_signals = _select_signals( signals )
Expand Down
2 changes: 1 addition & 1 deletion notifier/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

major_number = 0
minor_number = 9
revision_number = 5
revision_number = 6
extension = ''

VERSION = "%d.%d.%d%s" % ( major_number, minor_number,
Expand Down

0 comments on commit ff96ff3

Please sign in to comment.