def get_image_path(generator_id, fname, size=None): gen = query.get_generator(generator_id) pack_path = get_package_path(gen) pack_id = gen.package.pack_id gen_id = gen.gen_id.split(pack_id, 1)[-1].lstrip('.') image_path = os.path.sep.join([pack_path, 'screenshots', gen_id, fname]) if size: id = '+'.join([generator_id, fname, size]) fsize = [int(s) for s in size.split('x', 1)] thumb_path = compute_cache_path(config.cache_dir, id) if not os.path.exists(thumb_path): im = Image.open(image_path) im.thumbnail(fsize, Image.ANTIALIAS) im.save(thumb_path, "JPEG") image_path = thumb_path return image_path
def download(request, _id): gen = query.get_generator(_id) if not gen: return apiresponse(code='err_record') pack_path = get_package_path(gen) zip_file = '.'.join([pack_path, 'zip']) if not os.path.exists(zip_file): return apiresponse(code='err_record') data = open(zip_file, 'rb').read() resp = HttpResponse(mimetype='application/zip') resp['Content-Disposition'] = 'attachment; filename=%s.zip' % _id resp.write(data) pack = gen.package num_downloaded = pack.num_downloaded+1 if pack.num_downloaded else 1 pack.num_downloaded = num_downloaded pack.save() return resp