From 09f3205e770c23dfb647b1c796f98bd3d36cbf4f Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sun, 22 Aug 2010 01:30:33 +0200 Subject: [PATCH] update email config section as discussed on ML --- pyfpdb/Configuration.py | 46 +++++++++-------- pyfpdb/GuiImapFetcher.py | 94 +++++++++++++++++------------------ pyfpdb/HUD_config.xml.example | 5 +- 3 files changed, 72 insertions(+), 73 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 29b74b54..7e49d12d 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -256,6 +256,20 @@ class Layout: return temp + "\n" +class Email: + def __init__(self, node): + self.node = node + self.host= node.getAttribute("host") + self.username = node.getAttribute("username") + self.password = node.getAttribute("password") + self.useSsl = node.getAttribute("useSsl") + self.folder = node.getAttribute("folder") + self.fetchType = node.getAttribute("fetchType") + + def __str__(self): + return " fetchType=%s\n host = %s\n username = %s\n password = %s\n useSsl = %s\n folder = %s\n" \ + % (self.fetchType, self.host, self.username, self.password, self.useSsl, self.folder) + class Site: def __init__(self, node): def normalizePath(path): @@ -284,12 +298,17 @@ class Site: self.xshift = node.getAttribute("xshift") self.yshift = node.getAttribute("yshift") self.layout = {} + self.emails = {} print _("Loading site"), self.site_name for layout_node in node.getElementsByTagName('layout'): lo = Layout(layout_node) self.layout[lo.max] = lo + + for email_node in node.getElementsByTagName('email'): + email = Email(email_node) + self.emails[email.fetchType] = email # Site defaults self.xpad = 1 if self.xpad == "" else int(self.xpad) @@ -467,21 +486,6 @@ class Import: return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \ % (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.fastStoreHudCache) -class Email: - def __init__(self, node): - self.node = node - self.host= node.getAttribute("host") - self.username = node.getAttribute("username") - self.password = node.getAttribute("password") - self.useSsl = node.getAttribute("useSsl") - self.folder = node.getAttribute("folder") - self.siteName = node.getAttribute("siteName") - self.fetchType = node.getAttribute("fetchType") - - def __str__(self): - 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): self.node = node @@ -716,11 +720,6 @@ class Config: imp = Import(node = imp_node) self.imp = imp - for email_node in doc.getElementsByTagName("email"): - email = Email(node = email_node) - 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) self.ui = hui @@ -767,9 +766,12 @@ class Config: return site_node def getEmailNode(self, siteName, fetchType): - for emailNode in self.doc.getElementsByTagName("email"): - if emailNode.getAttribute("siteName") == siteName and emailNode.getAttribute("fetchType") == fetchType: + siteNode = self.get_site_node(siteName) + for emailNode in siteNode.getElementsByTagName("email"): + if emailNode.getAttribute("fetchType") == fetchType: + print "found emailNode" return emailNode + break #end def getEmailNode def getGameNode(self,gameName): diff --git a/pyfpdb/GuiImapFetcher.py b/pyfpdb/GuiImapFetcher.py index b9391daa..7294086a 100644 --- a/pyfpdb/GuiImapFetcher.py +++ b/pyfpdb/GuiImapFetcher.py @@ -72,19 +72,14 @@ class GuiImapFetcher (threading.Thread): siteName=columns[0].get_text() fetchType=columns[1].get_text() - code=siteName+"_"+fetchType - for email in self.config.emails: - toSave=self.config.emails[email] - break - toSave.siteName=siteName - toSave.fetchType=fetchType + toSave=self.config.supported_sites[siteName].emails[fetchType] toSave.host=columns[2].get_text() toSave.username=columns[3].get_text() if columns[4].get_text()=="***": - toSave.password=self.passwords[code] + toSave.password=self.passwords[siteName+fetchType] else: toSave.password=columns[4].get_text() @@ -101,16 +96,17 @@ class GuiImapFetcher (threading.Thread): def importAllClicked(self, widget, data=None): self.statusLabel.set_label(_("Starting import. Please wait.")) #FIXME: why doesnt this one show? - for email in self.config.emails: - try: - result=ImapFetcher.run(self.config.emails[email], self.db) - self.statusLabel.set_label(_("Finished import without error.")) - except IMAP4.error as error: - if str(error)=="[AUTHENTICATIONFAILED] Authentication failed.": - self.statusLabel.set_label(_("Login to mailserver failed: please check mailserver, username and password")) - except gaierror as error: - if str(error)=="[Errno -2] Name or service not known": - self.statusLabel.set_label(_("Could not connect to mailserver: check mailserver and use SSL settings and internet connectivity")) + for siteName in self.config.supported_sites: + for fetchType in self.config.supported_sites[siteName].emails: + try: + result=ImapFetcher.run(self.config.supported_sites[siteName].emails[fetchType], self.db) + self.statusLabel.set_label(_("Finished import without error.")) + except IMAP4.error as error: + if str(error)=="[AUTHENTICATIONFAILED] Authentication failed.": + self.statusLabel.set_label(_("Login to mailserver failed: please check mailserver, username and password")) + except gaierror as error: + if str(error)=="[Errno -2] Name or service not known": + self.statusLabel.set_label(_("Could not connect to mailserver: check mailserver and use SSL settings and internet connectivity")) #def importAllClicked def get_vbox(self): @@ -128,38 +124,42 @@ class GuiImapFetcher (threading.Thread): self.rowVBox = gtk.VBox() self.mainVBox.add(self.rowVBox) - for email in self.config.emails: - config=self.config.emails[email] - box=gtk.HBox(homogeneous=True) - - for field in (config.siteName, config.fetchType): - label=gtk.Label(field) - box.add(label) - - for field in (config.host, config.username): + for siteName in self.config.supported_sites: + for fetchType in self.config.supported_sites[siteName].emails: + config=self.config.supported_sites[siteName].emails[fetchType] + box=gtk.HBox(homogeneous=True) + + for field in (siteName, config.fetchType): + label=gtk.Label(field) + box.add(label) + + for field in (config.host, config.username): + entry=gtk.Entry() + entry.set_text(field) + box.add(entry) + entry=gtk.Entry() - entry.set_text(field) + self.passwords[siteName+fetchType]=config.password + entry.set_text("***") box.add(entry) - - entry=gtk.Entry() - self.passwords[email]=config.password - entry.set_text("***") - box.add(entry) - - entry=gtk.Entry() - entry.set_text(config.folder) - box.add(entry) - - sslBox = gtk.combo_box_new_text() - sslBox.append_text(_("Yes")) - sslBox.append_text(_("No")) - sslBox.set_active(0) - box.add(sslBox) - - #TODO: "run just this one" button - - self.rowVBox.pack_start(box, expand=False) - #print + + entry=gtk.Entry() + entry.set_text(config.folder) + box.add(entry) + + sslBox = gtk.combo_box_new_text() + sslBox.append_text(_("Yes")) + sslBox.append_text(_("No")) + if config.useSsl: + sslBox.set_active(0) + else: + sslBox.set_active(1) + box.add(sslBox) + + #TODO: "run just this one" button + + self.rowVBox.pack_start(box, expand=False) + #print self.mainVBox.show_all() #end def displayConfig diff --git a/pyfpdb/HUD_config.xml.example b/pyfpdb/HUD_config.xml.example index e95db1b8..58e12f42 100644 --- a/pyfpdb/HUD_config.xml.example +++ b/pyfpdb/HUD_config.xml.example @@ -156,6 +156,7 @@ Left-Drag to Move" xshift="0" yshift="0" supported_games="holdem,razz,omahahi,omahahilo,studhi,studhilo"> + @@ -708,10 +709,6 @@ Left-Drag to Move" - - - -