From 63d5fe316cb691bafb84c98438ec1607322baa60 Mon Sep 17 00:00:00 2001 From: Gabriele Mohr Date: Wed, 10 Oct 2012 12:31:31 +0200 Subject: [PATCH] Provide information whether acceptance of a product license is needed rename methods concerning license acceptance --- zypp/RepoInfo.cc | 32 ++++++++++++++++++++++++++++---- zypp/RepoInfo.h | 5 +++++ zypp/ResObject.cc | 7 +++++++ zypp/ResObject.h | 8 ++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/zypp/RepoInfo.cc b/zypp/RepoInfo.cc index 91d72c2..544531b 100644 --- a/zypp/RepoInfo.cc +++ b/zypp/RepoInfo.cc @@ -283,6 +283,34 @@ namespace zypp return ! licenseTgz.empty() && PathInfo(licenseTgz).isFile(); } + bool RepoInfo::needToAcceptLicense() const + { + static const std::string noAcceptanceFile = "no-acceptance-needed\n"; + bool accept = true; + + Pathname licenseTgz( _pimpl->licenseTgz() ); + if ( licenseTgz.empty() || ! PathInfo( licenseTgz ).isFile() ) + return false; // no licenses at all + + ExternalProgram::Arguments cmd; + cmd.push_back( "tar" ); + cmd.push_back( "-t" ); + cmd.push_back( "-z" ); + cmd.push_back( "-f" ); + cmd.push_back( licenseTgz.asString() ); + + ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout ); + for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) + { + if ( output == noAcceptanceFile ) + { + accept = false; + } + } + MIL << "License for " << this->name() << " has to be accepted: " << (accept?"true":"false" ) << endl; + return accept; + } + std::string RepoInfo::getLicense( const Locale & lang_r ) { LocaleSet avlocales( getLicenseLocales() ); @@ -351,10 +379,6 @@ namespace zypp else ret.insert( Locale( std::string( output.c_str()+license.size(), output.size()- license.size() - dotTxt.size() ) ) ); } - else - { - WAR << " " << output; - } } prog.close(); return ret; diff --git a/zypp/RepoInfo.h b/zypp/RepoInfo.h index 8ac20f5..71eb895 100644 --- a/zypp/RepoInfo.h +++ b/zypp/RepoInfo.h @@ -309,6 +309,11 @@ namespace zypp /** Whether there is a license associated with the repo. */ bool hasLicense() const; + /** Whether the repo license has to be accepted, e.g. there is no + * no acceptance needed for openSUSE. + */ + bool needToAcceptLicense() const; + /** Return the best license for the current (or a specified) locale. */ std::string getLicense( const Locale & lang_r = Locale() ); diff --git a/zypp/ResObject.cc b/zypp/ResObject.cc index 37b6fa5..958c671 100644 --- a/zypp/ResObject.cc +++ b/zypp/ResObject.cc @@ -75,6 +75,13 @@ namespace zypp return ret; } + bool ResObject::needToAcceptLicense() const + { + if ( isKind() ) + return repoInfo().needToAcceptLicense( ); + return true; + } + std::string ResObject::distribution() const { return lookupStrAttribute( sat::SolvAttr::distribution ); } diff --git a/zypp/ResObject.h b/zypp/ResObject.h index 286db0d..ddae8a7 100644 --- a/zypp/ResObject.h +++ b/zypp/ResObject.h @@ -130,6 +130,14 @@ namespace zypp */ std::string licenseToConfirm( const Locale & lang_r = Locale() ) const; + /** + * \short Acceptance of Product License needed? + * + * Returns whether a product license has to be accepted + * (no acceptance is needed for openSUSE) + */ + bool needToAcceptLicense() const; + /** * \short Vendor * -- 2.7.4