Remove weird SigListener class
The SigListener class was used to queue folders that we need to sync and to receive "resync" and "abort" signals. It was undocumented and weird and we had to pass "siglisteners" through the whole program. Simply do away with it, and make 2 functions in the Account() class: set_abort_event and get_abort_event which can be used to set and check for such signals. This way we do not need to pass siglisteners all over the place. Tested Blinkenlights and TTYUI uis to make sure that SIGUSR1 and SIGUSR2 actually still work. Document those signals in MANUAL.rst. They were completly undocumented. This simplifies the code and interdependencies by passing less stuff around. Removes an undocumented and weirdly named class. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:

committed by
Nicolas Sebrecht

parent
ac27c93c83
commit
89619838b0
@ -132,10 +132,10 @@ class BlinkenBase:
|
||||
s.gettf().setcolor('white')
|
||||
s.__class__.__bases__[-1].callhook(s, msg)
|
||||
|
||||
def sleep(s, sleepsecs, siglistener):
|
||||
def sleep(s, sleepsecs, account):
|
||||
s.gettf().setcolor('red')
|
||||
s.getaccountframe().startsleep(sleepsecs)
|
||||
return UIBase.sleep(s, sleepsecs, siglistener)
|
||||
return UIBase.sleep(s, sleepsecs, account)
|
||||
|
||||
def sleeping(s, sleepsecs, remainingsecs):
|
||||
if remainingsecs and s.gettf().getcolor() == 'black':
|
||||
|
@ -557,10 +557,10 @@ class Blinkenlights(BlinkenBase, UIBase):
|
||||
s.c.stop()
|
||||
UIBase.mainException(s)
|
||||
|
||||
def sleep(s, sleepsecs, siglistener):
|
||||
def sleep(s, sleepsecs, account):
|
||||
s.gettf().setcolor('red')
|
||||
s._msg("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60))
|
||||
return BlinkenBase.sleep(s, sleepsecs, siglistener)
|
||||
return BlinkenBase.sleep(s, sleepsecs, account)
|
||||
|
||||
if __name__ == '__main__':
|
||||
x = Blinkenlights(None)
|
||||
|
@ -342,24 +342,22 @@ class UIBase:
|
||||
|
||||
################################################## Other
|
||||
|
||||
def sleep(s, sleepsecs, siglistener):
|
||||
def sleep(s, sleepsecs, account):
|
||||
"""This function does not actually output anything, but handles
|
||||
the overall sleep, dealing with updates as necessary. It will,
|
||||
however, call sleeping() which DOES output something.
|
||||
|
||||
Returns 0 if timeout expired, 1 if there is a request to cancel
|
||||
the timer, and 2 if there is a request to abort the program."""
|
||||
|
||||
abortsleep = 0
|
||||
:returns: 0/False if timeout expired, 1/2/True if there is a
|
||||
request to cancel the timer.
|
||||
"""
|
||||
abortsleep = False
|
||||
while sleepsecs > 0 and not abortsleep:
|
||||
try:
|
||||
abortsleep = siglistener.get_nowait()
|
||||
# retrieved signal while sleeping: 1 means immediately resynch, 2 means immediately die
|
||||
except Empty:
|
||||
# no signal
|
||||
if account.get_abort_event():
|
||||
abortsleep = True
|
||||
else:
|
||||
abortsleep = s.sleeping(10, sleepsecs)
|
||||
sleepsecs -= 10
|
||||
s.sleeping(0, 0) # Done sleeping.
|
||||
sleepsecs -= 10
|
||||
s.sleeping(0, 0) # Done sleeping.
|
||||
return abortsleep
|
||||
|
||||
def sleeping(s, sleepsecs, remainingsecs):
|
||||
|
Reference in New Issue
Block a user