def _get_image(self, size, action): """ Fetches the large image for lightboxing for the given photo id. Returns the image raw data. """ id = self._get_id_from_path(action) try: id = int(id) p = Photo.get_by_id(id) except Exception as e: p = None if p == None: fc = util.FileContainer(os.path.join(S.IMPORT_DIR, id), S.IMPORT_DIR) fc.time = util.get_time(fc)["time"] p = Photo.from_file_container(fc) if p == None: Logger.warning("could not find photo for %s" % id) image_path = S.BROKEN_IMG_PATH else: rel_thumb_path = p.get_or_create_thumb(size) image_path = os.path.join(S.THUMBNAIL_DIR, rel_thumb_path) f = open(image_path) raw_image = f.read() f.close() return self.construct_response(raw_image, self._route_types.JPEG_CONTENT_TYPE)
def execute_import(self): """ Performs the actual import, taking information from the session file and applying the settings/whatever to the various images in the import dir """ post_args = parse_qs(self._env["wsgi.input"].read()) if "import_id" not in post_args.keys(): raise Exception("need valid import_id") session_data = None session_id = post_args["import_id"][0] session_file_path = os.path.join("/tmp", "%s.txt" % session_id) with open(session_file_path, "r") as handle: session_data = json.loads(handle.read()) import_dir = os.path.join(S.IMPORT_DIR, session_data["rel_dir"]) success_results = [] deleted_results = [] failed_results = [] for file_hash in session_data["file_listing"].keys(): file_data = session_data["file_listing"][file_hash] fc = util.FileContainer.from_dict(file_data["file_data"]) result = { "filename": fc.name, "from": fc.rel_path } try: if fc.marked: to_remove = fc.file_path fc.destroy() Logger.info("not importing %s because it is marked" % to_remove) os.remove(to_remove) result["to"] = "deleted" result["id"] = None deleted_results.append(result) else: p = Photo.from_file_container(fc) p.move_file(src_dir=p.path, copy=False) p.get_or_create_thumb(Photo.SMALL_THUMB_SIZE) p.get_or_create_thumb(Photo.MEDIUM_THUMB_SIZE) p.store() result["id"] = p.id result["to"] = p.rel_path success_results.append(result) except Exception, e: result["error"] = str(e) Logger.error("was not able to do something: %s" % str(e)) failed_results.append(result)
def execute_import(self): """ Performs the actual import, taking information from the session file and applying the settings/whatever to the various images in the import dir """ post_args = parse_qs(self._env["wsgi.input"].read()) if "import_id" not in post_args.keys(): raise Exception("need valid import_id") session_data = None session_id = post_args["import_id"][0] session_file_path = os.path.join("/tmp", "%s.txt" % session_id) with open(session_file_path, "r") as handle: session_data = json.loads(handle.read()) import_dir = os.path.join(S.IMPORT_DIR, session_data["rel_dir"]) success_results = [] deleted_results = [] failed_results = [] for file_hash in session_data["file_listing"].keys(): file_data = session_data["file_listing"][file_hash] fc = util.FileContainer.from_dict(file_data["file_data"]) result = {"filename": fc.name, "from": fc.rel_path} try: if fc.marked: to_remove = fc.file_path fc.destroy() Logger.info("not importing %s because it is marked" % to_remove) os.remove(to_remove) result["to"] = "deleted" result["id"] = None deleted_results.append(result) else: p = Photo.from_file_container(fc) p.move_file(src_dir=p.path, copy=False) p.get_or_create_thumb(Photo.SMALL_THUMB_SIZE) p.get_or_create_thumb(Photo.MEDIUM_THUMB_SIZE) p.store() result["id"] = p.id result["to"] = p.rel_path success_results.append(result) except Exception, e: result["error"] = str(e) Logger.error("was not able to do something: %s" % str(e)) failed_results.append(result)