-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustom_types.py
122 lines (95 loc) · 3.1 KB
/
custom_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# pkgs.void - web catalog of Void Linux packages.
# Copyright (C) 2019-2021 Piotr Wójcik <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from collections import defaultdict, namedtuple
from enum import Enum
class Attributes:
def __init__(self, dic):
super().__init__()
for i in dic.keys():
setattr(self, i, dic[i])
class Binpkgs:
def __init__(self):
super().__init__()
self._data = {}
self._isets = set()
self._libcs = set()
def __len__(self):
return len(self._data)
def add(self, version, *, iset, libc):
self._data[(iset, libc)] = Version(version, iset=iset, libc=libc)
self._isets.add(iset)
self._libcs.add(libc)
@property
def by_libc(self):
for libc in sorted(self._libcs):
yield Attributes({
'libc': libc,
'by_iset': (self._data.get((iset, libc))
for iset in sorted(self._isets))
})
@staticmethod
def _arch_sortkey(version):
return '{iset}-{libc}'.format(**version.data)
@property
def by_version(self):
versions = defaultdict(list)
for value in self._data.values():
versions[value.verrev].append(value)
for key in sorted(versions.keys()):
yield key, sorted(versions[key], key=self._arch_sortkey)
@property
def by_iset(self):
for iset in sorted(self._isets):
yield Attributes({
'iset': iset,
'by_libc': (self._data.get((iset, libc))
for libc in sorted(self._libcs))
})
@property
def all(self):
for version in self._data.values():
yield version
@property
def items(self):
for item in self._data.items():
yield item
Field = namedtuple('Field', ('name', 'title', 'value', 'presentation'))
FoundPackages = namedtuple(
'FoundPackages',
(
'parameters',
'other',
'popularity_reports'
)
)
class Interest(Enum):
INTERESTING = 'i'
BORING = 'b'
NOVEL = 'n'
Repo = namedtuple('Repo', ('repo', 'reason'))
Response = namedtuple('Response', (
'content',
'redirect',
'error'
))
ValueAt = namedtuple('ValueAt', ('value', 'coords'))
class Version:
def __init__(self, version, **kwargs):
super().__init__()
components = version.rsplit('_', 1)
self.version = components[0]
self.revision = components[1]
self.data = kwargs
self.verrev = version