def _get_blip(self, key=None, value=None): logging.debug('getting blip: %s %s %s' % (self.storage_root,key,len(value or ''))) blip = Blip(self.storage_root,key=key) if value is not None: blip.set_value(value) return blip
def get_thumbnail(storage_root,full_url,size,timeout=None,farm_work=False): from diskdb import SimpleBlip as Blip import urlparse import memcache # we are going to use memcache as a shared cache # and the drive as a local cache mc = memcache.Client(['memcached.mypubliccode.com:11211']) size = str(size) # we need a string parsed = urlparse.urlparse(full_url) # break up our url to strip args url = '%s://%s%s' % (parsed.scheme,parsed.netloc,parsed.path) # recreate key = get_key(url,size) # get the key for this file's storage print 'key: %s' % key # check and see if we have the thumbnail already thumbnail = Blip(storage_root,key) thumbnail_data = thumbnail.get_value() if not thumbnail_data: thumbnail_data = mc.get(key) if thumbnail_data: print 'got from mc' # if we don't have the thumbnail check and see if # we have the original if not thumbnail_data: print 'no thumbnail data' original = Blip(storage_root,get_key(url)) original_data = original.get_value() if not original_data: original_data = mc.get(get_key(url)) if original_data: print 'got from mc' # if we don't have the original send off a task to # download it if not thumbnail_data and not original_data: print 'no original data' original_data = download_resource(url,farm=True if farm_work else False) original.set_value(original_data) original.flush() mc.set(get_key(url),original_data) if not thumbnail_data: print 'creating thumbnail' # now that we've downloaded it we need to get it resized thumbnail_data = thumbnail_image(size,original_data, farm=True if farm_work else False) thumbnail.set_value(thumbnail_data) thumbnail.flush() mc.set(key,thumbnail_data) return thumbnail_data