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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
/*
** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
**
*/
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/
/*
** Bug reports and questions can be sent to kde-devel@kde.org
*/
#include "../config.h"
#include <stdlib.h>
#include "tdelocale.h"
#include <tdeaction.h>
#include <kstdaction.h>
#include <kdebug.h>
#include "kpackage.h"
#include "updateLoc.h"
#include "debAptInterface.h"
#include "cache.h"
#include "pkgOptions.h"
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
DEBAPT::DEBAPT():DEB()
{
head = "DEBAPT";
name = i18n("APT: Debian");
queryMsg = i18n("Querying DEB APT package list: ");
procMsg = i18n("KPackage: Waiting on APT-GET");
hasRemote = TRUE;
locatedialog = new Locations(i18n("Location of Debian Packages"));
locatedialog->aLocations(1, 60, this, i18n("APT sources", "A"),
i18n("APT Sources Entries"));
locatedialog->dLocations(1, 8, this, i18n("Folders", "F"),
"Deb", "*.deb",
i18n("Location of Folders Containing Debian Packages"));
connect(locatedialog,TQT_SIGNAL(returnVal(LcacheObj *)),
this,TQT_SLOT(setAvail(LcacheObj *)));
locatedialog->apply_slot();
paramsInst.append(new param(i18n("Download only"),FALSE,FALSE,"-d"));
paramsInst.append(new param(i18n("No download"),FALSE,FALSE,"--no-download"));
paramsInst.append(new param(i18n("Ignore missing"),FALSE,FALSE,"-m"));
paramsInst.append(new param(i18n("Ignore hold"),FALSE,FALSE,"--ignore-hold"));
paramsInst.append(new param(i18n("Allow Unauthenticated"),FALSE,FALSE,"--allow-unauthenticated"));
paramsInst.append(new param(i18n("Assume yes"),TRUE,FALSE,"--yes"));
paramsInst.append(new param(i18n("Test (do not uninstall)"),FALSE,FALSE,"-s"));
paramsUninst.append(new param(i18n("Purge Config Files"),FALSE,FALSE,"--purge"));
paramsUninst.append(new param(i18n("Assume yes"),TRUE,FALSE,"--yes"));
paramsUninst.append(new param(i18n("Test (do not uninstall)"),FALSE,FALSE,"-s"));
env = "DEBIAN_FRONTEND=readline; export DEBIAN_FRONTEND; ";
noFetch = TRUE;
hasSearchAll = TRUE;
hasProgram = ifExe("apt-get");
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
DEBAPT::~DEBAPT()
{
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
bool DEBAPT::isType(char *, const TQString &)
{
return false;
}
void DEBAPT::makeMenu(TDEActionCollection* act)
{
updateM = new TDEAction( i18n("&Update"), TQString(),
0, this,
TQT_SLOT(updateS()), act, "debapt_update");
upgradeM = new TDEAction( i18n("U&pgrade"), TQString(),
0, this,
TQT_SLOT(upgradeS()), act, "debapt_upgrade");
fixupM = new TDEAction( i18n("&Fixup"), TQString(),
0, this,
TQT_SLOT(fixupS()), act, "debapt_fixup");
fileM = new TDEAction( i18n("&Apt-File Update"), TQString(),
0, this,
TQT_SLOT(fileS()), act, "debapt_file");
}
void DEBAPT::setMenu(TDEActionCollection*, bool enable)
{
updateM->setEnabled(enable);
upgradeM->setEnabled(enable);
fixupM->setEnabled(enable);
fileM->setEnabled(enable);
}
void DEBAPT::updateS()
{
if (kprun->run("apt-get update", "APT update")) {
if (kprun->exec())
kpackage->management->collectData(TRUE);
}
}
void DEBAPT::upgradeS()
{
if (kprun->run(env + "apt-get dist-upgrade", "APT upgrade")) {
if (kprun->exec())
kpackage->management->collectData(TRUE);
}
}
void DEBAPT::fixupS()
{
if (kprun->run(env + "apt-get -f install", "APT fixup")) {
if (kprun->exec())
kpackage->management->collectData(TRUE);
}
}
void DEBAPT::fileS()
{
if (ifExe("apt-file") || !hostName.isEmpty()) {
if (kprun->run(env + "apt-file update", "APT file update")) {
kprun->exec();
}
} else {
KpMsg("Error",i18n("The %1 program needs to be installed").arg("apt-file"), TRUE);
}
}
void DEBAPT::listPackages(TQPtrList<packageInfo> *pki)
{
if (hostName.isEmpty()) {
listInstalledPackages(pki);
} else {
listRemotePackages(pki);
}
listAvail(pki);
if (hostName.isEmpty() && packageLoc) {
listUnIPackages(pki, packageLoc);
}
}
void DEBAPT::listRemotePackages(TQPtrList<packageInfo> *pki)
{
listRPack(pki);
}
void DEBAPT::listRPack(TQPtrList<packageInfo> *pki)
{
int NLINES = 70000;
packageInfo *p;
TQStringList plist;
kpackage->setStatus(i18n("Querying DEB APT remote package list: %1").arg(hostName));
kpackage->setPercent(0);
TQString cmd = "cat " STATUS;
TQStringList list = kpty->run(cmd);
kpackage->setStatus(i18n("Processing DEB APT remote package list: %1").arg(hostName));
// kdDebug() << "P=" << list.count() <<"\n";
kpackage->setPercent(50);
if (list.count() > 0) {
TQString s;
kpackage->setPercent(50 );
int cnt = 0;
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
cnt++;
if (cnt % (NLINES/20) == 0) {
kpackage->setPercent(((cnt * 100)/ NLINES ) + 50);
// kdDebug() << cnt << "_" << ((cnt * 100) / NLINES) <<"\n";
}
if (!(*it).isEmpty()) {
s = *it;
// kdDebug() << s.length() << "<" << s << ">\n";
plist << s;
} else {
// kdDebug() << "---------\n";
p = collectInfo(plist);
if (p) {
if (!p->pkgInsert(pki, typeID, TRUE)) {
delete p;
}
}
plist.clear();
}
}
}
list.clear();
kpackage->setStatus(i18n("DEB APT"));
kpackage->setPercent(100);
}
void DEBAPT::listAvail(TQPtrList<packageInfo> *pki)
{
int NLINES = 150000;
packageInfo *p;
TQStringList plist;
// kdDebug() << "H=" << hostName << "\n";
if (hostName.isEmpty())
kpackage->setStatus(i18n("Querying DEB APT available list"));
else
kpackage->setStatus(i18n("Querying DEB APT available list: %1").arg(hostName));
kpackage->setPercent(0);
TQStringList list = kpty->run("apt-cache dumpavail");
if (hostName.isEmpty())
kpackage->setStatus(i18n("Processing DEB APT available list"));
else
kpackage->setStatus(i18n("Processing DEB APT available list: %1").arg(hostName));
// kdDebug() << "A=" << list.count() <<"\n";
kpackage->setPercent(50);
if (list.count() > 0) {
TQString s;
kpackage->setPercent(50 );
int cnt = 0;
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
cnt++;
if (cnt % (NLINES/20) == 0) {
kpackage->setPercent(((cnt * 100)/ NLINES ) + 50);
}
if (!(*it).isEmpty()) {
s = *it;
plist << s;
} else {
p = collectInfo(plist);
if (p) {
if (!p->pkgInsert(pki, typeID, FALSE)) {
delete p;
}
}
plist.clear();
}
}
}
list.clear();
kpackage->setStatus(i18n("DEB APT"));
kpackage->setPercent(100);
}
TQStringList DEBAPT::listInstalls(const TQStringList &packs, bool install, bool &cancel)
{
bool extras=FALSE, found=FALSE;
TQString match;
TQString s = "apt-get -s ";
if (install) {
s += "install ";
match = " extra packages ";
} else {
match = "packages will be REMOVED:";
s += "remove ";
}
for ( TQStringList::ConstIterator it = packs.begin(); it != packs.end(); ++it ) {
s += *it;
s += " ";
}
TQStringList list = kpty->run(s, TRUE, TRUE);
if (!kpty->inSession) {
cancel = TRUE; // Root login did not work
} else {
cancel = FALSE;
}
// kdDebug() << "LS=" << list.count() << "\n";
TQString packAll;
for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
// kdDebug() << "M=" << *it << "\n";
if ((*it).find(match) >= 0 || extras) {
if (extras) {
if ((*it)[0] == ' ') {
packAll += *it;
found = true;
} else {
break;
}
}
extras=TRUE;
}
}
if (!found) {
TQStringList nill;
return nill;
} else {
TQStringList plist = TQStringList::split(' ',packAll);
return plist;
}
}
//////////////////////////////////////////////////////////////////////////////
TQStringList DEBAPT::FindFile(const TQString &name, bool searchAll)
{
if (searchAll) {
if (ifExe("apt-file") || !hostName.isEmpty()) {
TQString s = "apt-file search ";
s += name;
TQStringList filelist = kpty->run(s);
for ( TQStringList::Iterator it = filelist.begin(); it != filelist.end(); ++it ) {
int p = (*it).find(": ");
if( p !=-1 )
(*it).replace(p, 2, "\t");
}
if (filelist.count() == 1) {
TQStringList::Iterator it = filelist.begin();
if ((*it).find("not found") >= 0) {
filelist.remove(it);
}
}
return filelist;
} else {
KpMsg("Error",i18n("The %1 program needs to be installed").arg("apt-file"), TRUE);
TQStringList nill;
return nill;
}
} else {
return DEB::FindFile(name);
}
}
TQStringList DEBAPT::getFileList(packageInfo *p)
{
TQString fn( p->getFilename());
if(!fn.isEmpty())
return getUFileList(fn);
else {
if (hostName.isEmpty())
return getIFileList(p);
else {
if (p->packageState == packageInfo::INSTALLED) {
return getRFileList(p);
} else
return "";
}
}
}
TQStringList DEBAPT::getRFileList(packageInfo *p)
{
TQString from;
TQString name = p->getProperty("name");
from = "cat " INFODIR;
from += name;
from += ".list";
return kpty->run(from);
}
//////////////////////////////////////////////////////////////////////////////
TQString DEBAPT::doUninstall(int uninstallFlags, const TQString &packs, bool &test)
{
TQString s = env + "apt-get remove ";
s += setOptions(uninstallFlags, paramsUninst);
s += packs;
kdDebug() << "uCMD=" << s << "\n";
if (uninstallFlags>>2 & 1)
test = TRUE;
return s;
}
//////////////////////////////////////////////////////////////////////////////
TQString DEBAPT::install(int installFlags, TQPtrList<packageInfo> *p,
bool &test)
{
TQString packs = "";
TQString files = "";
packageInfo *i;
for (i = p->first(); i!= 0; i = p->next()) {
TQString file = i->getFilename();
TQString fname = i->fetchFilename();
if (!file.isEmpty()) {
files += TDEProcess::quote(file);
files += " ";
} else if (!fname.isEmpty()) {
packs += TDEProcess::quote(fname);
packs += " ";
}
}
if (!files.isEmpty()) { // What if mixed?
return DEB::doInstall(installFlags, files, test);
} else {
return doInstall(installFlags, packs, test);
}
}
TQString DEBAPT::doInstall(int installFlags, const TQString &packs, bool &test)
{
TQString s = env + "apt-get install ";
s += setOptions(installFlags, paramsInst);
s += packs;
kdDebug() << "iCMD=" << s << "\n";
if ((installFlags>>0 & 1) || (installFlags>>5 & 1))
test = TRUE;
return s;
}
//////////////////////////////////////////////////////////////////////////////
TQStringList DEBAPT::readApt()
{
if (hostName.isEmpty()) {
return readAptF();
} else {
return readAptS();
}
}
TQStringList DEBAPT::readAptS()
{
TQString cmd = "cat -E " APT_SOURCE;
TQStringList list = kpty->run(cmd);
if (!kpty->Result) {
TQString s;
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
(*it).truncate((*it).length() - 1);
(*it) = (*it).stripWhiteSpace();
}
return list;
} else {
return 0;
}
}
TQStringList DEBAPT::readAptF()
{
TQStringList lines;
TQFile file( "/etc/apt/sources.list" );
if ( file.open( IO_ReadOnly ) ) {
TQTextStream stream( &file );
TQString line;
while ( !stream.atEnd() ) {
line = stream.readLine(); // line of text excluding '\n'
line = line.stripWhiteSpace();
lines += line;
}
file.close();
return lines;
} else {
return 0;
}
}
void DEBAPT::writeApt(const TQStringList &list) {
kdDebug() << "writeApt\n";
TQString cmd = "sh -c \"/bin/echo -e '";
for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
TQString s = *it;
s.replace("\""," ");
s.replace("'"," ");
s.replace("!"," ");
s.replace("`"," ");
cmd += s;
cmd += "\n";
}
cmd += "' > /etc/apt/sources.list.n; if [ $? = 0 ]; then ";
cmd += "mv /etc/apt/sources.list /etc/apt/sources.list.b; mv /etc/apt/sources.list.n /etc/apt/sources.list; fi\" ";
TQStringList rlist = kpty->run(cmd,TRUE,TRUE);
//for ( TQStringList::Iterator it = rlist.begin(); it != rlist.end(); ++it ) {
// kdDebug() << "SL=" << *it << "\n";
//}
}
#include "debAptInterface.moc"
|