]>
code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/ui/TTY.py
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 from UIBase
import UIBase
19 from getpass
import getpass
21 from threading
import *
24 def __init__(s
, config
, verbose
= 0):
25 UIBase
.__init
__(s
, config
, verbose
)
30 return sys
.stdout
.isatty() and sys
.stdin
.isatty()
33 s
.outputlock
.acquire()
35 if (currentThread().getName() == 'MainThread'):
38 print "%s:\n %s" % (currentThread().getName(), msg
)
41 s
.outputlock
.release()
43 def getpass(s
, accountname
, config
, errmsg
= None):
45 s
._msg
("%s: %s" % (accountname
, errmsg
))
46 s
.outputlock
.acquire()
48 return getpass("%s: Enter password for %s on %s: " %
49 (accountname
, config
.get(accountname
, "remoteuser"),
50 config
.get(accountname
, "remotehost")))
52 s
.outputlock
.release()
55 if isinstance(sys
.exc_info()[1], KeyboardInterrupt) and \
57 sys
.stdout
.write("Timer interrupted at user request; program terminating. \n")
60 UIBase
.mainException(s
)