conduit r1707 - in trunk: . conduit conduit/modules



Author: jstowers
Date: Fri Aug 29 23:41:40 2008
New Revision: 1707
URL: http://svn.gnome.org/viewvc/conduit?rev=1707&view=rev

Log:
Merge from trunk

Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/conduit/TypeConverter.py
   trunk/conduit/modules/ConverterModule.py

Modified: trunk/conduit/TypeConverter.py
==============================================================================
--- trunk/conduit/TypeConverter.py	(original)
+++ trunk/conduit/TypeConverter.py	Fri Aug 29 23:41:40 2008
@@ -158,16 +158,15 @@
         return False
         
     def _convert(self, conversions, data):
-        if len(conversions) > 0:
+        if data and len(conversions) > 0:
             from_type, to_type, args = conversions[0]
             message = "Converting"
             if from_type == to_type:
                 message = "Transcoding"
                 #No conversion needed, or module does not supply transcode.
                 if args == {} or not self._conversion_exists(from_type, to_type):
-                    #recurse
                     log.debug("Skipping %s -> %s" % (from_type, to_type))
-                    return self._convert(conversions[1:],data)
+                    return data
 
             log.debug("%s %s -> %s (args: %s)" % (message, from_type, to_type, args))
             try:

Modified: trunk/conduit/modules/ConverterModule.py
==============================================================================
--- trunk/conduit/modules/ConverterModule.py	(original)
+++ trunk/conduit/modules/ConverterModule.py	Fri Aug 29 23:41:40 2008
@@ -107,6 +107,7 @@
                             "contact,file"    : self.contact_to_file,
                             "contact,text"    : self.contact_to_text,
                             "file,contact"    : self.file_to_contact,
+                            "text,contact"    : self.text_to_contact,
                             }
                             
     def contact_to_file(self, contact, **kwargs):
@@ -122,8 +123,24 @@
         return t
 
     def file_to_contact(self, f, **kwargs):
-        c = Contact.Contact()
-        c. set_from_vcard_string(f.get_contents_as_text())
+        c = None
+        if f.get_mimetype().split('/')[0] == "text":
+            try:
+                c = Contact.Contact()
+                c.set_from_vcard_string(f.get_contents_as_text())
+            except:
+                c = None
+                log.warn("Error converting file to contact")
+        return c
+
+    def text_to_contact(self, text, **kwargs):
+        c = None
+        try:
+            c = Contact.Contact()
+            c.set_from_vcard_string(text.get_string())
+        except:
+            c = None
+            log.warn("Error converting text to contact")
         return c
 
 class EventConverter(TypeConverter.Converter):
@@ -147,13 +164,24 @@
         return t
 
     def file_to_event(self, f, **kwargs):
-        e = Event.Event()
-        e.set_from_ical_string(f.get_contents_as_text())
+        e = None
+        if f.get_mimetype().split('/')[0] == "text":
+            try:
+                e = Event.Event()
+                e.set_from_ical_string(f.get_contents_as_text())
+            except:
+                e = None
+                log.warn("Error converting file to event")
         return e
 
     def text_to_event(self, text, **kwargs):
-        e = Event.Event()
-        e.set_from_ical_string(text.get_string())
+        e = None
+        try:
+            e = Event.Event()
+            e.set_from_ical_string(text.get_string())
+        except:
+            e = None
+            log.warn("Error converting text to event")
         return e
 
 class FileConverter(TypeConverter.Converter):



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