本文整理汇总了Python中offlineimap.ui.UIBase.setglobalui方法的典型用法代码示例。如果您正苦于以下问题:Python UIBase.setglobalui方法的具体用法?Python UIBase.setglobalui怎么用?Python UIBase.setglobalui使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类offlineimap.ui.UIBase
的用法示例。
在下文中一共展示了UIBase.setglobalui方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from offlineimap.ui import UIBase [as 别名]
# 或者: from offlineimap.ui.UIBase import setglobalui [as 别名]
def __init__(self, srcusername, srcpasswd, dstusername, dstpasswd):
try:
import fcntl
hasfcntl = 1
except:
hasfcntl = 0
lockfd = None
def lock(config, ui):
if not hasfcntl:
return
lockfd = open(self.configuration.getmetadatadir() + "/lock", "w")
try:
fcntl.flock(lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
ui.locked()
ui.terminate(1)
self.configuration = CustomConfigParser()
self.configuration.add_section('general')
self.configuration.set('general','accounts', dstusername)
self.configuration.add_section('Account ' + dstusername)
self.configuration.set('Account ' + dstusername, 'localrepository', dstusername+'_local')
self.configuration.set('Account ' + dstusername, 'remoterepository', dstusername+'_remote')
self.configuration.add_section('Repository ' + dstusername + '_local')
self.configuration.add_section('Repository ' + dstusername + '_remote')
self.configuration.set('Repository ' + dstusername + '_local', 'type', 'IMAP')
self.configuration.set('Repository ' + dstusername + '_local', 'remotehost', newserveraddr)
self.configuration.set('Repository ' + dstusername + '_local', 'remoteuser', dstusername)
self.configuration.set('Repository ' + dstusername + '_local', 'remotepass', dstpasswd)
self.configuration.set('Repository ' + dstusername + '_remote', 'type', 'IMAP')
self.configuration.set('Repository ' + dstusername + '_remote', 'remotehost', server)
self.configuration.set('Repository ' + dstusername + '_remote', 'remoteuser', srcusername)
self.configuration.set('Repository ' + dstusername + '_remote', 'remotepass', srcpasswd)
self.monothread = 0
# Setup a interface
ui = offlineimap.ui.detector.findUI(self.configuration, 'TTY.TTYUI')
UIBase.setglobalui(ui)
# ui.add_debug('imap')
# ui.add_debug('thread')
# imaplib.Debug = 5
# threading._VERBOSE = 1
lock(self.configuration, ui)
def sigterm_handler(signum, frame):
# die immediately
ui.terminate(errormsg="terminating...")
signal.signal(signal.SIGTERM,sigterm_handler)
try:
pidfd = open(config.getmetadatadir() + "/pid", "w")
pidfd.write(str(os.getpid()) + "\n")
pidfd.close()
except:
pass
try:
activeaccounts = self.configuration.get("general", "accounts")
activeaccounts = activeaccounts.replace(" ", "")
activeaccounts = activeaccounts.split(",")
allaccounts = accounts.AccountHashGenerator(self.configuration)
if self.monothread:
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
else:
threadutil.initInstanceLimit("ACCOUNTLIMIT", self.configuration.getdefaultint("general", "maxsyncaccounts", 1))
for reposname in self.configuration.getsectionlist('Repository'):
for instancename in ["FOLDER_" + reposname, "MSGCOPY_" + reposname]:
if self.monothread:
threadutil.initInstanceLimit(instancename, 1)
else:
threadutil.initInstanceLimit(instancename, self.configuration.getdefaultint('Repository ' + reposname, "maxconnections", 1))
syncaccounts = []
for account in activeaccounts:
if account not in syncaccounts:
syncaccounts.append(account)
siglisteners = []
def sig_handler(signum, frame):
if signum == signal.SIGUSR1:
# tell each account to do a full sync asap
signum = (1,)
elif signum == signal.SIGHUP:
# tell each account to die asap
signum = (2,)
elif signum == signal.SIGUSR2:
# tell each account to do a full sync asap, then die
signum = (1, 2)
#.........这里部分代码省略.........
示例2: startup
# 需要导入模块: from offlineimap.ui import UIBase [as 别名]
# 或者: from offlineimap.ui.UIBase import setglobalui [as 别名]
def startup(versionno):
assert versionno == version.versionstr, "Revision of main program (%s) does not match that of library (%s). Please double-check your PYTHONPATH and installation locations." % (versionno, version.versionstr)
options = {}
if '--help' in sys.argv[1:]:
sys.stdout.write(version.getcmdhelp() + "\n")
sys.exit(0)
for optlist in getopt(sys.argv[1:], 'P:1oqa:c:d:l:u:hk:f:')[0]:
options[optlist[0]] = optlist[1]
if options.has_key('-h'):
sys.stdout.write(version.getcmdhelp())
sys.stdout.write("\n")
sys.exit(0)
configfilename = os.path.expanduser("~/.offlineimaprc")
if options.has_key('-c'):
configfilename = options['-c']
if options.has_key('-P'):
if not options.has_key('-1'):
sys.stderr.write("FATAL: profile mode REQUIRES -1\n")
sys.exit(100)
profiledir = options['-P']
os.mkdir(profiledir)
threadutil.setprofiledir(profiledir)
sys.stderr.write("WARNING: profile mode engaged;\nPotentially large data will be created in " + profiledir + "\n")
config = CustomConfigParser()
if not os.path.exists(configfilename):
sys.stderr.write(" *** Config file %s does not exist; aborting!\n" % configfilename)
sys.exit(1)
config.read(configfilename)
# override config values with option '-k'
for option in options.keys():
if option == '-k':
(key, value) = options['-k'].split('=', 1)
if ':' in key:
(secname, key) = key.split(':', 1)
section = secname.replace("_", " ")
else:
section = "general"
config.set(section, key, value)
ui = offlineimap.ui.detector.findUI(config, options.get('-u'))
UIBase.setglobalui(ui)
if options.has_key('-l'):
ui.setlogfd(open(options['-l'], 'wt'))
ui.init_banner()
if options.has_key('-d'):
for debugtype in options['-d'].split(','):
ui.add_debug(debugtype.strip())
if debugtype == 'imap':
imaplib.Debug = 5
if debugtype == 'thread':
threading._VERBOSE = 1
if options.has_key('-o'):
# FIXME: maybe need a better
for section in accounts.getaccountlist(config):
config.remove_option('Account ' + section, "autorefresh")
if options.has_key('-q'):
for section in accounts.getaccountlist(config):
config.set('Account ' + section, "quick", '-1')
if options.has_key('-f'):
foldernames = options['-f'].replace(" ", "").split(",")
folderfilter = "lambda f: f in %s" % foldernames
folderincludes = "[]"
for accountname in accounts.getaccountlist(config):
account_section = 'Account ' + accountname
remote_repo_section = 'Repository ' + \
config.get(account_section, 'remoterepository')
local_repo_section = 'Repository ' + \
config.get(account_section, 'localrepository')
for section in [remote_repo_section, local_repo_section]:
config.set(section, "folderfilter", folderfilter)
config.set(section, "folderincludes", folderincludes)
lock(config, ui)
def sigterm_handler(signum, frame):
# die immediately
ui.terminate(errormsg="terminating...")
signal.signal(signal.SIGTERM,sigterm_handler)
try:
pidfd = open(config.getmetadatadir() + "/pid", "w")
pidfd.write(str(os.getpid()) + "\n")
pidfd.close()
except:
pass
try:
if options.has_key('-l'):
sys.stderr = ui.logfile
#.........这里部分代码省略.........