msaUtils Module¶
.file
¶
Attributes¶
Classes¶
FileDelete ¶
File Delete Class
PARAMETER | DESCRIPTION |
---|---|
uid |
str , the GUID of the file
TYPE:
|
root_path |
str, dir name of the file
TYPE:
|
uploads_dir |
str, the folder the file was uploaded to.
TYPE:
|
FileExtNotAllowed ¶
Bases: ServerHTTPException
raise when the upload file ext not allowed
FileMaxSizeLimit ¶
Bases: ServerHTTPException
raise when the upload file exceeds the max size
FileUpload ¶
FileUpload Class
PARAMETER | DESCRIPTION |
---|---|
filesize |
int, size in bytes
TYPE:
|
root_path |
str = dirname of the file
TYPE:
|
uploads_dir |
str = "data/uploads", where to store the file
TYPE:
|
not_allow_extensions |
Optional[List[str]] = None, exclude file extensions from upload ability
TYPE:
|
max_size |
int = 150000000, max allowed filesize in bytes for upload
TYPE:
|
createUIDSubFolders |
bool = False, if enabled the system creates Subfolders by the UID
TYPE:
|
Attributes¶
Functions¶
__init__ ¶
__init__(
filesize: int,
root_path: str = os.path.join(
os.path.dirname(__file__)
),
uploads_dir: str = "data/uploads",
not_allow_extensions: Optional[List[str]] = None,
max_size: int = 150000000,
createUIDSubFolders: bool = False,
)
save_file
async
¶
Save the file
PARAMETER | DESCRIPTION |
---|---|
filename |
the name of the file it should be saved uner
TYPE:
|
ufile |
UploadFile instance of the file to save
TYPE:
|
upload
async
¶
upload the file
PARAMETER | DESCRIPTION |
---|---|
chunk_size |
1024 * 1024 * 50 = 50 megabytes
DEFAULT:
|
file |
The UploadFile instance of the file for upload.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
filename
|
str complete filename after created safe version
TYPE:
|
InvalidResource ¶
Bases: ServerHTTPException
raise when has invalid resource
NoSuchFieldFound ¶
Bases: ServerHTTPException
raise when no such field for the given
Functions¶
checkIfFileIsArchive
async
¶
Check if File is an Archive like zip or tar
createMSAFile
async
¶
Create an MSAFile Instance for the provided file
PARAMETER | DESCRIPTION |
---|---|
file |
is the UploadFile
TYPE:
|
up |
is the FileUpload Instance
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mf
|
New MSAFile instance.
TYPE:
|
createMSAFileFromUnpacked
async
¶
Create an MSAFile Instance for a file from an archive, and keep them under one group by the process_uid
PARAMETER | DESCRIPTION |
---|---|
filepath |
str of the file path
TYPE:
|
process_uid |
str of the group process id (GUID)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mf
|
New MSAFile instance.
TYPE:
|
get_all_dirs
async
¶
Get all Directories of a specific root path
PARAMETER | DESCRIPTION |
---|---|
path |
The root path to wlk through
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
result
|
The list of directory names
TYPE:
|
get_all_dirs_with_subdirs
async
¶
Get all Directories which have a specific set of Sub Dirs
PARAMETER | DESCRIPTION |
---|---|
path |
The root path to wlk through
TYPE:
|
subdirs |
a set of subdir names which need to be found to add the dirs
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
result
|
The list of directory names
TYPE:
|
load_bytes_from_file
async
¶
Load a bytes/binary content from a file
PARAMETER | DESCRIPTION |
---|---|
path_file_name |
The pathfilename to load the content from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The content of the file
TYPE:
|
load_text_from_file
async
¶
Load a text content from a file
PARAMETER | DESCRIPTION |
---|---|
path_file_name |
The pathfilename to load the content from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The content of the file
TYPE:
|
save_bytes_to_file
async
¶
Saves a bytes content to file
PARAMETER | DESCRIPTION |
---|---|
path_file_name |
The pathfilename to save the content to
TYPE:
|
binary_content |
The bytes content to store inside the file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
save_text_to_file
async
¶
Saves a str content to file
PARAMETER | DESCRIPTION |
---|---|
path_file_name |
The pathfilename to save the content to
TYPE:
|
text_content |
The str content to store inside the file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
secure_filename ¶
Pass it a filename, and it will return a secure version of it. This
filename can then safely be stored on a regular file system and passed
to :func:os.path.join
. The filename returned is an ASCII only string
for maximum portability.
On Windows systems the function also makes sure that the file is not
named after one of the special device files.
Example
The function might return an empty filename. It's your responsibility to ensure that the filename is unique and that you abort or generate a random filename if the function returned an empty one. .. versionadded:: 0.5
PARAMETER | DESCRIPTION |
---|---|
filename |
the filename to secure
TYPE:
|
Created: September 24, 2022