ical, xmlutils: Introduced logging and more debug output
authorTobias Mueller <muelli@cryptobitch.de>
Sat, 14 Jan 2012 00:50:36 +0000 (01:50 +0100)
committerTobias Mueller (ideabox) <tobiasmue@gnome.org>
Sun, 15 Jan 2012 00:06:37 +0000 (01:06 +0100)
calypso/webdav.py
calypso/xmlutils.py

index d8e1c1678000786bc060627cb463d99b46eff814..a292e70f3676ac514bcf2d0f0857d82314268db8 100644 (file)
@@ -36,6 +36,7 @@ import tempfile
 import vobject
 import string
 import re
+import logging
 
 from . import config
 
@@ -206,6 +207,7 @@ class Collection(object):
     def __init__(self, path):
         """Initialize the collection with ``cal`` and ``user`` parameters."""
         
+        self.log = logging.getLogger(__name__)
         folder = os.path.expanduser(config.get("storage", "folder"))
 
         self.encoding = "utf-8"
@@ -251,9 +253,11 @@ class Collection(object):
             
     def write_file(self, item):
         fd, path = tempfile.mkstemp(suffix=".ics", prefix="cal", dir=self.path)
+        self.log.debug('Trying to write to %s', path)
         file = os.fdopen(fd, 'w')
         file.write(item.text.encode('utf-8'))
         file.close()
+        self.log.debug('Wrote %s to %s', file, path)
         return path
 
     def create_file(self, item):
@@ -274,6 +278,7 @@ class Collection(object):
         except OSError, ex:
             print "Error writing file: %s" % ex
         except Exception, ex:
+            print "Caught Exception:\n%s" % (ex,)
             print "Failed to create %s: %s" % (path,  ex)
 
     def destroy_file(self, item):
@@ -320,8 +325,8 @@ class Collection(object):
 
         try:
             new_item = Item(text, name, None)
-        except Exception:
-            print "Cannot create new item"
+        except Exception, e:
+            print "Cannot create new item: %s" % e
             return False
         if new_item.name not in (item.name for item in self.my_items):
             print "New item %s" % new_item.name
index 56783afc11837d2317a00ff321fc28e5f56403ef..688cad2a393361ad5b866238584fab1d8af7376e 100644 (file)
@@ -36,16 +36,19 @@ import dateutil.rrule
 import dateutil.tz
 import datetime
 import email.utils
+import logging
 import urllib
 
 from . import client, config, webdav
 
+__package__ = 'calypso.xmlutils'
 
 NAMESPACES = {
     "C": "urn:ietf:params:xml:ns:caldav",
     "D": "DAV:",
     "CS": "http://calendarserver.org/ns/"}
 
+log = logging.getLogger(__name__)
 
 def _tag(short_name, local):
     """Get XML Clark notation {uri(``short_name``)}``local``."""
@@ -60,7 +63,9 @@ def _response(code):
 def name_from_path(path):
     """Return Calypso item name from ``path``."""
     path_parts = path.strip("/").split("/")
-    return urllib.unquote(path_parts[-1]) if len(path_parts) > 2 else None
+    name =  urllib.unquote(path_parts[-1]) if len(path_parts) > 2 else None
+    log.debug('Path %s results in name: %s', path, name)
+    return name
 
 def delete(path, collection):
     """Read and answer DELETE requests.
@@ -206,6 +211,7 @@ def put(path, webdav_request, collection):
         collection.replace(name, webdav_request)
     else:
         # PUT is adding a new item
+        log.debug('Putting a new item, because name %s is not known', name)
         collection.append(name, webdav_request)