Coverage for d7a/fs/file_permissions.py: 88%
43 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 d7a.support.schema import Validatable, Types
22class FilePermissions(Validatable):
23 SCHEMA = [{
24 "encrypted": Types.BOOLEAN(),
25 "executable": Types.BOOLEAN(),
26 "user_readable": Types.BOOLEAN(),
27 "user_writable": Types.BOOLEAN(),
28 "user_executable": Types.BOOLEAN(),
29 "guest_readable": Types.BOOLEAN(),
30 "guest_writable": Types.BOOLEAN(),
31 "guest_executable": Types.BOOLEAN()
32 }]
34 def __init__(self, encrypted=False, executable=False, user_readable=True, user_writable=True, user_executable=True,
35 guest_readable= True, guest_writable=True, guest_executable=True):
36 self.encrypted = encrypted
37 self.executable = executable
38 self.user_readable = user_readable
39 self.user_writable = user_writable
40 self.user_executable = user_executable
41 self.guest_readable = guest_readable
42 self.guest_writable = guest_writable
43 self.guest_executable = guest_executable
45 Validatable.__init__(self)
47 @staticmethod
48 def parse(s):
49 encrypted = s.read("bool")
50 executable = s.read("bool")
51 user_readable = s.read("bool")
52 user_writable = s.read("bool")
53 user_executable = s.read("bool")
54 guest_readable = s.read("bool")
55 guest_writable = s.read("bool")
56 guest_executable = s.read("bool")
57 return FilePermissions(encrypted=encrypted, executable=executable, user_readable=user_readable,
58 user_writable=user_writable, user_executable=user_executable,
59 guest_readable=guest_readable, guest_writable=guest_writable, guest_executable=guest_executable)
61 def __iter__(self):
62 byte = 0
63 if self.encrypted: byte += 1 << 7
64 if self.executable: byte += 1 << 6
65 if self.user_readable: byte += 1 << 5
66 if self.user_writable: byte += 1 << 4
67 if self.user_executable: byte += 1 << 3
68 if self.guest_readable: byte += 1 << 2
69 if self.guest_writable: byte += 1 << 1
70 if self.guest_executable: byte += 1
71 yield byte
73 def __str__(self):
74 return "" #TODO
76 def __eq__(self, other):
77 if isinstance(other, FilePermissions):
78 return self.__dict__ == other.__dict__
80 return False
82 def __ne__(self, other):
83 return not self.__eq__(other)