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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
Handle recommended packages in core and rpm backends
Identify and store recommended packages in the cache, add a query option
to read them and ignore them if they are not present when installing.
Initial identification code from Mark Hatle <mark.hatle@windriver.com>.
Upstream-Status: Pending
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
diff --git a/smart/backends/rpm/base.py b/smart/backends/rpm/base.py
index 9332ea0..4fcfbee 100644
--- a/smart/backends/rpm/base.py
+++ b/smart/backends/rpm/base.py
@@ -225,6 +225,52 @@ class RPMPackage(Package):
break
else:
return False
+ srecs = fk(self.recommends)
+ orecs = fk(other.recommends)
+ if srecs != orecs:
+ for srec in srecs:
+ if srec.name[0] == "/" or srec in orecs:
+ continue
+ for orec in orecs:
+ if (srec.name == orec.name and
+ srec.relation == orec.relation and
+ checkver(srec.version, orec.version)):
+ break
+ else:
+ return False
+ for orec in orecs:
+ if orec.name[0] == "/" or orec in srecs:
+ continue
+ for srec in srecs:
+ if (srec.name == orec.name and
+ srec.relation == orec.relation and
+ checkver(srec.version, orec.version)):
+ break
+ else:
+ return False
+ srecs = fk(self.recommends)
+ orecs = fk(other.recommends)
+ if srecs != orecs:
+ for srec in srecs:
+ if srec.name[0] == "/" or srec in orecs:
+ continue
+ for orec in orecs:
+ if (srec.name == orec.name and
+ srec.relation == orec.relation and
+ checkver(srec.version, orec.version)):
+ break
+ else:
+ return False
+ for orec in orecs:
+ if orec.name[0] == "/" or orec in srecs:
+ continue
+ for srec in srecs:
+ if (srec.name == orec.name and
+ srec.relation == orec.relation and
+ checkver(srec.version, orec.version)):
+ break
+ else:
+ return False
return True
def coexists(self, other):
diff --git a/smart/ccache.c b/smart/ccache.c
index 7193185..8b66515 100644
--- a/smart/ccache.c
+++ b/smart/ccache.c
@@ -500,6 +500,46 @@ Package_equals(PackageObject *self, PackageObject *other)
}
}
+ ilen = 0;
+ jlen = 0;
+ for (i = 0; i != PyList_GET_SIZE(self->recommends); i++) {
+ PyObject *item = PyList_GET_ITEM(self->recommends, i);
+ if (!PyObject_IsInstance(item, (PyObject *)&Depends_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Depends instance expected");
+ return NULL;
+ }
+ if (STR(((DependsObject *)item)->name)[0] != '/')
+ ilen += 1;
+ }
+ for (j = 0; j != PyList_GET_SIZE(other->recommends); j++) {
+ PyObject *item = PyList_GET_ITEM(other->recommends, j);
+ if (!PyObject_IsInstance(item, (PyObject *)&Depends_Type)) {
+ PyErr_SetString(PyExc_TypeError, "Depends instance expected");
+ return NULL;
+ }
+ if (STR(((DependsObject *)item)->name)[0] != '/')
+ jlen += 1;
+ }
+ if (ilen != jlen) {
+ ret = Py_False;
+ goto exit;
+ }
+
+ ilen = PyList_GET_SIZE(self->recommends);
+ jlen = PyList_GET_SIZE(other->recommends);
+ for (i = 0; i != ilen; i++) {
+ PyObject *item = PyList_GET_ITEM(self->recommends, i);
+ if (STR(((DependsObject *)item)->name)[0] != '/') {
+ for (j = 0; j != jlen; j++)
+ if (item == PyList_GET_ITEM(other->recommends, j))
+ break;
+ if (j == jlen) {
+ ret = Py_False;
+ goto exit;
+ }
+ }
+ }
+
exit:
Py_INCREF(ret);
return ret;
@@ -1813,6 +1853,59 @@ Loader_buildPackage(LoaderObject *self, PyObject *args)
}
}
+ /* if recargs: */
+ if (recargs) {
+ int i = 0;
+ int len = PyList_GET_SIZE(recargs);
+ /* pkg.recommends = [] */
+ Py_DECREF(pkgobj->recommends);
+ pkgobj->recommends = PyList_New(len);
+ /* for args in recargs: */
+ for (; i != len; i++) {
+ PyObject *args = PyList_GET_ITEM(recargs, i);
+ DependsObject *recobj;
+ PyObject *rec;
+
+ if (!PyTuple_Check(args)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Item in recargs is not a tuple");
+ return NULL;
+ }
+
+ /* rec = cache._objmap.get(args) */
+ rec = PyDict_GetItem(cache->_objmap, args);
+ recobj = (DependsObject *)rec;
+
+ /* if not rec: */
+ if (!rec) {
+ if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 2) {
+ PyErr_SetString(PyExc_ValueError, "Invalid recargs tuple");
+ return NULL;
+ }
+ /* rec = args[0](*args[1:]) */
+ callargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
+ rec = PyObject_CallObject(PyTuple_GET_ITEM(args, 0), callargs);
+ Py_DECREF(callargs);
+ if (!rec) return NULL;
+ recobj = (DependsObject *)rec;
+
+ /* cache._objmap[args] = rec */
+ PyDict_SetItem(cache->_objmap, args, rec);
+ Py_DECREF(rec);
+
+ /* cache._recommends.append(rec) */
+ PyList_Append(cache->_recommends, rec);
+ }
+
+ /* relpkgs.append(rec.packages) */
+ PyList_Append(relpkgs, recobj->packages);
+
+ /* pkg.recommends.append(rec) */
+ Py_INCREF(rec);
+ PyList_SET_ITEM(pkgobj->recommends, i, rec);
+ }
+ }
+
/* if upgargs: */
if (upgargs) {
int i = 0;
@@ -2592,6 +2685,16 @@ Cache_reset(CacheObject *self, PyObject *args)
if (PyList_Check(reqobj->providedby))
LIST_CLEAR(reqobj->providedby);
}
+ len = PyList_GET_SIZE(self->_recommends);
+ for (i = 0; i != len; i++) {
+ DependsObject *reqobj;
+ PyObject *req;
+ req = PyList_GET_ITEM(self->_recommends, i);
+ reqobj = (DependsObject *)req;
+ LIST_CLEAR(reqobj->packages);
+ if (PyList_Check(reqobj->providedby))
+ LIST_CLEAR(reqobj->providedby);
+ }
len = PyList_GET_SIZE(self->_upgrades);
for (i = 0; i != len; i++) {
DependsObject *upgobj;
@@ -2834,6 +2937,30 @@ Cache__reload(CacheObject *self, PyObject *args)
}
/*
+ for rec in pkg.recommends:
+ rec.packages.append(pkg)
+ if rec not in recommends:
+ recommends[rec] = True
+ objmap[rec.getInitArgs()] = rec
+ */
+ if (PyList_Check(pkg->recommends)) {
+ klen = PyList_GET_SIZE(pkg->recommends);
+ for (k = 0; k != klen; k++) {
+ PyObject *rec = PyList_GET_ITEM(pkg->recommends, k);
+ PyList_Append(((DependsObject *)rec)->packages,
+ (PyObject *)pkg);
+ if (!PyDict_GetItem(recommends, rec)) {
+ PyDict_SetItem(recommends, rec, Py_True);
+ args = PyObject_CallMethod(rec, "getInitArgs",
+ NULL);
+ if (!args) return NULL;
+ PyDict_SetItem(objmap, args, rec);
+ Py_DECREF(args);
+ }
+ }
+ }
+
+ /*
for upg in pkg.upgrades:
upg.packages.append(pkg)
if upg not in upgrades:
@@ -3097,6 +3224,47 @@ Cache_linkDeps(CacheObject *self, PyObject *args)
Py_DECREF(seq);
}
+ /* recnames = {} */
+ recnames = PyDict_New();
+ /* for rec in self._recommends: */
+ len = PyList_GET_SIZE(self->_recommends);
+ for (i = 0; i != len; i++) {
+ PyObject *rec = PyList_GET_ITEM(self->_recommends, i);
+
+ /* for name in rec.getMatchNames(): */
+ PyObject *names = PyObject_CallMethod(rec, "getMatchNames", NULL);
+ PyObject *seq = PySequence_Fast(names, "getMatchNames() returned "
+ "non-sequence object");
+ int nameslen;
+ if (!seq) return NULL;
+ nameslen = PySequence_Fast_GET_SIZE(seq);
+ for (j = 0; j != nameslen; j++) {
+ PyObject *name = PySequence_Fast_GET_ITEM(seq, j);
+
+ /* lst = recnames.get(name) */
+ lst = PyDict_GetItem(recnames, name);
+
+ /*
+ if lst:
+ lst.append(rec)
+ else:
+ recnames[name] = [rec]
+ */
+ if (lst) {
+ PyList_Append(lst, rec);
+ } else {
+ lst = PyList_New(1);
+ Py_INCREF(rec);
+ PyList_SET_ITEM(lst, 0, rec);
+ PyDict_SetItem(recnames, name, lst);
+ Py_DECREF(lst);
+ }
+ }
+
+ Py_DECREF(names);
+ Py_DECREF(seq);
+ }
+
/* upgnames = {} */
upgnames = PyDict_New();
/* for upg in self._upgrades: */
@@ -3286,6 +3454,56 @@ Cache_linkDeps(CacheObject *self, PyObject *args)
}
}
+ /* lst = recnames.get(prv.name) */
+ lst = PyDict_GetItem(recnames, prv->name);
+
+ /* if lst: */
+ if (lst) {
+ /* for rec in lst: */
+ int reclen = PyList_GET_SIZE(lst);
+ for (j = 0; j != reclen; j++) {
+ DependsObject *rec = (DependsObject *)PyList_GET_ITEM(lst, j);
+ /* if rec.matches(prv): */
+ PyObject *ret = PyObject_CallMethod((PyObject *)rec, "matches",
+ "O", (PyObject *)prv);
+ if (!ret) return NULL;
+ if (PyObject_IsTrue(ret)) {
+ /*
+ if rec.providedby:
+ rec.providedby.append(prv)
+ else:
+ rec.providedby = [prv]
+ */
+ if (PyList_Check(rec->providedby)) {
+ PyList_Append(rec->providedby, (PyObject *)prv);
+ } else {
+ PyObject *_lst = PyList_New(1);
+ Py_INCREF(prv);
+ PyList_SET_ITEM(_lst, 0, (PyObject *)prv);
+ Py_DECREF(rec->providedby);
+ rec->providedby = _lst;
+ }
+
+ /*
+ if prv.recommendedby:
+ prv.recommendedby.append(prv)
+ else:
+ prv.recommendedby = [prv]
+ */
+ if (PyList_Check(prv->recommendedby)) {
+ PyList_Append(prv->recommendedby, (PyObject *)rec);
+ } else {
+ PyObject *_lst = PyList_New(1);
+ Py_INCREF(rec);
+ PyList_SET_ITEM(_lst, 0, (PyObject *)rec);
+ Py_DECREF(prv->recommendedby);
+ prv->recommendedby = _lst;
+ }
+ }
+ Py_DECREF(ret);
+ }
+ }
+
/* lst = upgnames.get(prv.name) */
lst = PyDict_GetItem(upgnames, prv->name);
@@ -3821,6 +4094,21 @@ Cache__setstate__(CacheObject *self, PyObject *state)
}
/*
+ for rec in pkg.recommends:
+ rec.packages.append(pkg)
+ recommends[rec] = True
+ */
+ if (PyList_Check(pkgobj->recommends)) {
+ jlen = PyList_GET_SIZE(pkgobj->recommends);
+ for (j = 0; j != jlen; j++) {
+ PyObject *rec = PyList_GET_ITEM(pkgobj->recommends, j);
+ DependsObject *recobj = (DependsObject *)rec;
+ PyList_Append(recobj->packages, pkg);
+ PyDict_SetItem(recommends, rec, Py_True);
+ }
+ }
+
+ /*
for upg in pkg.upgrades:
upg.packages.append(pkg)
upgrades[upg] = True
diff --git a/smart/commands/query.py b/smart/commands/query.py
index 9265cd9..b6f5697 100644
--- a/smart/commands/query.py
+++ b/smart/commands/query.py
@@ -750,6 +750,22 @@ class TextOutput(NullOutput):
name = str(prvpkg)
print " ", "%s (%s)" % (name, prv)
+ def showRecommends(self, pkg, rec):
+ if self._firstrecommends:
+ self._firstrecommends = False
+ print " ", _("Recommends:")
+ print " ", rec
+
+ def showRecommendsProvidedBy(self, pkg, req, prv, prvpkg):
+ if self._firstrecommendsprovidedby:
+ self._firstrecommendsprovidedby = False
+ print " ", _("Provided By:")
+ if self.opts.hide_version:
+ name = prvpkg.name
+ else:
+ name = str(prvpkg)
+ print " ", "%s (%s)" % (name, prv)
+
def showUpgrades(self, pkg, upg):
if self._firstupgrades:
self._firstupgrades = False
|