allow multiple email configs, start of nicer GUI for it

This commit is contained in:
steffen123 2010-08-10 03:28:57 +02:00
parent c7e86513c7
commit 6e654e5075
4 changed files with 99 additions and 16 deletions

View File

@ -452,8 +452,8 @@ class Email:
self.fetchType = node.getAttribute("fetchType") self.fetchType = node.getAttribute("fetchType")
def __str__(self): def __str__(self):
return " host = %s\n username = %s\n password = %s\n useSsl = %s\n folder = %s\n" \ return " siteName=%s\n fetchType=%s\n host = %s\n username = %s\n password = %s\n useSsl = %s\n folder = %s\n" \
% (self.host, self.username, self.password, self.useSsl, self.folder) % (self.siteName, self.fetchType, self.host, self.username, self.password, self.useSsl, self.folder)
class HudUI: class HudUI:
def __init__(self, node): def __init__(self, node):
@ -626,6 +626,7 @@ class Config:
self.db_selected = None # database the user would like to use self.db_selected = None # database the user would like to use
self.tv = None self.tv = None
self.general = General() self.general = General()
self.emails = {}
self.gui_cash_stats = GUICashStats() self.gui_cash_stats = GUICashStats()
for gen_node in doc.getElementsByTagName("general"): for gen_node in doc.getElementsByTagName("general"):
@ -687,7 +688,8 @@ class Config:
for email_node in doc.getElementsByTagName("email"): for email_node in doc.getElementsByTagName("email"):
email = Email(node = email_node) email = Email(node = email_node)
self.email = email if email.siteName!="": #FIXME: Why on earth is this needed?
self.emails[email.siteName+"_"+email.fetchType]=email
for hui_node in doc.getElementsByTagName('hud_ui'): for hui_node in doc.getElementsByTagName('hud_ui'):
hui = HudUI(node = hui_node) hui = HudUI(node = hui_node)

78
pyfpdb/GuiImapFetcher.py Normal file
View File

@ -0,0 +1,78 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Copyright 2010 Steffen Schaumburg
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#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 Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in agpl-3.0.txt.
import threading
import pygtk
pygtk.require('2.0')
import gtk
import ImapFetcher
class GuiImapFetcher (threading.Thread):
def __init__(self, config, db, sql, mainwin, debug=True):
self.config = config
self.db = db
self.mainVBox = gtk.VBox()
self.buttonsHBox = gtk.HBox()
self.mainVBox.pack_end(self.buttonsHBox, expand=False)
label=gtk.Label("To cancel just close this tab")
self.buttonsHBox.add(label)
self.saveButton = gtk.Button("_Save Configuration")
self.saveButton.connect('clicked', self.saveClicked)
self.buttonsHBox.add(self.saveButton)
self.runAllButton = gtk.Button("_Run All")
self.runAllButton.connect('clicked', self.runAllClicked)
self.buttonsHBox.add(self.runAllButton)
self.statusLabel=gtk.Label("Please edit your config if you wish and then click Run All")
self.mainVBox.pack_end(self.statusLabel, expand=False, padding=4)
self.rowVBox = gtk.VBox()
self.mainVBox.add(self.rowVBox)
self.displayConfig()
self.mainVBox.show_all()
#end def __init__
def saveClicked(self, widget, data=None):
pass
#def saveClicked
def runAllClicked(self, widget, data=None):
self.statusLabel.set_label("Starting import. Please wait.") #FIXME: why doesnt this one show?
for email in self.config.emails:
result=ImapFetcher.run(self.config.emails[email], self.db)
self.statusLabel.set_label("Finished import without error.")
#def runAllClicked
def get_vbox(self):
"""returns the vbox of this thread"""
return self.mainVBox
#end def get_vbox
def displayConfig(self):
print self.config.emails
for email in self.config.emails:
print self.config.emails[email]
#end def displayConfig
#end class GuiImapFetcher

View File

