Volume drivers API

yawd-elfinder implemets two volume drivers:

The first must be used along with Django storages and the latter is designed for native access to the local filesystem. Both drivers implement the elfinder.volumes.base.ElfinderVolumeDriver API.

Base driver

class elfinder.volumes.base.ElfinderVolumeDriver[source]

The base volume driver. Every elfinder volume driver should subclass this volume.

_abspath(path)[source]

Convert path (that should be relative to the volume root) into a real path.

_archive(dir_, files, name, arc)[source]

Create an archive file and return its path.

Warning

Not implemented, each driver must provide its own imlementation.

_attr(path, attr, val=False)[source]

Check a file attribute. attr can be one of ‘read’, ‘write’ ‘hidden’ or ‘locked’.

_basename(path)[source]

Return file name. This method should behave like os.path.basename() does.

Warning

Not implemented, each driver must provide its own imlementation.

_can_create_tmb(path, stat)[source]

Return True if thumnbnail for required file can be created.

_checkArchivers()[source]

Detect available archivers

_clear_cached_dir(path)[source]

Clear cache for this directory path.

_clear_cached_stat(path)[source]

Clear the cache for this file path.

_closest_by_attr(path, attr, val)[source]

If file has required attr == val - return file path, If dir has child with has required attr == val - return child path

_configure()[source]

Configure after successful mount. The default implementation sets the thumbnail path.

It is common for drivers to override this method.

_copy(source, target_dir, name)[source]

Copy file into another file (both paths belong to this volume driver).

Warning

Not implemented, each driver must provide its own imlementation.

_copy_from(volume, src, dst, name)[source]

Copy file from another volume and return the new file path. Raises PermissionDeniedError if source is not readable.

_crypt(path)[source]

Return crypted path.

_dimensions(path)[source]

Return object width and height as a string (e.g. ‘32x46’). It is used for images, but it could also be realized for video etc.

Warning

Not implemented, each driver must provide its own imlementation.

_dirname(path)[source]

Return parent directory path. This method should behave like os.path.dirname() does.

Warning

Not implemented, each driver must provide its own imlementation.

_extract(path, archiver)[source]

Extract files from archive.

Warning

Not implemented, each driver must provide its own imlementation.

_fclose(fp, **kwargs)[source]

Close opened file.

Warning

Not implemented, each driver must provide its own imlementation.

_fopen(path, mode='rb')[source]

Open file and return file pointer.

Warning

Not implemented, each driver must provide its own imlementation.

_get_cached_dir(path)[source]

Get the cached stat info for this directory path, if any.

_get_contents(path)[source]

Get file contents.

Warning

Not implemented, each driver must provide its own imlementation.

_get_scandir(path)[source]

Return required directory files info.

_get_tmb(path, stat)[source]

Return thumnbnail name if exists

_get_tree(path, deep, exclude='')[source]

Return subdirs tree

_img_crop(im, target, width, height, x, y, destformat=None)[source]

Crop image.

_img_resize(im, target, width, height, keepProportions=False, resizeByBiggerSide=True, destformat=None)[source]

Resize image and return the new image.

_img_rotate(im, target, degree, bgcolor='#ffffff', destformat=None)[source]

Rotate image. The degree argument is measured clock-wise.

_img_square_fit(im, target, width, height, bgcolor='#ffffff', destformat=None)[source]

Put image to square

_inpath(path, parent)[source]

Return True if path is child of parent.

_is_hidden(stat)[source]

Check if the file/directory is hidden

_is_locked(stat)[source]

Check if the file/directory is locked

_isabs(path)[source]

Check if path is absolute.

_join_path(path1, path2)[source]

Join two paths and return full path. If the latter path is absolute, return it. This method should behave like os.path.join() does, but accept only two paths.

Warning

Not implemented, each driver must provide its own imlementation.

_mimetype(path)[source]

Attempt to read the file’s mimetype. Should return None on fail.

Warning

Not implemented, each driver must provide its own imlementation.

_mkdir(path, mode)[source]

Create directory and return the path or raise an os.error on fail.

Warning

Not implemented, each driver must provide its own imlementation.

_mkfile(path, name)[source]

Create file and return it’s path or raise an os.error on fail.

Warning

Not implemented, each driver must provide its own imlementation.

_move(source, target_dir, name)[source]

Move file into another parent directory. Return the new file path or raise os.error.

Warning

Not implemented, each driver must provide its own imlementation.

_name_accepted(name)[source]

Validate file name based on self._options[‘acceptedName’] regular expression.

_normpath(path)[source]

Return normalized path. This method should behave like os.path.normpath() does.

Warning

Not implemented, each driver must provide its own imlementation.

_openimage(path)[source]

Open an image file.

Warning

Not implemented, each driver must provide its own imlementation.

_path(path)[source]

Return fake path starting from the root dir. Used for displaying the path to the client.

