name | arguments | returns |
set_media_folder | cls, path_name: str | None |
:param path_name: Location where the media for Content Items is stored, including the final "/"
EXAMPLE on Windows: "D:/media/"
(notice the forward slashes, even on Windows)
:return: None
|
name | arguments | returns |
lookup_file_path | cls, schema_code=None, class_name=None, thumb=False | str |
Return the full file path, including the final "/" of media of
a particular type, identified by the schema_code argument
TODO: allow media files to have a variety of locations - not just a standard
one based on their type
:param schema_code: String identifier used by the various plugins
:param class_name: An alternate way to identify the type of the media file.
If both schema_code and class_name are specified,
class_name prevails
:param thumb: If True, then the "thumbnail" version is returned
(only applicable to some media types, such as images)
:return: EXAMPLES on Windows:
"D:/media/documents/"
"D:/media/images/resized/"
|
name | arguments | returns |
get_from_text_file | cls, path: str, filename: str, encoding="latin-1" | str |
Read in and return the contents of the specified TEXT file.
Note: 'utf8' encoding at times led to problems.
More info: https://stackoverflow.com/questions/5552555/unicodedecodeerror-invalid-continuation-byte
:param path: String that must include a final "/", containing the full path of the file
EXAMPLE on Windows:
"D:/media/" (notice the forward slashes, even on Windows)
:param filename: EXCLUSIVE of path
:param encoding: A string such as "latin-1" (aka "iso-8859-1") or "utf8"
:return: The contents of the text file, using 'latin-1' encoding
|
name | arguments | returns |
get_from_binary_file | cls, path: str, filename: str | bytes |
Read in and return the contents of the specified BINARY file
:param path: String that must include a final "/", containing the full path of the file
EXAMPLE on Windows: "D:/media/" (notice the forward slashes, even on Windows)
:param filename: EXCLUSIVE of path. EXAMPLE: "my pic.jpg"
:return: The contents of the binary file
|
name | arguments | returns |
get_binary_content | cls, uri :str, th | (str, bytes) |
Fetch and return the contents of a media item stored on a local file.
In case of error, raise an Exception
:param uri: String identifier for a media item
:param th: If not None, then the thumbnail version is returned (only
applicable to images).
If the thumbnail version is not found, but the full-size image
is present, create and save a thumbnail file, prior to
returning the contents of the newly-created file
:return: The pair (filename suffix, binary data in the file)
|
name | arguments | returns |
save_into_file | cls, contents: str, filename: str | None |
Save the given data into the specified file in the class-wide media folder. UTF8 encoding is used.
In case of error, detailed Exceptions are raised
:param contents: String to store into the file
:param filename: EXCLUSIVE of file path
:return: None. In case of errors, detailed Exceptions are raised
|
name | arguments | returns |
delete_media_file | cls, basename: str, suffix: str, schema_code, thumbs=False | bool |
Delete the specified media file, assumed in a standard location
:param basename: File name, exclusive of path and of suffix
:param suffix: String such as "htm" (don't include the dot!)
:param schema_code:
:param thumbs:
:return: True if successful, or False otherwise
|
name | arguments | returns |
delete_file | cls, fullname: str | bool |
Delete the specified file
:param fullname: Full name of the file to delete, including its path
:return: True if successful, or False if not found
|
name | arguments | returns |
get_mime_type | cls, suffix :str | str |
Return the appropriate MIME type for file content type assumed from the
filename extension, assuming normal conventions are being followed
:param suffix: A string with a filename's suffix (i.e. the "file extension type".)
EXAMPLES: "jpg" or "PDF"
:return: A string describing the MIME type for files of that particular type
|
name | arguments | returns |
save_thumbnail | cls, src_folder: str, filename: str, save_to_folder: str,
src_width: int, src_height: int | None |
Make a thumbnail of the specified image, and save it in a file.
The "th" thumbnail format is being followed.
:param src_folder: Full path of folder with the file to resize. It MUST end with "/"
EXAMPLE (on Windows): "D:/Docs/Brain Annex/media/"
:param filename: Name of file to resize. EXAMPLE: "my image.jpg"
:param save_to_folder: Full path of folder where to save the resized file. It MUST end with "/"
EXAMPLE (on Windows): "D:/Docs/Brain Annex/media/resized/"
:param src_width: Pixel width of the original image
:param src_height: Pixel height of the original image
:return: None. In case of error, an Exception is raised
|
name | arguments | returns |
scale_down_horiz | cls, src_folder: str, filename: str, save_to_folder: str,
src_width: int, src_height: int, target_width: int | None |
Resize an image to the target WIDTH, and save it in a file.
:param src_folder: Full path of folder with the file to resize. It MUST end with "/"
EXAMPLE (on Windows): "D:/Docs/Brain Annex/media/"
:param filename: Name of file to resize. EXAMPLE: "my image.jpg"
:param save_to_folder: Full path of folder where to save the resized file. It MUST end with "/"
EXAMPLE (on Windows): "D:/Docs/Brain Annex/media/resized/"
:param src_width: Pixel width of the original image
:param src_height: Pixel height of the original image
:param target_width: Desired pixel width of the resized image
:return: None. In case of error, an Exception is raised
|
name | arguments | returns |
get_image_size | cls, source_full_name | (int, int) |
Return the size of the given image.
:param source_full_name: EXAMPLE (on Windows): "D:/Docs/Brain Annex/media/resized/my image.jpg"
:return: The pair (width, height) with the image dimensions in pixels. In case of error, an Exception is raised
|
name | arguments | returns |
process_uploaded_image | cls, media_folder :str, basename :str, suffix :str | dict |
If possible, obtain the size of the image, resize it to a thumbnail,
save the thumbnail in the "resized/" subfolder of the specified media folder;
not all images (such as SVG's) can be resized.
Return a dictionary of additional image-specific properties that will go in the database.
:param media_folder:Name of the folder (including the final "/") where the media files are located.
The resized version will go in a "resized" subfolder of it.
EXAMPLE (on Windows): "D:/Docs/media/
:param basename: EXAMPLE: "my image"
:param suffix: EXAMPLE: "jpg" . It's ok to be an empty string
:return: A dictionary of extra properties to store in database, containing some or all of
the following keys: "caption", "width", "height"
|
name | arguments | returns |
describe_image | cls, source_full_name | None |
Print out some info about the given image:
the file format, the pixel format, the image size and (if any) the color palette
:param source_full_name: EXAMPLE (on Windows): "D:/Docs/media/resized/my image.jpg"
:return: None. In case of error, an Exception is raised
|