]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import base | |
4 | ||
5 | class Arches(base.Object): | |
9177f86a MT |
6 | def get_all(self, really=False): |
7 | query = "SELECT * FROM arches" | |
f6e6ff79 | 8 | |
9177f86a MT |
9 | if not really: |
10 | query += " WHERE `binary` = 'Y'" | |
11 | else: | |
12 | query += " WHERE NOT name = 'src'" | |
13 | ||
14 | query += " ORDER BY prio ASC" | |
15 | ||
16 | arches = self.db.query(query) | |
17 | ||
18 | return [Arch(self.pakfire, a.id, a) for a in arches] | |
f6e6ff79 MT |
19 | |
20 | def get_name_by_id(self, id): | |
21 | arch = self.db.get("SELECT name FROM arches WHERE id = %s", id) | |
22 | ||
23 | return arch.name | |
24 | ||
25 | def get_id_by_name(self, name): | |
26 | arch = self.db.get("SELECT id FROM arches WHERE name = %s", name) | |
27 | ||
28 | if arch: | |
29 | return arch.id | |
30 | ||
31 | def get_by_name(self, name): | |
32 | id = self.get_id_by_name(name) | |
33 | ||
34 | if id: | |
35 | return self.get_by_id(id) | |
36 | ||
37 | def get_by_id(self, id): | |
38 | return Arch(self.pakfire, id) | |
39 | ||
40 | def exists(self, id): | |
41 | arch = self.db.get("SELECT id FROM arches WHERE id = %s", id) | |
42 | ||
43 | if arch: | |
44 | return True | |
45 | ||
46 | return False | |
47 | ||
48 | def expand(self, arches): | |
49 | args = [] | |
50 | ||
51 | if arches == "all": | |
52 | query = "SELECT id FROM arches WHERE name != 'noarch'" | |
53 | else: | |
54 | query = [] | |
55 | ||
56 | for arch in arches.split(): | |
57 | args.append(arch) | |
58 | query.append("name = %s") | |
59 | ||
60 | query = "SELECT id FROM arches WHERE (%s)" % " OR ".join(query) | |
61 | ||
62 | return sorted([self.get_by_id(a.id) for a in self.db.query(query, *args)]) | |
63 | ||
64 | ||
65 | class Arch(base.Object): | |
9177f86a | 66 | def __init__(self, pakfire, id, data=None): |
f6e6ff79 MT |
67 | base.Object.__init__(self, pakfire) |
68 | ||
69 | # The ID of this architecture. | |
70 | self.id = id | |
71 | ||
72 | # Cache data. | |
9177f86a | 73 | self._data = data |
f6e6ff79 MT |
74 | |
75 | def __cmp__(self, other): | |
76 | return cmp(self.prio, other.prio) | |
77 | ||
78 | @property | |
79 | def data(self): | |
80 | if self._data is None: | |
966498de | 81 | self._data = self.db.get("SELECT * FROM arches WHERE id = %s", self.id) |
f6e6ff79 MT |
82 | assert self._data |
83 | ||
84 | return self._data | |
85 | ||
86 | @property | |
87 | def name(self): | |
88 | return self.data.name | |
89 | ||
90 | @property | |
91 | def prio(self): | |
92 | return self.data.prio | |
93 | ||
94 | @property | |
95 | def build_type(self): | |
96 | if self.name == "src": | |
97 | return "source" | |
98 | ||
99 | return "binary" |