Back to bricks list
Introduction Version

File

RESOURCE
Typing name :  RESOURCE.gws_core.File Brick :  gws_core
Parent :
Fs node

Resource that represents a file in the system.

Technical notes:

/!\ The class that extend file can only have a path and file_store_id attributes. Other attributes will not be provided when creating the resource.

Views

DEFAULT VIEWDefault view
View the file with automatic view
VIEW AS JSON
View the complete resource as json
VIEW FILE CONTENT
View the file content as string

Attributes

file_store_id: stris_symbolic_link: boolname: strpath: strstyle: TypingStyletags: TagListtechnical_info: TechnicalInfoDictuid: str

Functions

__INIT__

Create a new FSNode

Parameters:
NameTypeDefault valueDescription
pathstr '' Absolute path to the file, defaults to "" , optional
ADD_TECHNICAL_INFO

Add technical information on the resource. Technical info are useful to set additional information on the resource.

Parameters:
NameTypeDefault valueDescription
technical_infoTechnicalInfo Technical information to add (key, value)
CHECK_IF_EXISTS
CHECK_RESOURCE

You can redefine this method to define custom logic to check this resource. If there is a problem with the resource, return a string that define the error, otherwise return None This method is called on output resources of a task. If there is an error returned, the task will be set to error and next proceses will not be run. It is also call when uploading a resource (usually for files or folder), if there is an error returned, the resource will not be uploaded

Return type:
Optional
CLONE

Clone the resource to create a new instance with a new id. It copies the RFields.

Return type:
ResourceType
COPY_TO_DIRECTORY

Copy the node to the directory and keep the same base name

Parameters:
NameTypeDefault valueDescription
destinationstr The destination directory
Return type:
str
COPY_TO_PATH

Copy the file or folder to the destination and rename the base name

Parameters:
NameTypeDefault valueDescription
destinationstr Complete path to the destination
Return type:
str
DETECT_FILE_ENCODING

Detect the encoding of the file using charset-normalizer

Parameters:
NameTypeDefault valueDescription
default_encodingstr utf-8 Default encoding to use if the encoding is not detected, defaults to 'utf-8' , optional
Return type:
str
EXISTS
Return type:
bool
GET_BASE_NAME

Get the name of the file or folder without the path

Return type:
str
GET_DEFAULT_NAME

You can redefine this method to set a name of the resource. When saving the resource the name will be saved automatically This can be useful to distinguish this resource from another one or to search for the resource

Return type:
str
GET_DEFAULT_VIEW

Get the default view of the file.

Parameters:
NameTypeDefault valueDescription
pageint 1 Page number, defaults to 1 , optional
Return type:
View
GET_MODEL_ID

Get the id of the resource model in the database. It is provided by the system for input resources of a task.

Return type:
str
GET_NAME
Return type:
str
GET_NAME_OR_DEFAULT

Get the name of the resource or the default name if the name is None

Return type:
str
GET_SIZE
Return type:
int
GET_TECHNICAL_INFO

Get the technical information of the resource

Parameters:
NameTypeDefault valueDescription
keystr Key of the technical information
Return type:
TechnicalInfo
GET_VIEW_BY_LINES
Parameters:
NameTypeDefault valueDescription
start_lineint 1
Return type:
SimpleTextView
INIT

This can be overwritten to perform custom initialization of the resource. This method is called after the init (constructor) of the resource. The values of RFields are set when this method is called.

IS_AUDIO
IS_CSV
IS_EMPTY
Return type:
bool
IS_IMAGE
IS_JPG
IS_JSON
IS_PNG
IS_READABLE
Return type:
bool
IS_TXT
OPEN

Open the file

Parameters:
NameTypeDefault valueDescription
modestr Mode of the file
encodingstr Encoding used to open the file. if none the encoding is automatically detected with charset-normalizer, defaults to none , optional
Return type:
Any
READ

Read the file

Parameters:
NameTypeDefault valueDescription
sizeint -1 Size of the file to read, defaults to -1 , optional
encodingstr Encoding used to read the file. if none the encoding is automatically detected with charset-normalizer, defaults to none , optional
modestr r+t Mode of the file, defaults to 'r+t' , optional
Return type:
AnyStr
READ_PART

Read a part of the file

Parameters:
NameTypeDefault valueDescription
from_lineint 0 Start line, defaults to 0 , optional
to_lineint 10 End line (excluded), defaults to 10 , optional
encodingstr Encoding used to read the file. if none the encoding is automatically detected with charset-normalizer, defaults to none , optional
modestr r+t Mode of the file, defaults to 'r+t' , optional
Return type:
str
WRITE

Write data to the file

Parameters:
NameTypeDefault valueDescription
datastr Data to write
encodingstr Encoding used to write the file. if none the encoding is automatically detected with charset-normalizer, defaults to none , optional
modestr a+t Mode of the file, defaults to 'a+t' , optional
CLASSNAME - @classmethod

Returns the name of the class

Parameters:
NameTypeDefault valueDescription
slugifybool False True to slugify the class name if true, defaults to false , optional
snakefybool False True to snakefy the class name if true, defaults to false , optional
replace_uppercasebool False Replace upper cases by "-" if true, defaults to false , optional
Return type:
str
COPY_STYLE - @classmethod

Copy the style of the resource with the possibility to override some properties. Useful when settings the style for a task based on the resource style.

Parameters:
NameTypeDefault valueDescription
icon_technical_namestr Technical name of the icon if provided, the icon_type must also be provided, defaults to none , optional
icon_typeTypingIconType Type of the icon if provided, the icon_technical_name must also be provided, defaults to none , optional
background_colorstr Background color, defaults to none , optional
icon_colorTypingIconColor Icon color, defaults to none , optional
Return type:
TypingStyle
DECORATED_METHOD_NAMES - @classmethod
Parameters:
NameTypeDefault valueDescription
decorator_nameAny
FULL_CLASSNAME - @classmethod

Returns the full name of the class

Parameters:
NameTypeDefault valueDescription
slugifybool False Slugify the returned class name if true, defaults to false , optional
snakefybool False Snakefy the returned class name if true, defaults to false ``
Return type:
str
GET_HUMAN_NAME - @classmethod

Get the human name of the resource

Return type:
str
GET_SHORT_DESCRIPTION - @classmethod

Get the short description of the resource

Return type:
str
GET_TYPING_NAME - @classmethod

Get the typing name of the resource

Return type:
str
INHERITORS - @classmethod

Get all the classes that inherit this class

Return type:
List
METHOD_NAMES - @classmethod

Returns the list of the methods

Return type:
List
MODULE_NAME - @classmethod

Returns the module name of the class

Return type:
str
PROPERTY_METHOD_NAMES - @classmethod
PROPERTY_NAMES - @classmethod

Retrieves the property names

Parameters:
NameTypeDefault valueDescription
instancetype The s of the properties to retrieve. set `none` to retrieve all. `type` or `union[type]`
excludetype
Return type:
List