file_obj
File Object Utility.
This module provides a utility class, FileObj, that represents a file object with
various properties and methods. It allows for easy manipulation and management of file
paths, file names, and file extensions.
Attributes
Classes
FileObj
Bases: BaseModel
Represents a file object with various properties and methods.
Attributes
abs_path
property
Returns the absolute path of the file.
:return: The absolute path of the file. :rtype: str
file_name
property
Returns the file name by joining the file fields with the filename field separator.
Returns:
-
str(str) –The file name.
file_name_full
property
Returns the full file name including the file extension.
Returns:
-
str(str) –The full file name.
filename_field_sep
class-attribute
instance-attribute
filename_field_sep: str = DEFAULT_FILENAME_FIELD_SEP
path
property
Returns the full path of the file, including the directory part and the file name.
Returns:
-
str(str) –The full path of the file.
Functions
append_field
append_field(value: str) -> FileObj
Appends a field value to the file object.
Parameters:
-
value(str) –The value to append.
Returns:
-
FileObj(FileObj) –The updated FileObj instance.
Raises:
-
ValueError–If the field value contains the filename field separator.
append_timestamp_field
append_timestamp_field(**kwargs) -> FileObj
Appends a timestamp field to the file_fields list.
Parameters:
-
**kwargs–Additional keyword arguments to pass to the
gen_timestampfunction.
Returns:
-
FileObj–FileObj
clone
clone(**kwargs) -> FileObj
Returns a clone of the current FileObj instance.
Returns:
-
FileObj(FileObj) –The cloned FileObj instance.
from_parts
classmethod
from_parts(*args, **kwargs) -> FileObj
Create a FileObj instance from the given parts.
Parameters:
-
args–Path parts to be joine before initializing the FileObj instance.
Returns:
-
FileObj(FileObj) –The created FileObj instance.
from_path
classmethod
from_path(
path: str,
filename_field_sep: str = DEFAULT_FILENAME_FIELD_SEP,
**kwargs
) -> FileObj
Create a FileObj instance from a given file path.
Individual fields of the object can be overridden via kwargs
Parameters:
-
path(str) –The file path.
-
filename_field_sep(str, default:DEFAULT_FILENAME_FIELD_SEP) –The separator used to split the file name into fields. Defaults to DEFAULT_FILENAME_FIELD_SEP.
Returns:
-
FileObj(FileObj) –The created FileObj instance.
update_field
update_field(value: str, field: int) -> FileObj
Update the value of a field in the FileObj object.
Parameters:
-
value(str) –The new value for the field.
-
field(int) –The index of the field to be updated.
Returns:
-
FileObj(FileObj) –The updated FileObj object.
Raises:
-
ValueError–If the field value contains the filename field separator.