mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[models] Further adjustments to new dataclasses
This commit is contained in:
parent
dc381cacb0
commit
1fe0dab78b
|
@ -1,7 +1,8 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
from enum import Flag, auto
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Union
|
from typing import Optional
|
||||||
|
|
||||||
from .manifest import ManifestComparison
|
from .manifest import ManifestComparison
|
||||||
|
|
||||||
|
@ -11,8 +12,8 @@ class SharedMemorySegment:
|
||||||
"""
|
"""
|
||||||
Segment of the shared memory used for one Chunk
|
Segment of the shared memory used for one Chunk
|
||||||
"""
|
"""
|
||||||
offset: int = 0
|
offset: int
|
||||||
end: int = 1024 * 1024
|
end: int
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
|
@ -24,24 +25,19 @@ class DownloaderTask:
|
||||||
"""
|
"""
|
||||||
Task submitted to the download worker
|
Task submitted to the download worker
|
||||||
"""
|
"""
|
||||||
url: Union[str, None] = None
|
url: str
|
||||||
chunk_guid: Union[int, None] = None
|
chunk_guid: int
|
||||||
shm: Union[SharedMemorySegment, None] = None
|
shm: SharedMemorySegment
|
||||||
kill: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DownloaderTaskResult:
|
class DownloaderTaskResult(DownloaderTask):
|
||||||
"""
|
"""
|
||||||
Result of DownloaderTask provided by download workers
|
Result of DownloaderTask provided by download workers
|
||||||
"""
|
"""
|
||||||
success: bool
|
success: bool
|
||||||
chunk_guid: int
|
size_downloaded: Optional[int] = None
|
||||||
shm: SharedMemorySegment
|
size_decompressed: Optional[int] = None
|
||||||
url: str
|
|
||||||
size: Union[int, None] = None
|
|
||||||
compressed_size: Union[int, None] = None
|
|
||||||
time_delta: Union[int, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -55,7 +51,18 @@ class ChunkTask:
|
||||||
# Whether this chunk can be removed from memory/disk after having been written
|
# Whether this chunk can be removed from memory/disk after having been written
|
||||||
cleanup: bool = False
|
cleanup: bool = False
|
||||||
# Path to the file the chunk is read from (if not from memory)
|
# Path to the file the chunk is read from (if not from memory)
|
||||||
chunk_file: Union[str, None] = None
|
chunk_file: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class TaskFlags(Flag):
|
||||||
|
NONE = 0
|
||||||
|
OPEN_FILE = auto()
|
||||||
|
CLOSE_FILE = auto()
|
||||||
|
DELETE_FILE = auto()
|
||||||
|
CREATE_EMPTY_FILE = auto()
|
||||||
|
RENAME_FILE = auto()
|
||||||
|
RELEASE_MEMORY = auto()
|
||||||
|
SILENT = auto()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -64,20 +71,9 @@ class FileTask:
|
||||||
A task describing some operation on the filesystem
|
A task describing some operation on the filesystem
|
||||||
"""
|
"""
|
||||||
filename: str
|
filename: str
|
||||||
# just create a 0-byte file
|
flags: TaskFlags
|
||||||
empty: bool = False
|
|
||||||
open: bool = False
|
|
||||||
close: bool = False
|
|
||||||
rename: bool = False
|
|
||||||
# Deletes the file, if rename is true, this will remove an existing file with the target name
|
|
||||||
delete: bool = False
|
|
||||||
silent: bool = False
|
|
||||||
# If rename is true, this is the name of the file to be renamed
|
# If rename is true, this is the name of the file to be renamed
|
||||||
temporary_filename: Union[str, None] = None
|
old_file: Optional[str] = None
|
||||||
|
|
||||||
@property
|
|
||||||
def is_reusing(self):
|
|
||||||
return self.temporary_filename is not None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -86,52 +82,27 @@ class WriterTask:
|
||||||
Task for FileWriter worker process, describing an operation on the filesystem
|
Task for FileWriter worker process, describing an operation on the filesystem
|
||||||
"""
|
"""
|
||||||
filename: str
|
filename: str
|
||||||
|
flags: TaskFlags
|
||||||
|
|
||||||
chunk_offset: int = 0
|
chunk_offset: int = 0
|
||||||
chunk_size: int = 0
|
chunk_size: int = 0
|
||||||
chunk_guid: Union[int, None] = None
|
chunk_guid: Optional[int] = None
|
||||||
|
|
||||||
# Just create an empty file
|
|
||||||
empty: bool = False
|
|
||||||
# Whether shared memory segment shall be released back to the pool on completion
|
# Whether shared memory segment shall be released back to the pool on completion
|
||||||
release_memory: bool = False
|
shared_memory: Optional[SharedMemorySegment] = None
|
||||||
shared_memory: Union[SharedMemorySegment, None] = None
|
|
||||||
|
|
||||||
# File to read old chunk from, disk chunk cache or old game file
|
# File to read old chunk from, disk chunk cache or old game file
|
||||||
old_file: Union[str, None] = None
|
old_file: Optional[str] = None
|
||||||
cache_file: Union[str, None] = None
|
cache_file: Optional[str] = None
|
||||||
|
|
||||||
open: bool = False
|
|
||||||
close: bool = False
|
|
||||||
delete: bool = False
|
|
||||||
# Do not log deletion failures
|
|
||||||
silent: bool = False
|
|
||||||
|
|
||||||
rename: bool = False
|
|
||||||
# Filename to rename from
|
|
||||||
old_filename: Union[str, None] = None
|
|
||||||
|
|
||||||
# Instruct worker to terminate
|
|
||||||
kill: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WriterTaskResult:
|
class WriterTaskResult(WriterTask):
|
||||||
"""
|
"""
|
||||||
Result from the FileWriter worker
|
Result from the FileWriter worker
|
||||||
"""
|
"""
|
||||||
success: bool
|
success: bool = False
|
||||||
filename: Union[str, None] = None
|
|
||||||
size: int = 0
|
size: int = 0
|
||||||
chunk_guid: Union[int, None] = None
|
|
||||||
|
|
||||||
shared_memory: Union[SharedMemorySegment, None] = None
|
|
||||||
release_memory: bool = False
|
|
||||||
closed: bool = False
|
|
||||||
time_delta: Union[float, None] = None
|
|
||||||
|
|
||||||
# Worker terminated, instructs results handler to also stop
|
|
||||||
kill: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -144,7 +115,7 @@ class UIUpdate:
|
||||||
write_speed: float
|
write_speed: float
|
||||||
read_speed: float
|
read_speed: float
|
||||||
memory_usage: float
|
memory_usage: float
|
||||||
current_filename: Union[str, None] = None
|
current_filename: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -167,7 +138,7 @@ class AnalysisResult:
|
||||||
added: int = 0
|
added: int = 0
|
||||||
changed: int = 0
|
changed: int = 0
|
||||||
unchanged: int = 0
|
unchanged: int = 0
|
||||||
manifest_comparison: Union[ManifestComparison, None] = None
|
manifest_comparison: Optional[ManifestComparison] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -175,5 +146,13 @@ class ConditionCheckResult:
|
||||||
"""
|
"""
|
||||||
Result of install condition checks
|
Result of install condition checks
|
||||||
"""
|
"""
|
||||||
failures: Union[list, None] = None
|
failures: Optional[set] = None
|
||||||
warnings: Union[list, None] = None
|
warnings: Optional[set] = None
|
||||||
|
|
||||||
|
|
||||||
|
class TerminateWorkerTask:
|
||||||
|
"""
|
||||||
|
Universal task to signal a worker to exit
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue