mirror of
https://github.com/natankeddem/bale.git
synced 2026-05-02 13:42:55 +00:00
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from typing import Any, List
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from copy import deepcopy
|
|
import time
|
|
|
|
|
|
@dataclass(kw_only=True)
|
|
class Result:
|
|
name: str = ""
|
|
command: str = ""
|
|
return_code: int = 0
|
|
stdout_lines: List[str] = field(default_factory=list)
|
|
stderr_lines: List[str] = field(default_factory=list)
|
|
terminated: bool = False
|
|
data: Any = None
|
|
failed: bool = False
|
|
trace: str = ""
|
|
cached: bool = False
|
|
status: str = "success"
|
|
timestamp: float = field(default_factory=time.time)
|
|
|
|
@property
|
|
def date(self) -> str:
|
|
return datetime.fromtimestamp(self.timestamp).strftime("%Y/%m/%d")
|
|
|
|
@property
|
|
def time(self) -> str:
|
|
return datetime.fromtimestamp(self.timestamp).strftime("%H:%M:%S")
|
|
|
|
@property
|
|
def stdout(self) -> str:
|
|
return "".join(self.stdout_lines)
|
|
|
|
@property
|
|
def stderr(self) -> str:
|
|
return "".join(self.stderr_lines)
|
|
|
|
def to_dict(self):
|
|
d = deepcopy(self.__dict__)
|
|
d["date"] = self.date
|
|
d["time"] = self.time
|
|
d["stdout"] = self.stdout
|
|
d["stderr"] = self.stderr
|
|
return d
|
|
|
|
def from_dict(self, d):
|
|
self.name = d["name"]
|
|
self.command = d["command"]
|
|
self.return_code = d["return_code"]
|
|
self.stdout_lines = d["stdout_lines"]
|
|
self.stderr_lines = d["stderr_lines"]
|
|
self.terminated = d["terminated"]
|
|
self.data = d["data"]
|
|
self.failed = d["failed"]
|
|
self.trace = d["trace"]
|
|
self.cached = d["cached"]
|
|
self.status = d["status"]
|
|
self.timestamp = d["timestamp"]
|
|
return self
|