Diffstat (limited to 'noncore/settings/packagemanager/oipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 188 |
1 files changed, 71 insertions, 117 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index 13f3d7d..eeb0131 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp | |||
@@ -30,42 +30,61 @@ | |||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "oipkg.h" | 32 | #include "oipkg.h" |
33 | 33 | ||
34 | #include <stdio.h> | 34 | #include <stdlib.h> |
35 | #include <string.h> | ||
35 | 36 | ||
36 | #include <qdir.h> | 37 | #include <qdir.h> |
37 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qmessagebox.h> | ||
38 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
39 | 41 | ||
40 | #include <opie/oprocess.h> | ||
41 | |||
42 | const QString IPKG_EXEC = "ipkg"; // Fully-qualified name of Ipkg executable | ||
43 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file | 42 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file |
44 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files | 43 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files |
45 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists | 44 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists |
46 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location | 45 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location |
47 | 46 | ||
47 | OIpkg *oipkg; | ||
48 | |||
49 | int fIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) | ||
50 | { | ||
51 | oipkg->ipkgOutput( msg ); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | char* fIpkgResponse( char */*question*/ ) | ||
56 | { | ||
57 | return 0x0; | ||
58 | } | ||
59 | |||
48 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) | 60 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) |
49 | : QObject( parent, name ) | 61 | : QObject( parent, name ) |
50 | , m_config( config ) | 62 | , m_config( config ) |
51 | , m_ipkgExec( IPKG_EXEC ) // TODO - find executable? | ||
52 | , m_confInfo( NULL ) | 63 | , m_confInfo( NULL ) |
53 | , m_ipkgExecOptions( 0 ) | 64 | , m_ipkgExecOptions( 0 ) |
54 | , m_ipkgExecVerbosity( 1 ) | 65 | , m_ipkgExecVerbosity( 1 ) |
55 | , m_ipkgProcess( NULL ) | ||
56 | { | 66 | { |
67 | oipkg = this; | ||
68 | |||
69 | // Initialize libipkg | ||
70 | if ( ipkg_init( &fIpkgMessage, &fIpkgResponse, &m_ipkgArgs ) ) | ||
71 | QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error initialing libipkg" ) ); | ||
72 | |||
73 | // Default ipkg run-time arguments | ||
74 | m_ipkgArgs.noaction = false; | ||
75 | m_ipkgArgs.force_defaults = true; | ||
57 | } | 76 | } |
58 | 77 | ||
59 | OIpkg::~OIpkg() | 78 | OIpkg::~OIpkg() |
60 | { | 79 | { |
61 | // Upon destruction, ensure that items in config list are deleted with list | 80 | // Upon destruction, ensure that items in config list are deleted with list |
62 | if ( m_confInfo ) | 81 | if ( m_confInfo ) |
63 | m_confInfo->setAutoDelete( true ); | 82 | m_confInfo->setAutoDelete( true ); |
64 | 83 | ||
65 | // Terminate any running ipkg processes | 84 | // Free up libipkg resources |
66 | if ( m_ipkgProcess ) | 85 | if ( ipkg_deinit( &m_ipkgArgs ) ) |
67 | delete m_ipkgProcess; | 86 | QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error freeing libipkg" ) ); |
68 | } | 87 | } |
69 | 88 | ||
70 | OConfItemList *OIpkg::configItems() | 89 | OConfItemList *OIpkg::configItems() |
71 | { | 90 | { |
@@ -253,138 +272,73 @@ OPackageList *OIpkg::installedPackages( const QString &destName, const QString & | |||
253 | return pl; | 272 | return pl; |
254 | } | 273 | } |
255 | 274 | ||
256 | bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, | 275 | bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, |
257 | const QObject *receiver, const char *slotOutput, const char *slotErrors, | 276 | const QObject *receiver, const char *slotOutput, bool rawOutput ) |
258 | const char *slotFinished, bool rawOutput ) | ||
259 | { | 277 | { |
260 | if ( command == OPackage::NotDefined ) | 278 | if ( command == OPackage::NotDefined ) |
261 | return false; | 279 | return false; |
262 | 280 | ||
263 | // Set up command line for execution | 281 | // Set ipkg run-time options/arguments |
264 | QStringList cmdLine; | 282 | m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); |
265 | cmdLine.append( IPKG_EXEC ); | 283 | m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); |
266 | 284 | // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); | |
267 | QString verbosity( "-V" ); | 285 | m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); |
268 | verbosity.append( QString::number( m_ipkgExecVerbosity ) ); | 286 | m_ipkgArgs.verbosity = m_ipkgExecVerbosity; |
269 | cmdLine.append( verbosity ); | 287 | if ( m_ipkgArgs.dest ) |
270 | 288 | free( m_ipkgArgs.dest ); | |
271 | // Determine Ipkg execution options | 289 | if ( !destination.isNull() ) |
272 | if ( command == OPackage::Install && destination != QString::null ) | ||
273 | { | 290 | { |
274 | // TODO - Set destination for installs | 291 | int len = destination.length() + 1; |
275 | cmdLine.append( "-dest" ); | 292 | m_ipkgArgs.dest = (char *)malloc( len ); |
276 | cmdLine.append( destination ); | 293 | strncpy( m_ipkgArgs.dest, destination, destination.length() ); |
294 | m_ipkgArgs.dest[ len - 1 ] = '\0'; | ||
277 | } | 295 | } |
296 | else | ||
297 | m_ipkgArgs.dest = 0x0; | ||
278 | 298 | ||
279 | if ( command != OPackage::Update && command != OPackage::Download ) | 299 | // Connect output signal to widget |
300 | if ( rawOutput ) | ||
280 | { | 301 | { |
281 | if ( m_ipkgExecOptions & FORCE_DEPENDS ) | 302 | if ( slotOutput ) |
282 | cmdLine.append( "-force-depends" ); | 303 | connect( this, SIGNAL(execOutput(char *)), receiver, slotOutput ); |
283 | if ( m_ipkgExecOptions & FORCE_REINSTALL ) | 304 | } |
284 | cmdLine.append( "-force-reinstall" ); | 305 | else |
285 | if ( m_ipkgExecOptions & FORCE_REMOVE ) | 306 | { |
286 | cmdLine.append( "-force-removal-of-essential-packages" ); | 307 | // TODO - connect to local slot and parse output before emitting execOutput |
287 | if ( m_ipkgExecOptions & FORCE_OVERWRITE ) | ||
288 | cmdLine.append( "-force-overwrite" ); | ||
289 | if ( m_ipkgExecVerbosity == 3 ) | ||
290 | cmdLine.append( "-verbose_wget" ); | ||
291 | |||
292 | // TODO | ||
293 | // Handle make links | ||
294 | // Rules - If make links is switched on, create links to root | ||
295 | // if destDir is NOT / | ||
296 | /* | ||
297 | if ( m_ipkgExecOptions & MAKE_LINKS ) | ||
298 | { | ||
299 | // If destDir == / turn off make links as package is being insalled | ||
300 | // to root already. | ||
301 | if ( destDir == "/" ) | ||
302 | m_ipkgExecOptions ^= MAKE_LINKS; | ||
303 | } | ||
304 | */ | ||
305 | } | 308 | } |
306 | 309 | ||
307 | QString cmd; | ||
308 | switch( command ) | 310 | switch( command ) |
309 | { | 311 | { |
310 | case OPackage::Install: cmd = "install"; | 312 | case OPackage::Update : ipkg_lists_update( &m_ipkgArgs ); |
311 | break; | ||
312 | case OPackage::Remove: cmd = "remove"; | ||
313 | break; | 313 | break; |
314 | case OPackage::Update: cmd = "update"; | 314 | case OPackage::Upgrade : ipkg_packages_upgrade( &m_ipkgArgs ); |
315 | break; | 315 | break; |
316 | case OPackage::Upgrade: cmd = "upgrade"; | 316 | case OPackage::Install : { |
317 | break; | 317 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
318 | case OPackage::Download: cmd = "download"; | 318 | { |
319 | break; | 319 | ipkg_packages_install( &m_ipkgArgs, (*it) ); |
320 | case OPackage::Info: cmd = "info"; | 320 | } |
321 | }; | ||
321 | break; | 322 | break; |
322 | case OPackage::Files: cmd = "files"; | 323 | case OPackage::Remove : { |
324 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | ||
325 | { | ||
326 | ipkg_packages_remove( &m_ipkgArgs, (*it), true ); | ||
327 | } | ||
328 | }; | ||
323 | break; | 329 | break; |
324 | //case OPackage::Version: cmd = "" ); | 330 | //case OPackage::Download : ; |
325 | // break; | 331 | // break; |
326 | default: | 332 | default : break; |
327 | break; | ||
328 | }; | 333 | }; |
329 | cmdLine.append( cmd ); | ||
330 | |||
331 | // TODO | ||
332 | // If we are removing, reinstalling or upgrading packages and make links option is selected | ||
333 | // create the links | ||
334 | /* | ||
335 | if ( command == Remove || command == Upgrade ) | ||
336 | { | ||
337 | createLinks = false; | ||
338 | if ( flags & MAKE_LINKS ) | ||
339 | { | ||
340 | emit outputText( tr( "Removing symbolic links...\n" ) ); | ||
341 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | ||
342 | emit outputText( QString( " " ) ); | ||
343 | } | ||
344 | } | ||
345 | */ | ||
346 | // Append package list (if any) to end of command line | ||
347 | if ( parameters && !parameters->isEmpty() ) | ||
348 | { | ||
349 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | ||
350 | { | ||
351 | cmdLine.append( *it ); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | // Create OProcess | ||
356 | if ( m_ipkgProcess ) | ||
357 | delete m_ipkgProcess; | ||
358 | m_ipkgProcess = new OProcess( cmdLine, this ); | ||
359 | |||
360 | // Connect signals (if any) | ||
361 | if ( receiver ) | ||
362 | { | ||
363 | if ( rawOutput ) | ||
364 | { | ||
365 | if ( slotOutput ) | ||
366 | connect( m_ipkgProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), receiver, slotOutput ); | ||
367 | if ( slotErrors ) | ||
368 | connect( m_ipkgProcess, SIGNAL(receivedStderr(OProcess*,char*,int)), receiver, slotErrors ); | ||
369 | if ( slotFinished ) | ||
370 | connect( m_ipkgProcess, SIGNAL(processExited(OProcess*)), receiver, slotFinished ); | ||
371 | } | ||
372 | else // !rawOutput | ||
373 | { | ||
374 | // TODO - how should it handle partial lines? (i.e. "Installing opi", "e-aqpkg...") | ||
375 | } | ||
376 | } | ||
377 | 334 | ||
378 | // Run process | 335 | return true; |
379 | printf( "Running: \'%s\'\n", cmdLine.join( " " ).latin1() ); | ||
380 | return m_ipkgProcess->start( OProcess::NotifyOnExit, OProcess::All ); | ||
381 | } | 336 | } |
382 | 337 | ||
383 | void OIpkg::abortCommand() | 338 | void OIpkg::ipkgOutput( char *msg ) |
384 | { | 339 | { |
385 | if ( m_ipkgProcess ) | 340 | emit execOutput( msg ); |
386 | delete m_ipkgProcess; | ||
387 | } | 341 | } |
388 | 342 | ||
389 | void OIpkg::loadConfiguration() | 343 | void OIpkg::loadConfiguration() |
390 | { | 344 | { |