From 61621004878614466bb962941c7634472585d6da Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Wed, 3 Jul 2002 07:50:31 +0100 Subject: [PATCH] /head: changeset 56 Integrated more functional sleep commands --- head/debian/changelog | 2 ++ head/offlineimap.py | 11 ++++------- head/offlineimap/ui/TTY.py | 13 ++++++++++--- head/offlineimap/ui/UIBase.py | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/head/debian/changelog b/head/debian/changelog index 60ccc0f..c494bc5 100644 --- a/head/debian/changelog +++ b/head/debian/changelog @@ -2,6 +2,8 @@ offlineimap (1.0.4) unstable; urgency=low * Deletion of more than one message has been optimized. This could make deleting large numbers of messages far faster. + * Moved more sleep code into ui layer. Fancier sleep actions are now + possible. -- John Goerzen Tue, 2 Jul 2002 14:16:04 -0500 diff --git a/head/offlineimap.py b/head/offlineimap.py index 8b682b1..6b63b18 100644 --- a/head/offlineimap.py +++ b/head/offlineimap.py @@ -135,11 +135,8 @@ syncitall() if config.has_option('general', 'autorefresh'): refreshperiod = config.getint('general', 'autorefresh') * 60 while 1: - sleepamount = refreshperiod - abortsleep = 0 - while sleepamount > 0 and not abortsleep: - abortsleep = ui.sleeping(1, sleepamount) - sleepamount -= 1 - ui.sleeping(0, 0) # Done sleeping. - syncitall() + if ui.sleep(refreshperiod) == 2: + break + else: + syncitall() diff --git a/head/offlineimap/ui/TTY.py b/head/offlineimap/ui/TTY.py index e69f8fc..ce934d2 100644 --- a/head/offlineimap/ui/TTY.py +++ b/head/offlineimap/ui/TTY.py @@ -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 - + diff --git a/head/offlineimap/ui/UIBase.py b/head/offlineimap/ui/UIBase.py index cf56a59..76559ce 100644 --- a/head/offlineimap/ui/UIBase.py +++ b/head/offlineimap/ui/UIBase.py @@ -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.