]>
code.delx.au - offlineimap/blob - offlineimap/ui/Machine.py
d02bbbc173804ea7cb654eaa5a8a713e201ba9f1
1 # Copyright (C) 2007 John Goerzen
2 # <jgoerzen@complete.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 import offlineimap
.version
19 import urllib
, sys
, re
, time
, traceback
, threading
, thread
20 from UIBase
import UIBase
21 from threading
import *
25 class MachineUI(UIBase
):
26 def __init__(s
, config
, verbose
= 0):
27 UIBase
.__init
__(s
, config
, verbose
)
28 s
.safechars
=" ;,./-_=+()[]"
31 s
._printData
('__init__', protocol
)
36 def _printData(s
, command
, data
, dolock
= True):
37 s
._printDataOut
('msg', command
, data
, dolock
)
39 def _printWarn(s
, command
, data
, dolock
= True):
40 s
._printDataOut
('warn', command
, data
, dolock
)
42 def _printDataOut(s
, datatype
, command
, data
, dolock
= True):
44 s
.outputlock
.acquire()
46 print "%s:%s:%s:%s" % \
48 urllib
.quote(command
, s
.safechars
),
49 urllib
.quote(currentThread().getName(), s
.safechars
),
50 urllib
.quote(data
, s
.safechars
))
54 s
.outputlock
.release()
57 s
._printData
('_display', msg
)
59 def warn(s
, msg
, minor
):
60 s
._printData
('warn', '%s\n%d' % (msg
, int(minor
)))
62 def registerthread(s
, account
):
63 UIBase
.registerthread(s
, account
)
64 s
._printData
('registerthread', account
)
66 def unregisterthread(s
, thread
):
67 UIBase
.unregisterthread(s
, thread
)
68 s
._printData
('unregisterthread', thread
.getName())
70 def debugging(s
, debugtype
):
71 s
._printData
('debugging', debugtype
)
73 def acct(s
, accountname
):
74 s
._printData
('acct', accountname
)
76 def acctdone(s
, accountname
):
77 s
._printData
('acctdone', accountname
)
79 def validityproblem(s
, folder
):
80 s
._printData
('validityproblem', "%s\n%s\n%s\n%s" % \
81 (folder
.getname(), folder
.getrepository().getname(),
82 folder
.getsaveduidvalidity(), folder
.getuidvalidity()))
84 def connecting(s
, hostname
, port
):
85 s
._printData
('connecting', "%s\n%s" % (hostname
, str(port
)))
87 def syncfolders(s
, srcrepos
, destrepos
):
88 s
._printData
('syncfolders', "%s\n%s" % (s
.getnicename(srcrepos
),
89 s
.getnicename(destrepos
)))
91 def syncingfolder(s
, srcrepos
, srcfolder
, destrepos
, destfolder
):
92 s
._printData
('syncingfolder', "%s\n%s\n%s\n%s\n" % \
93 (s
.getnicename(srcrepos
), srcfolder
.getname(),
94 s
.getnicename(destrepos
), destfolder
.getname()))
96 def loadmessagelist(s
, repos
, folder
):
97 s
._printData
('loadmessagelist', "%s\n%s" % (s
.getnicename(repos
),
98 folder
.getvisiblename()))
100 def messagelistloaded(s
, repos
, folder
, count
):
101 s
._printData
('messagelistloaded', "%s\n%s\n%d" % \
102 (s
.getnicename(repos
), folder
.getname(), count
))
104 def syncingmessages(s
, sr
, sf
, dr
, df
):
105 s
._printData
('syncingmessages', "%s\n%s\n%s\n%s\n" % \
106 (s
.getnicename(sr
), sf
.getname(), s
.getnicename(dr
),
109 def copyingmessage(s
, uid
, src
, destlist
):
110 ds
= s
.folderlist(destlist
)
111 s
._printData
('copyingmessage', "%d\n%s\n%s\n%s" % \
112 (uid
, s
.getnicename(src
), src
.getname(), ds
))
114 def folderlist(s
, list):
115 return ("\f".join(["%s\t%s" % (s
.getnicename(x
), x
.getname()) for x
in list]))
117 def deletingmessage(s
, uid
, destlist
):
118 s
.deletingmessages(s
, [uid
], destlist
)
120 def uidlist(s
, list):
121 return ("\f".join([str(u
) for u
in list]))
123 def deletingmessages(s
, uidlist
, destlist
):
124 ds
= s
.folderlist(destlist
)
125 s
._printData
('deletingmessages', "%s\n%s" % (s
.uidlist(uidlist
), ds
))
127 def addingflags(s
, uidlist
, flags
, destlist
):
128 ds
= s
.folderlist(destlist
)
129 s
._printData
("addingflags", "%s\n%s\n%s" % (s
.uidlist(uidlist
),
133 def deletingflags(s
, uidlist
, flags
, destlist
):
134 ds
= s
.folderlist(destlist
)
135 s
._printData
('deletingflags', "%s\n%s\n%s" % (s
.uidlist(uidlist
),
139 def threadException(s
, thread
):
140 print s
.getThreadExceptionString(thread
)
141 s
._printData
('threadException', "%s\n%s" % \
142 (thread
.getName(), s
.getThreadExceptionString(thread
)))
143 s
.delThreadDebugLog(thread
)
146 def terminate(s
, exitstatus
= 0, errortitle
= '', errormsg
= ''):
147 s
._printData
('terminate', "%d\n%s\n%s" % (exitstatus
, errortitle
, errormsg
))
150 def mainException(s
):
151 s
._printData
('mainException', s
.getMainExceptionString())
153 def threadExited(s
, thread
):
154 s
._printData
('threadExited', thread
.getName())
155 UIBase
.threadExited(s
, thread
)
157 def sleeping(s
, sleepsecs
, remainingsecs
):
158 s
._printData
('sleeping', "%d\n%d" % (sleepsecs
, remainingsecs
))
160 time
.sleep(sleepsecs
)
164 def getpass(s
, accountname
, config
, errmsg
= None):
165 s
.outputlock
.acquire()
168 s
._printData
('getpasserror', "%s\n%s" % (accountname
, errmsg
),
170 s
._printData
('getpass', accountname
, False)
171 return (sys
.stdin
.readline()[:-1])
173 s
.outputlock
.release()
176 s
._printData
('initbanner', offlineimap
.version
.banner
)