1 import logging
2 log = logging.getLogger("dataproviders.Image")
3
4 import conduit
5 import conduit.Exceptions as Exceptions
6 import conduit.datatypes.File as File
7 import conduit.dataproviders.DataProvider as DataProvider
8
10 """
11 Upload information container, this way we can add info
12 and keep the _upload_info method on the ImageSink retain
13 its api
14 """
15 - def __init__ (self, url, mimeType, name="", tags=(), caption=""):
16 self.url = url
17 self.mimeType = mimeType
18 self.name = name
19 self.tags = tags
20 self.caption = caption
21
23 """
24 Abstract Base class for Image DataSinks
25 """
26 _category_ = conduit.dataproviders.CATEGORY_PHOTOS
27 _module_type_ = "sink"
28 _in_type_ = "file/photo"
29 _out_type_ = "file/photo"
30
31 IMAGE_SIZES = ["640x480", "800x600", "1024x768"]
32 NO_RESIZE = "None"
33
36
39
41 import gtk
42 store = gtk.ListStore(str)
43 cell = gtk.CellRendererText()
44 combobox.pack_start(cell, True)
45 combobox.add_attribute(cell, 'text', 0)
46 combobox.set_model(store)
47
48 for s in [self.NO_RESIZE] + self.IMAGE_SIZES:
49 rowref = store.append( (s,) )
50 if s == selected:
51 combobox.set_active_iter(rowref)
52
54 model = combobox.get_model()
55 active = combobox.get_active()
56 if active < 0:
57 return self.NO_RESIZE
58
59 size = model[active][0]
60 if size not in self.IMAGE_SIZES:
61 return self.NO_RESIZE
62
63 return size
64
66 """
67 This should return the info for a given photo id,
68 If this returns anything different from None, it will be
69 passed onto _get_raw_photo_url
70 """
71 return None
72
74 """
75 This should return the url of the online photo
76 """
77 return None
78
80 """
81 Upload a photo
82 """
83 return None
84
86 """
87 Replace a photo with a new version
88 """
89 return id
90
96
102
104 """
105 Return the preferred photo size string for rescaling, or None
106 """
107 return None
108
109 - def put(self, photo, overwrite, LUID=None):
110 """
111 Accepts a vfs file. Must be made local.
112 I also store a md5 of the photos uri to check for duplicates
113 """
114 DataProvider.DataSink.put(self, photo, overwrite, LUID)
115
116 originalName = photo.get_filename()
117
118
119 photoURI = photo.get_local_uri()
120 mimeType = photo.get_mimetype()
121 tags = photo.get_tags ()
122 caption = photo.get_caption()
123
124 uploadInfo = UploadInfo(photoURI, mimeType, originalName, tags, caption)
125
126
127 if LUID != None:
128 info = self._get_photo_info(LUID)
129
130 if info != None:
131 if overwrite == True:
132
133 return self._replace_photo(LUID, uploadInfo)
134 else:
135
136 url = self._get_raw_photo_url(info)
137 remoteFile = File.File(url)
138
139
140 comp = photo.compare(remoteFile,True)
141 log.debug("Compared %s with %s to check if they are the same (size). Result = %s" %
142 (photo.get_filename(),remoteFile.get_filename(),comp))
143 if comp != conduit.datatypes.COMPARISON_EQUAL:
144 raise Exceptions.SynchronizeConflictError(comp, photo, remoteFile)
145 else:
146 return conduit.datatypes.Rid(uid=LUID)
147
148 log.debug("Uploading Photo URI = %s, Mimetype = %s, Original Name = %s" % (photoURI, mimeType, originalName))
149
150
151 return self._upload_photo (uploadInfo)
152
155
163
165 """
166 Abstract Base Class for ImageTwoWay dataproviders
167 """
168
169