Coverage for d7a/fs/file_properties.py: 88%
40 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19from enum import Enum
21from d7a.support.schema import Validatable, Types
24class ActionCondition(Enum):
25 LIST = 0
26 READ = 1
27 WRITE = 2
28 WRITE_FLUSH = 3
31class StorageClass(Enum):
32 TRANSIENT = 0
33 VOLATILE = 1
34 RESTORABLE = 2
35 PERMANENT = 3
38class FileProperties(Validatable):
39 SCHEMA = [{
40 "act_enabled": Types.BOOLEAN(),
41 "act_cond": Types.ENUM(ActionCondition),
42 "storage_class": Types.ENUM(StorageClass),
43 }]
45 def __init__(self, act_enabled, act_condition, storage_class):
46 self.act_enabled = act_enabled
47 self.act_condition = act_condition
48 self.storage_class = storage_class
50 Validatable.__init__(self)
52 @staticmethod
53 def parse(s):
54 act_enabled = s.read("bool")
55 act_condition = ActionCondition(s.read("uint:3"))
56 _rfu = s.read("uint:2")
57 storage_class = StorageClass(s.read("uint:2"))
58 return FileProperties(act_enabled, act_condition, storage_class)
60 def __iter__(self):
61 byte = 0
62 if self.act_enabled: byte += 1 << 7
63 byte += self.act_condition.value << 4
64 byte += self.storage_class.value
65 yield byte
67 def __str__(self):
68 return "act_enabled={}, act_condition={}, storage_class={}".format(
69 self.act_enabled,
70 self.act_condition,
71 self.storage_class
72 )
74 def __eq__(self, other):
75 if isinstance(other, FileProperties):
76 return self.__dict__ == other.__dict__
78 return False
80 def __ne__(self, other):
81 return not self.__eq__(other)