Skip to content

Commit

Permalink
Merge pull request #80 from yast/improve-license-handling
Browse files Browse the repository at this point in the history
Improve license handling
  • Loading branch information
imobachgs committed Aug 22, 2017
2 parents cd2f04c + c6059e5 commit 007fcc9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings-devel-doc.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-pkg-bindings-devel-doc
Version: 3.3.0
Version: 3.3.1
Release: 0
License: GPL-2.0
Group: Documentation/HTML
Expand Down
11 changes: 11 additions & 0 deletions package/yast2-pkg-bindings.changes
@@ -1,3 +1,14 @@
-------------------------------------------------------------------
Mon Aug 21 07:35:43 UTC 2017 - igonzalezsosa@suse.com

- Add a Pkg.PrdHasLicenseConfirmed and
Pkg.PrdMarkLicenseUnconfirmed (FATE#322276)
- Pkg.PrdGetLicenseToConfirm always returns the license, no matter
whether is confirmed or not
- Add a second argument to Pkg.PrdGetLicenseToConfirm in order
get the license translated to the given language
- 3.3.1

-------------------------------------------------------------------
Wed Aug 16 11:20:16 UTC 2017 - igonzalezsosa@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-pkg-bindings
Version: 3.3.0
Version: 3.3.1
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
93 changes: 65 additions & 28 deletions src/Package.cc
Expand Up @@ -48,6 +48,7 @@
#include <zypp/sat/WhatProvides.h>
#include <zypp/ZYppFactory.h>
#include <zypp/repo/PackageProvider.h>
#include <zypp/Locale.h>

#include <fstream>
#include <sstream>
Expand Down Expand Up @@ -736,6 +737,20 @@ static zypp::Package::constPtr find_package(const string &name)
return NULL;
}

static zypp::ui::Selectable::Ptr find_selectable_product(const string &name)
{
if (name.empty())
return NULL;

using zypp::ui::Selectable;
Selectable::Ptr selectable = Selectable::get( zypp::ResKind::product, name );

if (!selectable)
y2warning("Product '%s' not found", name.c_str());

return selectable;
}

/**
@builtin PkgSummary
Expand Down Expand Up @@ -2733,49 +2748,35 @@ YCPBoolean PkgFunctions::PkgMarkLicenseConfirmed (const YCPString & package)
@short Return the product's license to confirm
@param string name of a product
@return string license to confirm. It returns the empty string if the license was already
confirmed.
@param string locale code (for instance, "en_US.UTF-8")
@return string license to confirm
*/
YCPValue
PkgFunctions::PrdGetLicenseToConfirm(const YCPString& product)
PkgFunctions::PrdGetLicenseToConfirm(const YCPString& product, const YCPString& localeCode)
{
using zypp::ui::Selectable;
std::string productName(product->value());
Selectable::Ptr selectable = Selectable::get( zypp::ResKind::product, productName );
zypp::ui::Selectable::Ptr selectable = find_selectable_product(product->value());
zypp::Locale locale(localeCode->value());

if (!selectable)
{
y2warning("Product '%s' not found", productName.c_str());
return YCPVoid();
}

if (!selectable->hasLicenceConfirmed())
{
return YCPString(selectable->candidateObj().licenseToConfirm());
} else {
return YCPString("");
}
return YCPString(selectable->candidateObj().licenseToConfirm(locale));
}

/**
@builtin PrdMarkLicenseConfirmed
@short Mark a product's license as confirmed
@param string name of a product
@return boolean true if the license was confirmed.
@return boolean true if the license was confirmed
*/
YCPValue
PkgFunctions::PrdMarkLicenseConfirmed(const YCPString& product)
{
using zypp::ui::Selectable;
std::string productName(product->value());
Selectable::Ptr selectable = Selectable::get( zypp::ResKind::product, productName );
zypp::ui::Selectable::Ptr selectable = find_selectable_product(product->value());

if (!selectable)
{
y2warning("Product '%s' not found", productName.c_str());
return YCPVoid();
}

if (!selectable->hasLicenceConfirmed()) {
selectable->setLicenceConfirmed();
Expand All @@ -2785,6 +2786,29 @@ PkgFunctions::PrdMarkLicenseConfirmed(const YCPString& product)
}
}

/**
@builtin PrdUnmarkLicenseConfirmed
@short Unmark a product's license so it is not confirmed anymore
@param string name of a product
@return boolean true if the license was unconfirmed
*/
YCPValue
PkgFunctions::PrdMarkLicenseUnconfirmed(const YCPString& product)
{
zypp::ui::Selectable::Ptr selectable = find_selectable_product(product->value());

if (!selectable)
return YCPVoid();

if (selectable->hasLicenceConfirmed()) {
selectable->setLicenceConfirmed(false);
return YCPBoolean(true);
} else {
return YCPBoolean(false);
}
}

/**
@builtin PrdNeedToAcceptLicense
Expand All @@ -2795,19 +2819,32 @@ PkgFunctions::PrdMarkLicenseConfirmed(const YCPString& product)
YCPValue
PkgFunctions::PrdNeedToAcceptLicense(const YCPString& product)
{
using zypp::ui::Selectable;
std::string productName(product->value());
Selectable::Ptr selectable = Selectable::get( zypp::ResKind::product, productName );
zypp::ui::Selectable::Ptr selectable = find_selectable_product(product->value());

if (!selectable)
{
y2warning("Product '%s' not found", productName.c_str());
return YCPVoid();
}

return YCPBoolean(selectable->candidateObj().needToAcceptLicense());
}

/**
@builtin PrdHasLicenseConfirmed
@short Product license to confirm
@param string name of a product
@return boolean true if the license is confirmed
*/
YCPValue
PkgFunctions::PrdHasLicenseConfirmed(const YCPString& product)
{
zypp::ui::Selectable::Ptr selectable = find_selectable_product(product->value());

if (!selectable)
return YCPVoid();

return YCPBoolean(selectable->hasLicenceConfirmed());
}


/****************************************************************************************
* @builtin RpmChecksig
Expand Down
6 changes: 5 additions & 1 deletion src/PkgFunctions.h
Expand Up @@ -733,11 +733,15 @@ class PkgFunctions
/* TYPEINFO: string(string)*/
YCPBoolean PkgMarkLicenseConfirmed (const YCPString & package);
/* TYPEINFO: string(string)*/
YCPValue PrdGetLicenseToConfirm (const YCPString& product);
YCPValue PrdGetLicenseToConfirm (const YCPString& product, const YCPString& localeCode);
/* TYPEINFO: boolean(string)*/
YCPValue PrdMarkLicenseConfirmed (const YCPString& product);
/* TYPEINFO: boolean(string)*/
YCPValue PrdMarkLicenseUnconfirmed(const YCPString& product);
/* TYPEINFO: boolean(string)*/
YCPValue PrdNeedToAcceptLicense (const YCPString& product);
/* TYPEINFO: boolean(string)*/
YCPValue PrdHasLicenseConfirmed(const YCPString& product);

/* TYPEINFO: boolean(string)*/
YCPBoolean RpmChecksig( const YCPString & filename );
Expand Down

0 comments on commit 007fcc9

Please sign in to comment.