def save_attachments(self, p, dbname, docid, rev): print "Processing image for", p.id t = p.extension if t == 'jpg': t = 'jpeg' t = 'image/' + t self.save_attachment(p, dbname, docid, libphoto.fetchImage(self.pbase, p.id), t, 'original', rev) self.save_attachment(p, dbname, docid, libphoto.fetchImage(self.pbase, p.id, thumbnail=True), t, 'thumb') self.save_attachment(p, dbname, docid, libphoto.fetchImage(self.pbase, p.id, size='800x600'), t, '800x600')
def __storeImage(baseurl, d, fn, img): print "Fetching", img[0] imgid, imgmd5, ext=img if not os.path.exists(d): os.makedirs(d) fout=open(fn + ".tmp", "w") fin=libphoto.fetchImage(baseurl, imgid) shutil.copyfileobj(fin, fout) fin.close() fout.close() assert __validateMd5(fn + ".tmp", imgmd5), "Invalid MD5 for " + `imgid` os.rename(fn + ".tmp", fn)
def __fetchRemoteImage(self): f = libphoto.fetchImage(self.baseurl, self.photo.id, self.size, self.tn) toWrite=open(self.destpath, "w") shutil.copyfileobj(f, toWrite) toWrite.close() f.close()