def copy(self, src_path_spec, dst_volume, dst_path_spec, remove=False): spath, sdir, sfile = src_path_spec dpath, ddir, dfile = dst_path_spec if not sfile: raise elFinder.Error("errNotFile") if not ddir: raise elFinder.Error("errNotFolder") if dfile: raise elFinder.Error("errCmdParams") dfile = dst_volume._copy_from(ddir, self, sdir, sfile) result = dict(added=[dst_volume.file_entry(ddir, dfile)]) if remove: result["removed"] = [self.file_entry(sdir, sfile)["hash"]] self.remove(src_path_spec) return result
def add(self, path_spec, upload): import werkzeug ### XXX path, gallery, file = path_spec MOM = self._scope.MOM if file: raise elFinder.Error("errTrgFolderNotFound") pics = sorted(gallery.pictures, key=lambda p: -p.number) if pics: number = pics[0].number + 1 else: number = 0 name, ext = os.path.splitext \ (werkzeug.secure_filename (upload.filename)) img = self.PETM \ ( gallery , number = number , name = name , photo = MOM._Pic_ ( extension = ext ) , thumb = MOM._Thumb_ ( extension = ext ) ) upload.save(img.photo.path) i = PIL.Image.open(img.photo.path) img.photo.width, img.photo.height = i.size i.thumbnail(self.thum_size, PIL.Image.ANTIALIAS) i.save(img.thumb.path) img.thumb.width, img.thumb.height = i.size return self.file_entry(gallery, img)
def decode_hashes(self, hashes): if len(hashes) > 2: raise elFinder.Error("errCmdParams") result = [] dir = None file = None if hashes: dir_name = hashes.pop(0) dir = self.GETM.pid_query(dir_name) if not dir: raise elFinder.Error("errFolderNotFound", dir_name) result.append(dir.perma_name) if hashes: file_name = hashes.pop(0) file = self.PETM.pid_query(file_name) if not file: raise elFinder.Error("errFileNotFound", file_name) result.append(file.name) return "/".join(result), dir, file
def tree(self, path): path, dir, file = path result = [] if not dir: raise elFinder.Error("errCmdParams") else: result.append(self.volume_entry()) for b in self.dirs_of_path(path, dir): for d in self.directories(b): result.append(self.directory_entry(d)) return result
def remove(self, path_spec): ### XXX path, gallery, picture = path_spec if picture: entry = self.file_entry(gallery, picture) picture.destroy() else: if not gallery.pictures: entry = self.directory_entry(gallery) gallery.destroy() else: raise elFinder.Error("errUsupportType") return entry
def add(self, path_spec, upload): import werkzeug ### XXX path, dir, file = path_spec if file: raise elFinder.Error("errTrgFolderNotFound") abs_file_name = os.path.join \ ( self.root_dir, dir.name , werkzeug.secure_filename (upload.filename) ) rel_file_name = abs_file_name.replace(MOM.Web_Src_Root, "") upload.save(abs_file_name) i = PIL.Image.open(abs_file_name) w, h = i.size file = self.ETM(path=rel_file_name, width=w, height=h) self._scope.MOM.Id_Entity_has_Tag(file, ddir) return self.file_entry(dir, file)
def mkdir(self, dir, name): raise elFinder.Error("mkdir", name)
def _handle_mkdir(self, request, response, method, volume, path_spec): path, dir, file = path_spec if file: raise elFinder.Error("errCmdParams") return dict \ (added = [volume.mkdir (dir, request.req_data.get ("name"))])
def _is_image(self, volume, file): self._is_file(volume, file) mime = volume.mime_type(file) if not mime.startswith("image"): raise elFinder.Error("errUsupportType")
def _is_file(self, volume, file): if not file: raise elFinder.Error("errCmdParams")