-rw-r--r-- | noncore/unsupported/oipkg/package.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/noncore/unsupported/oipkg/package.cpp b/noncore/unsupported/oipkg/package.cpp index 7aaa240..1054a1d 100644 --- a/noncore/unsupported/oipkg/package.cpp +++ b/noncore/unsupported/oipkg/package.cpp @@ -1,217 +1,217 @@ /*************************************************************************** * * * 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. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #include "package.h" #include <qpe/process.h> #include <qpe/stringutil.h> #include <qfile.h> #include <qtextstream.h> #include <stdlib.h> #include <unistd.h> #include "debug.h" Package::Package( QObject *parent, const char *name ) : QObject(parent,name) { } Package::~Package() { } Package::Package( PackageManagerSettings *s, QObject *parent, const char *name ) : QObject(parent,name) { Package(parent,name); init(s); } void Package::init( PackageManagerSettings *s ) { settings = s; _size = ""; _section = ""; _subsection = ""; _shortDesc = ""; _desc = ""; _name = ""; _toProcess = false; _useFileName = false; _old = false; _status = ""; _dest = settings->getDestinationName(); _link = settings->createLinks(); _versions=0; _version=""; } Package::Package( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name ) : QObject(parent,name) -{ +{ init(s); parsePackage( pack ); } Package::Package( QString n, PackageManagerSettings *s, QObject *parent, const char *name ) : QObject(parent,name) -{ +{ init(s); if ( !QFile::exists( n ) ) { _name = QString( n ); }else{ pvDebug(4,"remote file: "+n); parseIpkgFile( n ); _useFileName = true; _fileName = QString( n ); } } Package::Package( Package *pi, QObject *parent, const char *name ) : QObject(parent,name) { init(pi->settings); copyValues( pi ); } void Package::setValue( QString n, QString t ) { if ( n == "Package" ) { _name = QString( t ); }else if ( n == "Installed-Size" ) { _size = t; // }else if ( n == "Priority") // { }else if ( n == "Section") { setSection( t ); // }else if ( n == "Maintainer") // { // // }else if ( n == "Architecture") // { }else if ( n == "Version") { _version = t; // }else if ( n == "Pre-Depends") // { // // }else if ( n == "Depends") // { }else if ( n == "Filename") { _fileName = t; // }else if ( n == "Size") // { -// +// // }else if ( n == "MD5Sum") // { }else if ( n == "Description") { setDesc( t ); }else if ( n == "Status") { if ( installed() ) return; _status = t; // }else if ( n == "Essential") // { }else{ _values.insert(n,new QString(t)); } } QString Package::name() { if (_displayName.isEmpty() ) return _name; else return _displayName; } QString Package::installName() { if (_useFileName) return _fileName; else return _name; } QString Package::packageName() { QString pn = installName(); pn = pn.right(pn.length()-pn.findRev("/")); pn = pn.left(pn.find("_")); return pn; } bool Package::installed() { if (_status.contains("installed")) { if (_status.contains("not-installed")) { _toProcess = true; return false; } else return true; } else if (_versions) { QDictIterator<Package> other( *_versions ); while ( other.current() ) { if (other.current()->status().contains("installed") && other.current()->version() == version()) return true; ++other; } } return false; } bool Package::otherInstalled() { if (_versions) { QDictIterator<Package> other( *_versions ); while ( other.current() ) { if (other.current()->installed()) return true; ++other; } } return false; } void Package::setDesc( QString s ) { _desc = s; _shortDesc = s.left( s.find("\n") ); } QString Package::desc() { return _desc; } QString Package::shortDesc() { return _shortDesc; } QString Package::size() @@ -292,181 +292,188 @@ void Package::setSection( QString s) if ( i > 0 ) { _section = s.left(i); _subsection = s.mid(i+1); }else{ _section = s; _subsection = ""; } } QString Package::subSection() { return _subsection; } void Package::parsePackage( QStringList pack ) { if ( pack.isEmpty() ) return; int count = pack.count(); for( int i = 0; i < count; i++ ) { QString line = pack[i]; int sep = line.find( QRegExp(":[\t ]+") ); if ( sep >= 0 ) { QString tag = line.left(sep); QString value = line.mid(sep+2).simplifyWhiteSpace(); setValue( tag, value ); }else{ } } return; } QString Package::details() { QString status; Process ipkg_status(QStringList() << "ipkg" << "info" << name() ); QString description; if ( ipkg_status.exec("",status) ) { QStringList lines = QStringList::split('\n',status,TRUE); for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { QString line = *it; if ( line == " ." ) { description.append("<p>"); } else if ( line[0] == ' ' || line[0] == '\t' ) { // continuation description.append(" "); description.append(Qtopia::escapeString(line)); } else { int sep = line.find(QRegExp(":[\t ]+")); if ( sep >= 0 ) { QString tag = line.left(sep); description.append("<br>"); description.append("<b>"); description.append(Qtopia::escapeString(tag)); description.append(":</b> "); description.append(Qtopia::escapeString(line.mid(sep+2))); } else { description.append(" "); description.append(Qtopia::escapeString(line)); } } } } return description; } void Package::processed() { _toProcess = false; //hack, but we're not writing status anyway... if ( installed() ) _status = "install"; else _status = "installed"; } QString Package::dest() { if ( installed()||(!installed() && _toProcess) ) return _dest!=""?_dest:settings->getDestinationName(); else return ""; } void Package::setDest( QString d ) { if ( d == "remote") _useFileName = true; else _dest = d; } void Package::setOn() { - _toProcess = true; + _toProcess = true; } bool Package::link() { if ( _dest == "root" || (!installed() && !_toProcess) ) return false; return _link; } void Package::setLink(bool b) { _link = b; } void Package::parseIpkgFile( QString file) { - system("tar xzf "+file+" -C /tmp"); - system("tar xzf /tmp/control.tar.gz -C /tmp"); +// 20020830 +// a quick hack to make oipkg understand the new ipk format +// neu: ar pf PACKAGE control.tar.gz | tar xfOz - ./control > /tmp/control + if (! system("ar pf "+file+" control.tar.gz | tar xfOz - ./control > /tmp/control") ) + { +//#old tar ipk format + system("tar xzf "+file+" -C /tmp"); + system("tar xzf /tmp/control.tar.gz -C /tmp"); + } QFile f("/tmp/control"); if ( f.open(IO_ReadOnly) ) { QTextStream t( &f ); QStringList pack; while ( !t.eof() ) { pack << t.readLine(); } f.close(); parsePackage( pack ); } - + } //QString Package::getPackageName() //{ // if ( _packageName.isEmpty() ) return _name; // else return _packageName; //} void Package::instalFromFile(bool iff) { _useFileName = iff; } void Package::setName(QString n) { _displayName = n; } QDict<QString>* Package::getFields() { - return &_values; + return &_values; } QString Package::status() { return _status; } bool Package::isOld() { if (!_versions) return false; QDictIterator<Package> other( *_versions ); while ( other.current() ) { if (other.current()->version() > version() ) return true; ++other; } return false; } bool Package::hasVersions() { if (!_versions) return false; else return true; } QDict<Package>* Package::getOtherVersions() { return _versions; } void Package::setOtherVersions(QDict<Package> *v) { _versions=v; } |