3 commits - pykolab/xml wallace/module_resources.py

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Fri Jul 13 15:44:16 CEST 2012


 pykolab/xml/__init__.py     |    3 +++
 pykolab/xml/utils.py        |   19 +++++++++++++++++++
 wallace/module_resources.py |   31 ++++++++-----------------------
 3 files changed, 30 insertions(+), 23 deletions(-)

New commits:
commit 2f9376cdfaca44939041cf9c809cb83a148af108
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Jul 13 13:43:32 2012 +0200

    Use utility function to_dt() before comparing es/is/ee/es, greatly simplifying this part of the code
    Make sure we have append permissions

diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index bf0b59d..1641be1 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -21,6 +21,7 @@ import datetime
 import icalendar
 import json
 import os
+import pytz
 import random
 import tempfile
 import time
@@ -41,6 +42,7 @@ from pykolab.conf import Conf
 from pykolab.imap import IMAP
 from pykolab.xml import event_from_ical
 from pykolab.xml import event_from_string
+from pykolab.xml import to_dt
 from pykolab.translate import _
 
 log = pykolab.getLogger('pykolab.wallace')
@@ -231,31 +233,12 @@ def execute(*args, **kw):
                         event = pykolab.xml.event_from_string(payload)
 
                         for itip in itip_events:
-                            _es = event.get_start()
-                            _is = itip['start'].dt
+                            _es = to_dt(event.get_start())
+                            _is = to_dt(itip['start'].dt)
 
-                            if type(_es) == 'datetime.date' or not hasattr(_es, 'hour'):
-                                _es = datetime.datetime(
-                                        _es.year, _es.month, _es.day, 0, 0, 0
-                                    )
-
-                            if type(_is) == 'datetime.date' or not hasattr(_is, 'hour'):
-                                _is = datetime.datetime(
-                                        _is.year, _is.month, _is.day, 0, 0, 0
-                                    )
-
-                            _ee = event.get_end()
-                            _ie = itip['end'].dt
+                            _ee = to_dt(event.get_end())
+                            _ie = to_dt(itip['end'].dt)
 
-                            if type(_ee) == 'datetime.date' or not hasattr(_ee, 'hour'):
-                                _ee = datetime.datetime(
-                                        _ee.year, _ee.month, _ee.day, 0, 0, 0
-                                    )
-
-                            if type(_ie) == 'datetime.date' or not hasattr(_ie, 'hour'):
-                                _ie = datetime.datetime(
-                                        _ie.year, _ie.month, _ie.day, 0, 0, 0
-                                    )
 
                             if _es < _is:
                                 if _es <= _ie:
@@ -360,6 +343,7 @@ def execute(*args, **kw):
                             level=9
                         )
 
+                    imap.imap.m.setacl(resources[resource]['kolabtargetfolder'], "cyrus-admin", "lrswipkxtecda")
                     imap.imap.m.append(
                             resources[resource]['kolabtargetfolder'],
                             None,
@@ -395,6 +379,7 @@ def execute(*args, **kw):
                                 level=9
                             )
 
+                        imap.imap.m.setacl(_target_resource['kolabtargetfolder'], "cyrus-admin", "lrswipkxtecda")
                         imap.imap.m.append(
                                 _target_resource['kolabtargetfolder'],
                                 None,


commit bbabfa8913b349c79023df2fcfba79b257ddc7d4
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Jul 13 13:39:02 2012 +0200

    Add utils.to_dt() as a convenience function to transform a d or dt into a datetime (with timezone) for comparison in resource management

diff --git a/pykolab/xml/__init__.py b/pykolab/xml/__init__.py
index db12a33..5ca2837 100644
--- a/pykolab/xml/__init__.py
+++ b/pykolab/xml/__init__.py
@@ -10,6 +10,8 @@ from event import InvalidEventDateError
 from event import event_from_ical
 from event import event_from_string
 
+from utils import to_dt
+
 __all__ = [
         "Attendee",
         "Contact",
@@ -17,6 +19,7 @@ __all__ = [
         "Event",
         "event_from_ical",
         "event_from_string",
+        "to_dt",
     ]
 
 errors = [


commit 02b4f24ca5cf66fd108f723cb4bfb6319a9d93a8
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Jul 13 13:38:48 2012 +0200

    Add utils for common actions

diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
new file mode 100644
index 0000000..0959c80
--- /dev/null
+++ b/pykolab/xml/utils.py
@@ -0,0 +1,19 @@
+import datetime
+import pytz
+
+def to_dt(dt):
+    """
+        Convert a naive date or datetime to a tz-aware datetime.
+    """
+
+    if type(dt) == 'datetime.date' or not hasattr(dt, 'hour'):
+        dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0)
+
+    else:
+        if dt.tzinfo == None:
+            return dt.replace(tzinfo=pytz.utc)
+        else:
+
+            return dt
+
+





More information about the commits mailing list