]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
2c909128 | 3 | from . import base |
f6e6ff79 | 4 | |
839b1f3f MT |
5 | _priorities = { |
6 | "noarch" : 0, | |
7 | ||
8 | # 64 bit | |
9 | "x86_64" : 1, | |
10 | "aarch64" : 2, | |
11 | ||
12 | # 32 bit | |
13 | "i686" : 3, | |
14 | "armv7hl" : 4, | |
15 | "armv5tel" : 5, | |
16 | } | |
17 | ||
18 | def priority(arch): | |
19 | try: | |
20 | return _priorities[arch] | |
21 | except KeyError: | |
22 | return 99 | |
23 | ||
f6e6ff79 | 24 | class Arches(base.Object): |
3e454de1 MT |
25 | def __iter__(self): |
26 | res = self.db.query("SELECT name FROM arches \ | |
27 | WHERE NOT name = ANY(%s)", ("noarch", "src")) | |
28 | ||
087a5f09 MT |
29 | return iter(sorted((a.name for a in res), key=priority)) |
30 | ||
31 | def exists(self, name): | |
32 | # noarch doesn't really exist | |
33 | if name == "noarch": | |
34 | return False | |
35 | ||
36 | res = self.db.get("SELECT 1 FROM arches \ | |
37 | WHERE name = %s", name) | |
38 | ||
39 | if res: | |
40 | return True | |
41 | ||
42 | return False | |
3e454de1 | 43 | |
f6e6ff79 | 44 | def expand(self, arches): |
f6e6ff79 | 45 | if arches == "all": |
66a7479a | 46 | return list(self) |
f6e6ff79 | 47 | |
66a7479a MT |
48 | res = [] |
49 | for arch in arches.split(): | |
50 | if self.exists(arch): | |
51 | res.append(arch) | |
f6e6ff79 | 52 | |
66a7479a | 53 | return res |