2002-07-11 07:38:14 +02:00
|
|
|
# TTY UI
|
|
|
|
# Copyright (C) 2002 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2002-06-21 07:42:39 +02:00
|
|
|
from UIBase import UIBase
|
2002-06-21 07:29:12 +02:00
|
|
|
from getpass import getpass
|
2002-06-21 09:25:24 +02:00
|
|
|
import select, sys
|
2002-07-05 04:34:39 +02:00
|
|
|
from threading import *
|
2002-06-21 07:29:12 +02:00
|
|
|
|
2002-06-21 07:42:39 +02:00
|
|
|
class TTYUI(UIBase):
|
|
|
|
def __init__(self, verbose = 0):
|
|
|
|
self.verbose = 0
|
2002-07-05 04:34:39 +02:00
|
|
|
self.iswaiting = 0
|
2002-06-21 07:42:39 +02:00
|
|
|
|
2002-06-21 07:29:12 +02:00
|
|
|
def _msg(s, msg):
|
2002-07-12 02:48:45 +02:00
|
|
|
if currentThread().getName() == 'MainThread':
|
|
|
|
print msg
|
|
|
|
else:
|
|
|
|
print "%-30s %s" % (currentThread().getName(), msg)
|
2002-07-04 04:14:07 +02:00
|
|
|
sys.stdout.flush()
|
2002-06-21 07:29:12 +02:00
|
|
|
|
2002-07-04 02:02:10 +02:00
|
|
|
def getpass(s, accountname, config):
|
2002-06-21 07:42:39 +02:00
|
|
|
return getpass("%s: Enter password for %s on %s: " %
|
2002-07-04 02:02:10 +02:00
|
|
|
(accountname, config.get(accountname, "remoteuser"),
|
|
|
|
config.get(accountname, "remotehost")))
|
2002-06-21 07:42:39 +02:00
|
|
|
|
|
|
|
def syncingmessages(s, sr, sf, dr, df):
|
|
|
|
if s.verbose:
|
|
|
|
UIBase.syncingmessages(s, sr, sf, dr, df)
|
|
|
|
|
|
|
|
def loadmessagelist(s, repos, folder):
|
|
|
|
if s.verbose:
|
|
|
|
UIBase.syncingmessages(s, repos, folder)
|
2002-06-21 07:29:12 +02:00
|
|
|
|
2002-06-21 07:42:39 +02:00
|
|
|
def messagelistloaded(s, repos, folder, count):
|
|
|
|
if s.verbose:
|
|
|
|
UIBase.messagelistloaded(s, repos, folder, count)
|
2002-06-21 09:25:24 +02:00
|
|
|
|
2002-07-03 08:50:31 +02:00
|
|
|
def sleep(s, sleepsecs):
|
2002-07-05 04:34:39 +02:00
|
|
|
s.iswaiting = 1
|
2002-07-03 08:50:31 +02:00
|
|
|
try:
|
|
|
|
UIBase.sleep(s, sleepsecs)
|
2002-07-05 04:34:39 +02:00
|
|
|
finally:
|
|
|
|
s.iswaiting = 0
|
|
|
|
|
|
|
|
def mainException(s):
|
|
|
|
if isinstance(sys.exc_info()[1], KeyboardInterrupt) and \
|
|
|
|
s.iswaiting:
|
2002-07-03 08:50:31 +02:00
|
|
|
sys.stdout.write("Timer interrupted at user request; program terminating. \n")
|
2002-07-05 04:34:39 +02:00
|
|
|
s.terminate()
|
|
|
|
else:
|
|
|
|
UIBase.mainException(s)
|
2002-07-03 08:50:31 +02:00
|
|
|
|
2002-06-21 09:25:24 +02:00
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
|
|
|
if remainingsecs > 0:
|
2002-07-03 08:50:31 +02:00
|
|
|
sys.stdout.write("Next sync in %d:%02d (press Enter to sync now, Ctrl-C to abort) \r" % \
|
2002-06-21 09:25:24 +02:00
|
|
|
(remainingsecs / 60, remainingsecs % 60))
|
|
|
|
sys.stdout.flush()
|
|
|
|
else:
|
2002-07-03 08:50:31 +02:00
|
|
|
sys.stdout.write("Wait done, proceeding with sync.... \n")
|
2002-06-21 09:25:24 +02:00
|
|
|
|
|
|
|
if sleepsecs > 0:
|
|
|
|
if len(select.select([sys.stdin], [], [], sleepsecs)[0]):
|
2002-06-21 11:55:23 +02:00
|
|
|
sys.stdin.readline()
|
2002-06-21 09:25:24 +02:00
|
|
|
return 1
|
|
|
|
return 0
|
2002-07-03 08:50:31 +02:00
|
|
|
|
2002-06-21 09:25:24 +02:00
|
|
|
|