/head: changeset 56

Integrated more functional sleep commands
This commit is contained in:
jgoerzen
2002-07-03 07:50:31 +01:00
parent fb055de114
commit 6162100487
4 changed files with 31 additions and 10 deletions

View File

@ -25,18 +25,25 @@ class TTYUI(UIBase):
if s.verbose:
UIBase.messagelistloaded(s, repos, folder, count)
def sleep(s, sleepsecs):
try:
UIBase.sleep(s, sleepsecs)
except KeyboardInterrupt:
sys.stdout.write("Timer interrupted at user request; program terminating. \n")
return 2
def sleeping(s, sleepsecs, remainingsecs):
if remainingsecs > 0:
sys.stdout.write("Next sync in %d:%02d (press Enter to sync now) \r" % \
sys.stdout.write("Next sync in %d:%02d (press Enter to sync now, Ctrl-C to abort) \r" % \
(remainingsecs / 60, remainingsecs % 60))
sys.stdout.flush()
else:
sys.stdout.write("Wait done, proceeding with sync.... \n")
sys.stdout.write("Wait done, proceeding with sync.... \n")
if sleepsecs > 0:
if len(select.select([sys.stdin], [], [], sleepsecs)[0]):
sys.stdin.readline()
return 1
return 0

View File

@ -110,6 +110,21 @@ class UIBase:
################################################## Other
def sleep(s, sleepsecs):
"""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
while sleepsecs > 0 and not abortsleep:
abortsleep = s.sleeping(1, sleepsecs)
sleepsecs -= 1
s.sleeping(0, 0) # Done sleeping.
return abortsleep
def sleeping(s, sleepsecs, remainingsecs):
"""Sleep for sleepsecs, remainingsecs to go.
If sleepsecs is 0, indicates we're done sleeping.