_put_contents(path, content)[source]

Write a string to a file.

Warning

Not implemented, each driver must provide its own imlementation.

_relpath(path)[source]

Return file path related to root dir

_rm_tmb(stat, recursion=True)[source]

Remove thumbnail, also remove recursively if stat is directory

_rmdir(path)[source]

Remove directory (not recursively).

Warning

Not implemented, each driver must provide its own imlementation.

_save(fp, dir_, name)[source]

Create new file and write into it from file pointer. Return the new file path or raise an py:class:Exception.

Warning

Not implemented, each driver must provide its own imlementation.

_save_uploaded(uploaded_file, dir_, name, **kwargs)[source]

Save the Django UploadedFile object and return its new path.

Warning

Not implemented, each driver must provide its own imlementation.

_saveimage(im, path, form)[source]

Save an image file.

Warning

Not implemented, each driver must provide its own imlementation.

_scandir(path)[source]

Return files list in directory. The ‘.’ and ‘..’ special directories are omitted and the returned paths must be relative to the driver root.

Warning

Not implemented, each driver must provide its own imlementation.

Recursively search for files in the specified path, based on the q query.

_size(path)[source]

Return file or directory total size.

_stat(path)[source]

Return stat for given path. The returned dictionary must contain the following keys:

size:file size in b. Required
ts:file modification time in unix time. Required
mime:mimetype. required for folders, others. Optional
read:read permissions. Required
write:write permissions. Required
alias:link target path relative to root path (for symlinks). Optional
target:link target path (for symlinks). Optional

This method should raise an os.error on fail.

Warning

Not implemented, each driver must provide its own imlementation.

_subdirs(path)[source]
Return True if path is dir and has at least one child directory.

Warning

Not implemented, each driver must provide its own imlementation.

Create symlink. Some drivers may not support this.

Warning

Not implemented, each driver must provide its own imlementation.

_tmb_name(stat)[source]

Return thumbnail file name for required file

_uncrypt(hash_)[source]

Return uncrypted path.

_unique_name(dir_, name, suffix=' copy', check_num=True)[source]

Return new unique name based on file name and suffix

Remove file.

Warning

Not implemented, each driver must provide its own imlementation.

_unpack(path, archiver)[source]

Unpack archive

archive(hashes, mime)[source]

Add files to archive

close(fp, hash_)[source]

Close a file pointer.

closest(hash_, attr, val)[source]

Return the file/directory hash or the first found child hash for which attr == val.

command_disabled(cmd)[source]

Return True if command cmd is disabled.

copy(src, dst, name)[source]

Copy file/recursive copy dir only in current volume. Return new file path or raise an Exception.

copy_from_allowed()[source]

Return True if copy from this volume is allowed.

debug()[source]

Return debug info for client. The returned dictionary contains the following keys:

id:the volume id
name:the volume name
decode(hash_)[source]

Decode path from hash.

default_path()[source]

Return volume root or startPath hash.

dimensions(hash_)[source]

Return image dimensions. Raises FileNotFoundError or NotAnImageError.

dir(hash_, resolve_link=False)[source]

Return folder info. Raises a DirNotFoundError if hash_ path is not a directory, or FileNotFoundError if the hash_ path is not a valid file at all.

driver_id()[source]

Return the driver id. Used as a part of volume id.

duplicate(hash_, suffix='copy')[source]

Create file copy with suffix “copy <number>” and return its info.

encode(path)[source]

Encode path into hash

extract(hash_)[source]

Extract files from archive

file(hash_)[source]

Return file info or raises a FileNotFoundError if file was not found.

get_contents(hash_)[source]

Return file contents

id()[source]

Return volume id.

is_readable()[source]

Return True if root is readable.

ls(hash_)[source]

List directory files. Can raise PermissionDeniedError, FileNotFoundError, DirNotFoundError If a mime filter is set, use it to return only accepted listings.

mime_accepted(mime, mimes=[], empty=True)[source]

Return True if mime is in required mimes list.

mimetype(path, name='')[source]

Return file mimetype.

mkdir(hash_dst, name)[source]

Create directory and return its stat info.

mkfile(hash_dst, name)[source]

Create empty file and return its stat info.

mount(opts)[source]

“Mount” volume. Return True if volume available for read or write, False otherwise.

It is common for drivers to override this method.

move(src, dst, name)[source]

Move file. Return new file path or raise an Exception.

name()[source]

Return the driver name.

open(hash_)[source]

Open file for reading and return a file pointer.

options(hash_)[source]

Return volume options required by client. The returned dictionary contains the following keys:

path:the path to the root as it will be displayed to the end user
url:the root volume url
pathUrl:url of the path provided in the hash_ argument
tmbUrl:the root thumbnail url
disabled:a list of the disabled commands
separator:the path separator for this volume
copyOverwrite:whether it is allowed or not to overwrite a file
archivers:the available create and extract archives (e.g. tar, gzip etc.)
parents(hash_)[source]

