Provide information whether acceptance of a product license is needed
authorGabriele Mohr <gs@suse.de>
Wed, 10 Oct 2012 10:31:31 +0000 (12:31 +0200)
committerGabriele Mohr <gs@suse.de>
Wed, 10 Oct 2012 12:47:10 +0000 (14:47 +0200)
rename methods concerning license acceptance

zypp/RepoInfo.cc
zypp/RepoInfo.h
zypp/ResObject.cc
zypp/ResObject.h

index 91d72c2..544531b 100644 (file)
@@ -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;
index 8ac20f5..71eb895 100644 (file)
@@ -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() );
 
index 37b6fa5..958c671 100644 (file)
@@ -75,6 +75,13 @@ namespace zypp
     return ret;
   }
 
+  bool ResObject::needToAcceptLicense() const
+  {
+    if ( isKind<Product>() )
+      return repoInfo().needToAcceptLicense( );
+    return true;
+  }
+
   std::string ResObject::distribution() const
   { return lookupStrAttribute( sat::SolvAttr::distribution ); }
 
index 286db0d..ddae8a7 100644 (file)
@@ -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
      *