• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deadc0de6 / catcli / 5632666386

pending completion
5632666386

push

github

deadc0de6
fix casting

15 of 15 new or added lines in 2 files covered. (100.0%)

1342 of 1768 relevant lines covered (75.9%)

3.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.06
/catcli/nodes.py
1
"""
2
author: deadc0de6 (https://github.com/deadc0de6)
3
Copyright (c) 2023, deadc0de6
4

5
Class that represents a node in the catalog tree
6
"""
7
# pylint: disable=W0622
8

9
from typing import Dict, Any
5✔
10
from anytree import NodeMixin  # type: ignore
5✔
11

12

13
TYPE_TOP = 'top'
5✔
14
TYPE_FILE = 'file'
5✔
15
TYPE_DIR = 'dir'
5✔
16
TYPE_ARCHIVED = 'arc'
5✔
17
TYPE_STORAGE = 'storage'
5✔
18
TYPE_META = 'meta'
5✔
19

20
NAME_TOP = 'top'
5✔
21
NAME_META = 'meta'
5✔
22

23

24
def typcast_node(node: Any) -> None:
5✔
25
    """typecast node to its sub type"""
26
    if node.type == TYPE_TOP:
5✔
27
        node.__class__ = NodeTop
×
28
    elif node.type == TYPE_FILE:
5✔
29
        node.__class__ = NodeFile
5✔
30
    elif node.type == TYPE_DIR:
5✔
31
        node.__class__ = NodeDir
5✔
32
    elif node.type == TYPE_ARCHIVED:
5✔
33
        node.__class__ = NodeArchived
×
34
    elif node.type == TYPE_STORAGE:
5✔
35
        node.__class__ = NodeStorage
5✔
36
    elif node.type == TYPE_META:
×
37
        node.__class__ = NodeMeta
×
38

39

40
class NodeAny(NodeMixin):  # type: ignore
5✔
41
    """generic node"""
42

43
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
44
                 parent=None,
45
                 children=None):
46
        """build generic node"""
47
        super().__init__()
5✔
48
        self.parent = parent
5✔
49
        if children:
5✔
50
            self.children = children
×
51

52
    def _to_str(self) -> str:
5✔
53
        ret = str(self.__class__) + ": " + str(self.__dict__)
5✔
54
        if self.children:
5✔
55
            ret += '\n'
5✔
56
        for child in self.children:
5✔
57
            ret += f'  child => {child}\n'
5✔
58
        return ret
5✔
59

60
    def __str__(self) -> str:
5✔
61
        return self._to_str()
×
62

63
    def flagged(self) -> bool:
5✔
64
        """is flagged"""
65
        if not hasattr(self, '_flagged'):
5✔
66
            return False
5✔
67
        return self._flagged
5✔
68

69
    def flag(self) -> None:
5✔
70
        """flag a node"""
71
        self._flagged = True  # pylint: disable=W0201
5✔
72

73
    def unflag(self) -> None:
5✔
74
        """unflag node"""
75
        self._flagged = False  # pylint: disable=W0201
5✔
76
        delattr(self, '_flagged')
5✔
77

78

79
class NodeTop(NodeAny):
5✔
80
    """a top node"""
81

82
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
83
                 name: str,
84
                 children=None):
85
        """build a top node"""
86
        super().__init__()  # type: ignore[no-untyped-call]
5✔
87
        self.name = name
5✔
88
        self.type = TYPE_TOP
5✔
89
        self.parent = None
5✔
90
        if children:
5✔
91
            self.children = children
5✔
92

93
    def __str__(self) -> str:
5✔
94
        return self._to_str()
5✔
95

96

97
class NodeFile(NodeAny):
5✔
98
    """a file node"""
99

100
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
101
                 name: str,
102
                 relpath: str,
103
                 nodesize: int,
104
                 md5: str,
105
                 maccess: float,
106
                 parent=None,
107
                 children=None):
108
        """build a file node"""
109
        super().__init__()  # type: ignore[no-untyped-call]
5✔
110
        self.name = name
5✔
111
        self.type = TYPE_FILE
5✔
112
        self.relpath = relpath
5✔
113
        self.nodesize = nodesize
5✔
114
        self.md5 = md5
5✔
115
        self.maccess = maccess
5✔
116
        self.parent = parent
5✔
117
        if children:
5✔
118
            self.children = children
×
119

120
    def __str__(self) -> str:
5✔
121
        return self._to_str()
5✔
122

123

124
class NodeDir(NodeAny):
5✔
125
    """a directory node"""
126

127
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
128
                 name: str,
129
                 relpath: str,
130
                 nodesize: int,
131
                 maccess: float,
132
                 parent=None,
133
                 children=None):
134
        """build a directory node"""
135
        super().__init__()  # type: ignore[no-untyped-call]
5✔
136
        self.name = name
5✔
137
        self.type = TYPE_DIR
5✔
138
        self.relpath = relpath
5✔
139
        self.nodesize = nodesize
5✔
140
        self.maccess = maccess
5✔
141
        self.parent = parent
5✔
142
        if children:
5✔
143
            self.children = children
×
144

145
    def __str__(self) -> str:
5✔
146
        return self._to_str()
5✔
147

148

149
class NodeArchived(NodeAny):
5✔
150
    """an archived node"""
151

152
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
153
                 name: str,
154
                 relpath: str,
155
                 nodesize: int,
156
                 md5: str,
157
                 archive: str,
158
                 parent=None,
159
                 children=None):
160
        """build an archived node"""
161
        super().__init__()  # type: ignore[no-untyped-call]
×
162
        self.name = name
×
163
        self.type = TYPE_ARCHIVED
×
164
        self.relpath = relpath
×
165
        self.nodesize = nodesize
×
166
        self.md5 = md5
×
167
        self.archive = archive
×
168
        self.parent = parent
×
169
        if children:
×
170
            self.children = children
×
171

172
    def __str__(self) -> str:
5✔
173
        return self._to_str()
×
174

175

176
class NodeStorage(NodeAny):
5✔
177
    """a storage node"""
178

179
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
180
                 name: str,
181
                 free: int,
182
                 total: int,
183
                 nodesize: int,
184
                 ts: float,
185
                 attr: str,
186
                 parent=None,
187
                 children=None):
188
        """build a storage node"""
189
        super().__init__()  # type: ignore[no-untyped-call]
5✔
190
        self.name = name
5✔
191
        self.type = TYPE_STORAGE
5✔
192
        self.free = free
5✔
193
        self.total = total
5✔
194
        self.attr = attr
5✔
195
        self.nodesize = nodesize
5✔
196
        self.ts = ts  # pylint: disable=C0103
5✔
197
        self.parent = parent
5✔
198
        if children:
5✔
199
            self.children = children
×
200

201
    def __str__(self) -> str:
5✔
202
        return self._to_str()
5✔
203

204

205
class NodeMeta(NodeAny):
5✔
206
    """a meta node"""
207

208
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
209
                 name: str,
210
                 attr: Dict[str, Any],
211
                 parent=None,
212
                 children=None):
213
        """build a meta node"""
214
        super().__init__()  # type: ignore[no-untyped-call]
5✔
215
        self.name = name
5✔
216
        self.type = TYPE_META
5✔
217
        self.attr = attr
5✔
218
        self.parent = parent
5✔
219
        if children:
5✔
220
            self.children = children
×
221

222
    def __str__(self) -> str:
5✔
223
        return self._to_str()
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc