| Trees | Indices | Help |
|
|---|
|
|
1 import re
2 import logging
3 log = logging.getLogger("modules.Converter")
4
5 import conduit.utils as Utils
6 import conduit.TypeConverter as TypeConverter
7 import conduit.datatypes.Contact as Contact
8 import conduit.datatypes.Event as Event
9 import conduit.datatypes.Text as Text
10 import conduit.datatypes.Email as Email
11 import conduit.datatypes.File as File
12 import conduit.datatypes.Note as Note
13 import conduit.datatypes.Setting as Setting
14 import conduit.datatypes.Bookmark as Bookmark
15
16 MODULES = {
17 "EmailConverter" : { "type": "converter" },
18 "NoteConverter" : { "type": "converter" },
19 "ContactConverter" : { "type": "converter" },
20 "EventConverter" : { "type": "converter" },
21 "FileConverter" : { "type": "converter" },
22 "SettingConverter" : { "type": "converter" },
23 "BookmarkConverter" : { "type": "converter" },
24 }
25
28 self.conversions = {
29 "email,text" : self.email_to_text,
30 "text,email" : self.text_to_email,
31 "email,file" : self.email_to_file,
32 "file,email" : self.file_to_email,
33 }
34
35
41
47
51
53 """
54 If the file is non binary then include it as the
55 Subject of the message. Otherwise include it as an attachment
56 """
57 mimeCategory = thefile.get_mimetype().split('/')[0]
58 if mimeCategory == "text":
59 #insert the contents into the email
60 log.debug("Inserting file contents into email")
61 email = Email.Email(
62 subject=thefile.get_filename(),
63 content=thefile.get_contents_as_text()
64 )
65 else:
66 #binary file so send as attachment
67 log.debug("Binary file, attaching to email")
68 email = Email.Email(
69 subject=thefile.get_filename(),
70 content="Attached"
71 )
72 email.add_attachment(thefile.get_local_uri())
73
74 return email
75
76
79 self.conversions = {
80 "text,note" : self.text_to_note,
81 "note,text" : self.note_to_text,
82 "note,file" : self.note_to_file
83 }
84
91
97
99 f = File.TempFile(note.get_contents())
100 f.force_new_filename(note.get_title())
101 f.force_new_file_extension(".txt")
102 return f
103
106 self.conversions = {
107 "contact,file" : self.contact_to_file,
108 "contact,text" : self.contact_to_text,
109 "file,contact" : self.file_to_contact,
110 }
111
116
123
128
131 self.conversions = {
132 "event,file" : self.event_to_file,
133 "event,text" : self.event_to_text,
134 "file,event" : self.file_to_event,
135 "text,event" : self.text_to_event,
136 }
137
142
148
153
158
161 self.conversions = {
162 "text,file" : self.text_to_file,
163 "file,text" : self.file_to_text,
164 "file,note" : self.file_to_note
165 }
166
169
171 test = None
172 if f.get_mimetype().startswith("text"):
173 text = Text.Text(
174 text=f.get_contents_as_text()
175 )
176 return text
177
179 note = None
180 if f.get_mimetype().startswith("text"):
181 title,ext = f.get_filename_and_extension()
182 #remove the file extension....
183 note = Note.Note(
184 title=title,
185 contents=f.get_contents_as_text()
186 )
187 return note
188
191 self.conversions = {
192 "setting,text" : self.setting_to_text,
193 "setting,file" : self.setting_to_file,
194 "text,setting" : self.text_to_setting,
195 "file,setting" : self.file_to_setting
196 }
197 #recognizes key value in text strings
198 self.regex = re.compile(r"^key:(.+)\nvalue:(.*)$")
199
202
204 m = self.regex.match(txt)
205 if m != None and len(m.groups()) == 2:
206 return m.group(1),m.group(2)
207 else:
208 return None,None
209
215
217 setting = None
218 k,v = self._to_key_value(text.get_string())
219 if k != None and v != None:
220 setting = Setting.Setting(
221 key=k,
222 value=v
223 )
224 return setting
225
227 f = File.TempFile(
228 self._to_text(setting)
229 )
230 f.force_new_filename(setting.key.replace("/","_"))
231 f.force_new_file_extension(".txt")
232 return f
233
235 setting = None
236 if f.get_mimetype().startswith("text"):
237 txt = f.get_contents_as_text()
238 k,v = self._to_key_value(txt)
239 if k != None and v != None:
240 setting = Setting.Setting(
241 key=k,
242 value=v
243 )
244 return setting
245
248 self.conversions = {
249 "bookmark,text" : self.bookmark_to_text,
250 "bookmark,file" : self.bookmark_to_file,
251 "text,bookmark" : self.text_to_bookmark,
252 "file,bookmark" : self.file_to_bookmark
253 }
254 #recognizes key value in text strings
255 self.regex = re.compile(r"^title:(.+)\nuri:(.*)$")
256
259
261 m = self.regex.match(txt)
262 if m != None and len(m.groups()) == 2:
263 return m.group(1),m.group(2)
264 else:
265 return None,None
266
272
274 bookmark = None
275 k,v = self._to_key_value(text.get_string())
276 if k != None and v != None:
277 bookmark = Bookmark.Bookmark(
278 title=k,
279 uri=v
280 )
281 return bookmark
282
284 f = File.TempFile(
285 self._to_text(bookmark)
286 )
287 f.force_new_filename(bookmark.title.replace("/","_"))
288 f.force_new_file_extension(".txt")
289 return f
290
292 bookmark = None
293 if f.get_mimetype().startswith("text"):
294 txt = f.get_contents_as_text()
295 k,v = self._to_key_value(txt)
296 if k != None and v != None:
297 bookmark = Bookmark.Bookmark(
298 title=k,
299 uri=v
300 )
301 return bookmark
302
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Sat Aug 2 22:18:49 2008 | http://epydoc.sourceforge.net |