Coretex
coretex.entities.task_run.artifact.Artifact Class Reference
Inheritance diagram for coretex.entities.task_run.artifact.Artifact:
coretex.codable.codable.Codable

Public Member Functions

Path localFilePath (self)
 
bool isDirectory (self)
 
bool isFile (self)
 
bool download (self)
 
List[Self] fetchAll (cls, int taskRunId, Optional[str] path=None, bool recursive=False)
 
- Public Member Functions inherited from coretex.codable.codable.Codable
Dict[str, Any] encode (self)
 
None onDecode (self)
 
Self decode (cls, Dict[str, Any] encodedObject)
 

Detailed Description

    Artifact class represents a single result of a run\n
    Result can be file of any kind

    Properties
    ----------
    artifactType : ArtifactType
        type of Artifact
    remoteFilePath : str
        path of Artifact on Coretex
    size : Optional[int]
        size of Artifact in bytes (not required)
    mimeType : str
        mimeType of Artifact
    timestamp : int
        current timestamp
    taskRunId : int
        id of run

Definition at line 39 of file artifact.py.

Member Function Documentation

◆ download()

bool coretex.entities.task_run.artifact.Artifact.download (   self)
    Downloads Artifact from Coretex.ai

    Returns
    -------
    bool -> False if response has failed, True otherwise

Definition at line 145 of file artifact.py.

145  def download(self) -> bool:
146  """
147  Downloads Artifact from Coretex.ai
148 
149  Returns
150  -------
151  bool -> False if response has failed, True otherwise
152  """
153 
154  params = {
155  "model_queue_id": self.taskRunId,
156  "path": self.remoteFilePath
157  }
158 
159  return not networkManager.download("artifact/download-file", str(self.localFilePath), params).hasFailed()
160 

◆ fetchAll()

List[Self] coretex.entities.task_run.artifact.Artifact.fetchAll (   cls,
int  taskRunId,
Optional[str]   path = None,
bool   recursive = False 
)
    Fetch all Artifacts from Coretex.ai for the specified run

    Parameters
    ----------
    taskRunId : int
        id of run
    path : Optional[str]
        local path where u want to store fetched Artifacts
    recursive : bool
        True if you want list to be sorted recursively, False otherwise

Definition at line 162 of file artifact.py.

162  def fetchAll(cls, taskRunId: int, path: Optional[str] = None, recursive: bool = False) -> List[Self]:
163  """
164  Fetch all Artifacts from Coretex.ai for the specified run
165 
166  Parameters
167  ----------
168  taskRunId : int
169  id of run
170  path : Optional[str]
171  local path where u want to store fetched Artifacts
172  recursive : bool
173  True if you want list to be sorted recursively, False otherwise
174  """
175 
176  params: Dict[str, Any] = {
177  "model_queue_id": taskRunId,
178  }
179 
180  if path is not None:
181  params["path"] = path
182 
183  response = networkManager.get("artifact/list-contents", params)
184  if response.hasFailed():
185  return []
186 
187  artifacts = [cls.decode(element) for element in response.getJson(list)]
188 
189  for artifact in artifacts:
190  artifact.taskRunId = taskRunId
191 
192  if recursive and artifact.isDirectory:
193  artifacts.extend(
194  cls.fetchAll(taskRunId, artifact.remoteFilePath)
195  )
196 
197  return artifacts

◆ isDirectory()

bool coretex.entities.task_run.artifact.Artifact.isDirectory (   self)
    Returns
    -------
    bool -> True if Artifact type is directory

Definition at line 81 of file artifact.py.

81  def isDirectory(self) -> bool:
82  """
83  Returns
84  -------
85  bool -> True if Artifact type is directory
86  """
87 
88  return self.artifactType == ArtifactType.directory
89 

◆ isFile()

bool coretex.entities.task_run.artifact.Artifact.isFile (   self)
    Returns
    -------
    bool -> True if Artifact type is file

Definition at line 91 of file artifact.py.

91  def isFile(self) -> bool:
92  """
93  Returns
94  -------
95  bool -> True if Artifact type is file
96  """
97 
98  return self.artifactType == ArtifactType.file
99 

◆ localFilePath()

Path coretex.entities.task_run.artifact.Artifact.localFilePath (   self)
    Represents the local path of the Artifact

    Returns
    -------
    Path -> local path to Artifact

Definition at line 69 of file artifact.py.

69  def localFilePath(self) -> Path:
70  """
71  Represents the local path of the Artifact
72 
73  Returns
74  -------
75  Path -> local path to Artifact
76  """
77 
78  return folder_manager.getArtifactsFolder(self.taskRunId) / self.remoteFilePath
79 

The documentation for this class was generated from the following file: