From 6e654e5075a0cf8b6d6414725b50ae36fbb79e0f Mon Sep 17 00:00:00 2001 From: steffen123 Date: Tue, 10 Aug 2010 03:28:57 +0200 Subject: [PATCH] allow multiple email configs, start of nicer GUI for it --- pyfpdb/Configuration.py | 8 +++-- pyfpdb/GuiImapFetcher.py | 78 ++++++++++++++++++++++++++++++++++++++++ pyfpdb/ImapFetcher.py | 12 +++---- pyfpdb/fpdb.pyw | 17 +++++---- 4 files changed, 99 insertions(+), 16 deletions(-) create mode 100644 pyfpdb/GuiImapFetcher.py diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 7c8f1fba..24f1dcd4 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -452,8 +452,8 @@ class Email: self.fetchType = node.getAttribute("fetchType") def __str__(self): - return " 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) + return " siteName=%s\n fetchType=%s\n host = %s\n username = %s\n password = %s\n useSsl = %s\n folder = %s\n" \ + % (self.siteName, self.fetchType, self.host, self.username, self.password, self.useSsl, self.folder) class HudUI: def __init__(self, node): @@ -626,6 +626,7 @@ class Config: self.db_selected = None # database the user would like to use self.tv = None self.general = General() + self.emails = {} self.gui_cash_stats = GUICashStats() for gen_node in doc.getElementsByTagName("general"): @@ -687,7 +688,8 @@ class Config: for email_node in doc.getElementsByTagName("email"): 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'): hui = HudUI(node = hui_node) diff --git a/pyfpdb/GuiImapFetcher.py b/pyfpdb/GuiImapFetcher.py new file mode 100644 index 00000000..d8e4d18e --- /dev/null +++ b/pyfpdb/GuiImapFetcher.py @@ -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 . +#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 diff --git a/pyfpdb/ImapFetcher.py b/pyfpdb/ImapFetcher.py index da13698c..97dbf3de 100755 --- a/pyfpdb/ImapFetcher.py +++ b/pyfpdb/ImapFetcher.py @@ -33,16 +33,16 @@ def run(config, db): #print "start of IS.run" server=None #try: - #print "useSSL",config.email.useSsl,"host",config.email.host - if config.email.useSsl: - server = IMAP4_SSL(config.email.host) + #print "useSSL",config.useSsl,"host",config.host + if config.useSsl: + server = IMAP4_SSL(config.host) else: - server = IMAP4(config.email.host) - response = server.login(config.email.username, config.email.password) #TODO catch authentication error + server = IMAP4(config.host) + response = server.login(config.username, config.password) #TODO catch authentication error print "response to logging in:",response #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 if response[0]!="OK": raise error #TODO: show error message diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 75faebf2..8553ee72 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -103,7 +103,7 @@ import GuiPrefs import GuiLogView #import GuiDatabase import GuiBulkImport -import ImapFetcher +import GuiImapFetcher import GuiRingPlayerStats import GuiTourneyPlayerStats import GuiTourneyViewer @@ -786,7 +786,7 @@ class fpdb: - + @@ -828,7 +828,7 @@ class fpdb: ('import', None, '_Import'), ('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase), ('bulkimp', None, '_Bulk Import', 'B', 'Bulk Import', self.tab_bulk_import), - ('imapsummaries', None, '_Import Tourney Summaries through eMail/IMAP', 'I', 'Auto Import and HUD', self.import_imap_summaries), + ('imapimport', None, '_Import through eMail/IMAP', 'I', 'Import through eMail/IMAP', self.tab_imap_import), ('viewers', None, '_Viewers'), ('autoimp', None, '_Auto Import and HUD', 'A', 'Auto Import and HUD', self.tab_auto_import), ('hudConfigurator', None, '_HUD Configurator', 'H', 'HUD Configurator', self.diaHudConfigurator), @@ -860,10 +860,6 @@ class fpdb: return menubar #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): """Loads profile from the provided path name.""" @@ -1024,6 +1020,13 @@ class fpdb: bulk_tab=new_import_thread.get_vbox() 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): new_ps_thread = GuiRingPlayerStats.GuiRingPlayerStats(self.config, self.sql, self.window) self.threads.append(new_ps_thread)