retuve.classes.general

Other general classes that are used in the project.

 1# Copyright 2024 Adam McArthur
 2#
 3# Licensed under the Apache License, Version 2.0 (the "License");
 4# you may not use this file except in compliance with the License.
 5# You may obtain a copy of the License at
 6#
 7#     http://www.apache.org/licenses/LICENSE-2.0
 8#
 9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16Other general classes that are used in the project.
17"""
18
19
20class RecordedError:
21    """
22    Class for storing errors as they occur during processing.
23
24    Can be critical or non-critical, and frame-dependent or not.
25    """
26
27    def __init__(self):
28        self.errors = []
29        self.frame_dependent_errors = {}
30        self.critical = False
31
32    def __str__(self) -> str:
33        str_errors = self.errors.copy()
34
35        for frame_no, errors in self.frame_dependent_errors.items():
36            str_errors.append(f"Frame {frame_no}: {', '.join(errors)}")
37
38        return " ".join(str_errors)
39
40    def append(self, error: str, frame_no: int = None):
41        """
42        Append an error to the list of errors.
43
44        :param error: Error to append.
45        :param frame_no: Frame number the error occurred on. (If required)
46        """
47
48        if not frame_no:
49            self.errors.append(error)
50
51        else:
52            if frame_no not in self.frame_dependent_errors:
53                self.frame_dependent_errors[frame_no] = []
54            self.frame_dependent_errors[frame_no].append(error)
55
56    def __bool__(self):
57        return len(self.errors) > 0
class RecordedError:
21class RecordedError:
22    """
23    Class for storing errors as they occur during processing.
24
25    Can be critical or non-critical, and frame-dependent or not.
26    """
27
28    def __init__(self):
29        self.errors = []
30        self.frame_dependent_errors = {}
31        self.critical = False
32
33    def __str__(self) -> str:
34        str_errors = self.errors.copy()
35
36        for frame_no, errors in self.frame_dependent_errors.items():
37            str_errors.append(f"Frame {frame_no}: {', '.join(errors)}")
38
39        return " ".join(str_errors)
40
41    def append(self, error: str, frame_no: int = None):
42        """
43        Append an error to the list of errors.
44
45        :param error: Error to append.
46        :param frame_no: Frame number the error occurred on. (If required)
47        """
48
49        if not frame_no:
50            self.errors.append(error)
51
52        else:
53            if frame_no not in self.frame_dependent_errors:
54                self.frame_dependent_errors[frame_no] = []
55            self.frame_dependent_errors[frame_no].append(error)
56
57    def __bool__(self):
58        return len(self.errors) > 0

Class for storing errors as they occur during processing.

Can be critical or non-critical, and frame-dependent or not.

errors
frame_dependent_errors
critical
def append(self, error: str, frame_no: int = None):
41    def append(self, error: str, frame_no: int = None):
42        """
43        Append an error to the list of errors.
44
45        :param error: Error to append.
46        :param frame_no: Frame number the error occurred on. (If required)
47        """
48
49        if not frame_no:
50            self.errors.append(error)
51
52        else:
53            if frame_no not in self.frame_dependent_errors:
54                self.frame_dependent_errors[frame_no] = []
55            self.frame_dependent_errors[frame_no].append(error)

Append an error to the list of errors.

Parameters
  • error: Error to append.
  • frame_no: Frame number the error occurred on. (If required)