@ -33,16 +33,16 @@ def run(config, db):
#print "start of IS.run" #print "start of IS.run"
server=None server=None
#try: #try:
#print "useSSL",config.email.useSsl,"host",config.email.host #print "useSSL",config.useSsl,"host",config.host
if config.email.useSsl: if config.useSsl:
server = IMAP4_SSL(config.email.host) server = IMAP4_SSL(config.host)
else: else:
server = IMAP4(config.email.host) server = IMAP4(config.host)
response = server.login(config.email.username, config.email.password) #TODO catch authentication error response = server.login(config.username, config.password) #TODO catch authentication error
print "response to logging in:",response print "response to logging in:",response
#print "server.list():",server.list() #prints list of folders #print "server.list():",server.list() #prints list of folders
response = server.select(config.email.folder) response = server.select(config.folder)
#print "response to selecting INBOX:",response #print "response to selecting INBOX:",response
if response[0]!="OK": if response[0]!="OK":
raise error #TODO: show error message raise error #TODO: show error message

View File

@ -103,7 +103,7 @@ import GuiPrefs
import GuiLogView import GuiLogView
#import GuiDatabase #import GuiDatabase
import GuiBulkImport import GuiBulkImport
import ImapFetcher import GuiImapFetcher
import GuiRingPlayerStats import GuiRingPlayerStats
import GuiTourneyPlayerStats import GuiTourneyPlayerStats
import GuiTourneyViewer import GuiTourneyViewer
@ -786,7 +786,7 @@ class fpdb:
<menu action="import"> <menu action="import">
<menuitem action="sethharchive"/> <menuitem action="sethharchive"/>
<menuitem action="bulkimp"/> <menuitem action="bulkimp"/>
<menuitem action="imapsummaries"/> <menuitem action="imapimport"/>
<menuitem action="autoimp"/> <menuitem action="autoimp"/>
</menu> </menu>
<menu action="viewers"> <menu action="viewers">
@ -828,7 +828,7 @@ class fpdb:
('import', None, '_Import'), ('import', None, '_Import'),
('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase), ('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase),
('bulkimp', None, '_Bulk Import', '<control>B', 'Bulk Import', self.tab_bulk_import), ('bulkimp', None, '_Bulk Import', '<control>B', 'Bulk Import', self.tab_bulk_import),
('imapsummaries', None, '_Import Tourney Summaries through eMail/IMAP', '<control>I', 'Auto Import and HUD', self.import_imap_summaries), ('imapimport', None, '_Import through eMail/IMAP', '<control>I', 'Import through eMail/IMAP', self.tab_imap_import),
('viewers', None, '_Viewers'), ('viewers', None, '_Viewers'),
('autoimp', None, '_Auto Import and HUD', '<control>A', 'Auto Import and HUD', self.tab_auto_import), ('autoimp', None, '_Auto Import and HUD', '<control>A', 'Auto Import and HUD', self.tab_auto_import),
('hudConfigurator', None, '_HUD Configurator', '<control>H', 'HUD Configurator', self.diaHudConfigurator), ('hudConfigurator', None, '_HUD Configurator', '<control>H', 'HUD Configurator', self.diaHudConfigurator),
@ -860,10 +860,6 @@ class fpdb:
return menubar return menubar
#end def get_menu #end def get_menu
def import_imap_summaries(self, widget, data=None):
result=ImapFetcher.run(self.config, self.db)
#print "import imap summaries result:", result
#end def import_imap_summaries
def load_profile(self, create_db = False): def load_profile(self, create_db = False):
"""Loads profile from the provided path name.""" """Loads profile from the provided path name."""
@ -1024,6 +1020,13 @@ class fpdb:
bulk_tab=new_import_thread.get_vbox() bulk_tab=new_import_thread.get_vbox()
self.add_and_display_tab(bulk_tab, "Bulk Import") self.add_and_display_tab(bulk_tab, "Bulk Import")
def tab_imap_import(self, widget, data=None):
new_thread = GuiImapFetcher.GuiImapFetcher(self.config, self.db, self.sql, self.window)
self.threads.append(new_thread)
tab=new_thread.get_vbox()
self.add_and_display_tab(tab, "IMAP Import")
#end def tab_import_imap_summaries
def tab_ring_player_stats(self, widget, data=None): def tab_ring_player_stats(self, widget, data=None):
new_ps_thread = GuiRingPlayerStats.GuiRingPlayerStats(self.config, self.sql, self.window) new_ps_thread = GuiRingPlayerStats.GuiRingPlayerStats(self.config, self.sql, self.window)
self.threads.append(new_ps_thread) self.threads.append(new_ps_thread)