summaryrefslogtreecommitdiff
path: root/logbot.py
diff options
context:
space:
mode:
authorChris Oliver <excid3@gmail.com>2011-12-13 18:30:47 -0600
committerChris Oliver <excid3@gmail.com>2011-12-13 18:30:47 -0600
commit925df20d1a95e52dc4a7a9f2b2c4fe5e378f4b38 (patch)
tree6d720917646af83c4d2bd4527a8b54f0cfb2264b /logbot.py
parent3af452f3b8c84cfac0945989f89167f54e8b143b (diff)
downloadlogbot-925df20d1a95e52dc4a7a9f2b2c4fe5e378f4b38.tar.xz
Reconnect FTP if we have a timeout.
Diffstat (limited to 'logbot.py')
-rw-r--r--logbot.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/logbot.py b/logbot.py
index 2460582..dd75edb 100644
--- a/logbot.py
+++ b/logbot.py
@@ -82,7 +82,7 @@ default_format = {
}
html_header = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@@ -216,6 +216,9 @@ class Logbot(SingleServerIRCBot):
self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb"))
else:
raise e
+ except ftplib.error_temp, e: # Reconnect on timeout
+ self.set_ftp(connect_ftp())
+
print "Finished uploading"
def append_log_msg(self, channel, msg):
@@ -324,6 +327,12 @@ class Logbot(SingleServerIRCBot):
self.write_event("topic", e)
+def connect_ftp():
+ print "Using FTP %s..." % (FTP_SERVER)
+ f = ftplib.FTP(FTP_SERVER, FTP_USER, FTP_PASS)
+ f.cwd(FTP_FOLDER)
+ return f
+
def main():
# Create the logs directory
if not os.path.exists("logs"):
@@ -335,14 +344,11 @@ def main():
try:
# Connect to FTP
if FTP_SERVER:
- print "Using FTP %s..." % (FTP_SERVER)
- f = ftplib.FTP(FTP_SERVER, FTP_USER, FTP_PASS)
- f.cwd(FTP_FOLDER)
- bot.set_ftp(f)
+ bot.set_ftp(connect_ftp())
bot.start()
except KeyboardInterrupt:
- if FTP_SERVER: f.quit()
+ if FTP_SERVER: bot.ftp.quit()
bot.quit()