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

deadc0de6 / catcli / 4399176145

pending completion
4399176145

Pull #30

github

GitHub
Merge ee2cf80d9 into 7590ad02c
Pull Request #30: Fuse

474 of 474 new or added lines in 13 files covered. (100.0%)

1304 of 1691 relevant lines covered (77.11%)

3.86 hits per line

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

84.68
/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
class NodeAny(NodeMixin):  # type: ignore
5✔
25
    """generic node"""
26

27
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
28
                 parent=None,
29
                 children=None):
30
        """build generic node"""
31
        super().__init__()
5✔
32
        self.parent = parent
5✔
33
        if children:
5✔
34
            self.children = children
×
35

36
    def _to_str(self) -> str:
5✔
37
        ret = str(self.__class__) + ": " + str(self.__dict__)
5✔
38
        if self.children:
5✔
39
            ret += '\n'
5✔
40
        for child in self.children:
5✔
41
            ret += '  child => ' + str(child)
5✔
42
        return ret
5✔
43

44
    def __str__(self) -> str:
5✔
45
        return self._to_str()
×
46

47
    def flagged(self) -> bool:
5✔
48
        """is flagged"""
49
        if not hasattr(self, '_flagged'):
5✔
50
            return False
5✔
51
        return self._flagged
5✔
52

53
    def flag(self) -> None:
5✔
54
        """flag a node"""
55
        self._flagged = True  # pylint: disable=W0201
5✔
56

57
    def unflag(self) -> None:
5✔
58
        """unflag node"""
59
        self._flagged = False  # pylint: disable=W0201
5✔
60
        delattr(self, '_flagged')
5✔
61

62

63
class NodeTop(NodeAny):
5✔
64
    """a top node"""
65

66
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
67
                 name: str,
68
                 children=None):
69
        """build a top node"""
70
        super().__init__()  # type: ignore[no-untyped-call]
5✔
71
        self.name = name
5✔
72
        self.type = TYPE_TOP
5✔
73
        self.parent = None
5✔
74
        if children:
5✔
75
            self.children = children
5✔
76

77
    def __str__(self) -> str:
5✔
78
        return self._to_str()
5✔
79

80

81
class NodeFile(NodeAny):
5✔
82
    """a file node"""
83

84
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
85
                 name: str,
86
                 relpath: str,
87
                 size: int,
88
                 md5: str,
89
                 maccess: float,
90
                 parent=None,
91
                 children=None):
92
        """build a file node"""
93
        super().__init__()  # type: ignore[no-untyped-call]
5✔
94
        self.name = name
5✔
95
        self.type = TYPE_FILE
5✔
96
        self.relpath = relpath
5✔
97
        self.size = size
5✔
98
        self.md5 = md5
5✔
99
        self.maccess = maccess
5✔
100
        self.parent = parent
5✔
101
        if children:
5✔
102
            self.children = children
×
103

104
    def __str__(self) -> str:
5✔
105
        return self._to_str()
5✔
106

107

108
class NodeDir(NodeAny):
5✔
109
    """a directory node"""
110

111
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
112
                 name: str,
113
                 relpath: str,
114
                 size: int,
115
                 maccess: float,
116
                 parent=None,
117
                 children=None):
118
        """build a directory node"""
119
        super().__init__()  # type: ignore[no-untyped-call]
5✔
120
        self.name = name
5✔
121
        self.type = TYPE_DIR
5✔
122
        self.relpath = relpath
5✔
123
        self.size = size
5✔
124
        self.maccess = maccess
5✔
125
        self.parent = parent
5✔
126
        if children:
5✔
127
            self.children = children
×
128

129
    def __str__(self) -> str:
5✔
130
        return self._to_str()
5✔
131

132

133
class NodeArchived(NodeAny):
5✔
134
    """an archived node"""
135

136
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
137
                 name: str,
138
                 relpath: str,
139
                 size: int,
140
                 md5: str,
141
                 archive: str,
142
                 parent=None,
143
                 children=None):
144
        """build an archived node"""
145
        super().__init__()  # type: ignore[no-untyped-call]
×
146
        self.name = name
×
147
        self.type = TYPE_ARCHIVED
×
148
        self.relpath = relpath
×
149
        self.size = size
×
150
        self.md5 = md5
×
151
        self.archive = archive
×
152
        self.parent = parent
×
153
        if children:
×
154
            self.children = children
×
155

156
    def __str__(self) -> str:
5✔
157
        return self._to_str()
×
158

159

160
class NodeStorage(NodeAny):
5✔
161
    """a storage node"""
162

163
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
164
                 name: str,
165
                 free: int,
166
                 total: int,
167
                 size: int,
168
                 ts: float,
169
                 attr: str,
170
                 parent=None,
171
                 children=None):
172
        """build a storage node"""
173
        super().__init__()  # type: ignore[no-untyped-call]
5✔
174
        self.name = name
5✔
175
        self.type = TYPE_STORAGE
5✔
176
        self.free = free
5✔
177
        self.total = total
5✔
178
        self.attr = attr
5✔
179
        self.size = size
5✔
180
        self.ts = ts  # pylint: disable=C0103
5✔
181
        self.parent = parent
5✔
182
        if children:
5✔
183
            self.children = children
×
184

185
    def __str__(self) -> str:
5✔
186
        return self._to_str()
5✔
187

188

189
class NodeMeta(NodeAny):
5✔
190
    """a meta node"""
191

192
    def __init__(self,  # type: ignore[no-untyped-def]
5✔
193
                 name: str,
194
                 attr: Dict[str, Any],
195
                 parent=None,
196
                 children=None):
197
        """build a meta node"""
198
        super().__init__()  # type: ignore[no-untyped-call]
5✔
199
        self.name = name
5✔
200
        self.type = TYPE_META
5✔
201
        self.attr = attr
5✔
202
        self.parent = parent
5✔
203
        if children:
5✔
204
            self.children = children
×
205

206
    def __str__(self) -> str:
5✔
207
        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