[gsoc-admin] Add configuration parsing



commit e703ce4e41fc1e1667643c082153222d822bc1dc
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Wed Aug 12 11:41:52 2015 +0200

    Add configuration parsing

 data/config.cfg |    4 +++-
 email/config.py |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/data/config.cfg b/data/config.cfg
index f47ee98..86b1c73 100644
--- a/data/config.cfg
+++ b/data/config.cfg
@@ -1,3 +1,5 @@
+[GSoC_Dates]
+type = ics_source
 ics_url = http://www.google.com/calendar/ical/gsummerofcode%40gmail.com/public/basic.ics
 
 [FINAL_EVALS]
@@ -6,4 +8,4 @@ ics_description = .*[fF]inal evaluation deadline.*
 
 [FOO]
 type = mail_template
-when = FINAL_EVALS - 3d
\ No newline at end of file
+when = FINAL_EVALS - 3d
diff --git a/email/config.py b/email/config.py
new file mode 100644
index 0000000..0e8c628
--- /dev/null
+++ b/email/config.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import configparser
+
+class EventConfig:
+    def __init__(self):
+        self.ics_sources = []
+        self.mail_templates = []
+        self.dates = []
+
+    def append_from_section(self, section):
+        section_type = section['type'].lower()
+        if section_type in ['date']:
+            return self.append_date_from_section(section)
+
+        if section_type in ['mail', 'mail_template']:
+            return self.append_mail_from_section(section)
+
+        if section_type in ['ics', 'ics_source']:
+            return self.append_ics_from_section(section)
+
+    def append_date_from_section(self, section):
+        raise NotImplementedError
+
+    def append_mail_from_section(self, section):
+        raise NotImplementedError
+
+    def append_ics_from_section(self, section):
+        raise NotImplementedError
+
+def parse_event_config(filename)
+    config = configparser.ConfigParser()
+    config.read(filename)
+    result = EventConfig()
+    for section in config.sections():
+        result.append_from_section(section)
+
+    return result


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]