Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit d52ec0ad2cabcdf365e0996be6158a28c7f8ad11
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Fri Nov 23 18:23:32 2012 +0100
Move the address of the SMTP server used to send the emails to the configuration file
Up to now the SMTP address was hard-coded to 'localhost', this commit changes
this
allowing one to specify a specific SMTP server to use to send the emails.
Emails are only sent via the cron job which is run hourly to send reminders.
Fixes #14
---------------------------------------------------------------
fedocal.cfg.sample | 5 +++++
fedocal/default_config.py | 5 +++++
fedocal_cron.py | 24 ++++++------------------
3 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/fedocal.cfg.sample b/fedocal.cfg.sample
index d68897d..535ce59 100644
--- a/fedocal.cfg.sample
+++ b/fedocal.cfg.sample
@@ -10,3 +10,8 @@ DB_URL='sqlite:////tmp/fedocal_dev.sqlite'
### The FAS group in which the admin of fedocal are
ADMIN_GROUP='fedocal_admin'
+
+### The address of the SMTP server used to send the reminders emails
+### via the cron job.
+### Default: 'localhost'
+SMTP_SERVER='localhost'
diff --git a/fedocal/default_config.py b/fedocal/default_config.py
index 81f6e92..95c7351 100644
--- a/fedocal/default_config.py
+++ b/fedocal/default_config.py
@@ -30,3 +30,8 @@ DB_URL = 'sqlite:////tmp/fedocal_dev.sqlite'
# The FAS group in which the admin of fedocal are
ADMIN_GROUP = 'fedocal_admin'
+
+
+# The address of the SMTP server used to send the reminders emails
+# via the cron job.
+SMTP_SERVER='localhost'
diff --git a/fedocal_cron.py b/fedocal_cron.py
index 5e885c7..3c577e5 100644
--- a/fedocal_cron.py
+++ b/fedocal_cron.py
@@ -33,10 +33,9 @@ import os
from email.mime.text import MIMEText
-import sys
-sys.path.insert(0, 'fedocal')
+import fedocal
+import fedocal.fedocallib as fedocallib
-from fedocal import fedocallib
def send_reminder_meeting(meeting):
""" This function sends the actual reminder of a given meeting.
@@ -67,17 +66,18 @@ Please note:
# Send the message via our own SMTP server, but don't include the
# envelope header.
- s = smtplib.SMTP('localhost')
+ s = smtplib.SMTP(fedocal.APP.config['SMTP_SERVER'])
s.sendmail(from_email,
meeting.reminder.reminder_to,
msg.as_string())
s.quit()
-def send_reminder(db_url):
+def send_reminder():
""" Retrieve all the meeting for which we should send a reminder and
do it.
"""
+ db_url = fedocal.APP.config['DB_URL']
session = fedocallib.create_session(db_url)
meetings = fedocallib.retrieve_meeting_to_remind(session)
for meeting in meetings:
@@ -85,16 +85,4 @@ def send_reminder(db_url):
if __name__ == '__main__':
- sys.argv.append('fedocal/fedocal.cfg')
- config = ConfigParser.ConfigParser()
- if len(sys.argv) == 1:
- if os.path.exists('/etc/fedocal.cfg'):
- config.readfp(open('/etc/fedocal.cfg'))
- else:
- print 'No config file found in /etc or specified to the cron.'
- elif len(sys.argv) == 2:
- if os.path.exists(sys.argv[1]):
- config.readfp(open(sys.argv[1]))
- else:
- print 'Config file specified to the cron could not be found.'
- send_reminder(config.get('fedocal', 'db_url'))
+ send_reminder()