Return part of dirs tree from required dir up to the root dir. Raises DirNotFoundError, FileNotFoundError, PermissionDeniedError.

paste(volume, hash_src, dst, rm_src=False)[source]

Paste files. Raises exception if the operation fails.

path(hash_)[source]

Return file path related to the volume root.

put_contents(hash_, content)[source]

Put content in text file and return file info.

remove(path, force=False)[source]

Remove file/ recursive remove dir

removed()[source]

Return a list of moved/overwrited files.

rename(hash_, name)[source]

Rename file and return file info.

reset_removed()[source]

Clean removed files list.

resize(hash_, width, height, x, y, mode='resize', bg='', degree=0)[source]

Resize image. Raises PermissionDeniedError if the command is disabled or there is no file ‘write’ permission. Raises NotAnImageError if file is not an image.

rm(hash_)[source]

Remove file/dir. Raises PermisionDeniedError if ‘rm’ command is disabled.

scandir(hash_)[source]

Return directory contents. Raises a DirNotFoundError if hash_ is not a valid dir, or a PermissionDenied Error if the user cannot access the data.

search(q)[source]

Search files based on query q.

set_mimes_filter(mimes)[source]

Set mimetypes allowed to display to the client.

size(hash_)[source]

Return file size or total directory size.

stat(path)[source]

Return fileinfo. Raises os.error if the path is invalid

tmb(hash_)[source]

Create thumbnail for the required file hash_ and return its name. It will raise an Exception on fail.

tree(hash_='', deep=0, exclude='')[source]

Return sub-directories for the required folder has_, or raise an Exception.

unmount()[source]

The unmunt method is currently not used, but in the future it might be useful to some drivers.

upload(uploaded_file, hash_dst)[source]

Save uploaded file. On success return a list of file stat information. If an already existing file was replaced, it will be added to the removed file list and can be retrieved using the elfinder.volumes.base.ElfinderVolumeDriver.remove() method.

upload_max_size()[source]

Return the upload max size.

ElfinderVolumeStorage

ElfinderVolumeLocalFileSystem

class elfinder.volumes.filesystem.ElfinderVolumeLocalFileSystem[source]

elFinder driver for local filesystem. It implements the elfinder.volumes.base.ElfinderVolumeDriver API.

_archive(dir_, files, name, arc)[source]

Create archive and return its path

_basename(path)[source]

Return file name. See elfinder.volumes.base.ElfinderVolumeDriver._basename().

_configure()[source]

Configure after successful mount.

_copy(source, target_dir, name)[source]

Copy file into another file

_dimensions(path)[source]

Return object width and height Ususaly used for images, but can be realize for video etc... Can Raise a NotAnImageError

_dirname(path)[source]

Return parent directory path. See elfinder.volumes.base.ElfinderVolumeDriver._dirname().

_extract(path, archiver)[source]

Extract files from archive.

_fclose(fp, **kwargs)[source]

Close opened file

Recursive symlinks search

_fopen(path, mode='rb')[source]

Open file and return file pointer

_get_available_name(dir_, name, ext, i)[source]

Get an available name for this file name.

_get_contents(path)[source]

Get file contents

_join_path(path1, path2)[source]

Join two paths and return full path. If the latter path is absolute, return it.

See elfinder.volumes.base.ElfinderVolumeDriver._join_path().

_mimetype(path)[source]

Attempt to read the file’s mimetype

_mkdir(path, mode=None)[source]

Create dir and return created dir path or raise an os.error

_mkfile(path, name)[source]

Create file and return it’s path or False on failed

_move(source, target_dir, name)[source]

Move file into another parent dir. Return new file path or raise os.error.

_normpath(path)[source]

Return normalized path. See elfinder.volumes.base.ElfinderVolumeDriver._normpath().

_openimage(path)[source]

Open an image file.

_put_contents(path, content)[source]

Write a string to a file.

Return symlink target file

_remove_unaccepted_files(path)[source]

Recursively delete unaccepted files based on their mimetype or accepted name and return files in the directory.

_rmdir(path)[source]

Remove dir

_save(fp, dir_, name)[source]

Create new file and write into it from file pointer. Return new file path or raise an Exception.

_save_uploaded(uploaded_file, dir_, name, **kwargs)[source]

Save the django UploadedFile object and return its new path

_saveimage(im, path, form)[source]

Save an image file

_scandir(path)[source]

Return files list in directory. The ‘.’ and ‘..’ special directories are omitted.

_stat(path)[source]

Return stat for given path. See elfinder.volumes.base.ElfinderVolumeDriver._stat().

_subdirs(path)[source]

Return True if path is dir and has at least one childs directory

Create symlink

Remove file

mount(opts)[source]

Override the original mount method so that path and URL settings point to the MEDIA_ROOT and MEDIA_URL Django settings by default.