Bug 1138096 - [doc] add examples on install, resolve, do_transaction api usage
[doc] add examples on install, resolve, do_transaction api usage
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: dnf (Show other bugs)
21
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Radek Holy
Fedora Extras Quality Assurance
: Reopened
: 1159255 (view as bug list)
Depends On:
Blocks: 1156485
  Show dependency treegraph
 
Reported: 2014-09-04 01:12 EDT by Parag Nemade
Modified: 2015-10-05 22:14 EDT (History)
8 users (show)

See Also:
Fixed In Version: hawkey-0.5.3-2.fc21
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-02-20 03:32:43 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
sample code that fails (372 bytes, text/plain)
2014-09-04 08:14 EDT, Parag Nemade
no flags Details

  None (edit)
Description Parag Nemade 2014-09-04 01:12:32 EDT
Description of problem:
Add some documentation on install, resolve, do_transaction api usage.

Version-Release number of selected component (if applicable):
dnf-0.6.1

How reproducible:
always
Comment 1 Parag Nemade 2014-09-04 01:17:33 EDT
e.g. its not clear to me what api's one need to install a set of packages. Good to give examples in documentation.
Comment 2 Parag Nemade 2014-09-04 01:28:53 EDT
another thing install api does not return control back to calling program. If I am using following in my plugin code then code gets exit after executing install call and will not continue further in the calling program.

<snippet>
for pkg in pkgs:
               print(pkg)
               try:
########################################################
                   self.base.install(pkg)
########################################################
               except dnf.exceptions.MarkingError:
                   msg = _("No matching package to install: '%s'") % pkg
                   raise dnf.exceptions.Error(msg)
<snippet>
Comment 3 Honza Silhan 2014-09-04 08:10:30 EDT
Hi, thanks for the report. I don't know what's going on in your snippet, it should work if pkg is string object. IMO resolve and do_transaction is clear from the doc. We could write small dnf tutorial from sack loading, package installing, resolve and do_transaction.
Comment 4 Parag Nemade 2014-09-04 08:14:26 EDT
Created attachment 934398 [details]
sample code that fails
Comment 5 Parag Nemade 2014-09-04 08:14:43 EDT
I do have one more query for same install function. attached sample code. Appreciate your help to make it work.
Comment 6 Tim Lauridsen 2014-09-05 03:11:26 EDT
@Parag:
Look like you are missing the part there download the packages to install

https://github.com/timlau/dnf-apiex/blob/master/dnf-install.py#L82
Comment 7 Parag Nemade 2014-09-05 08:57:52 EDT
@Tim: Thanks for the pointer.

I thought install function call used to take care of downloading the packages. After correcting db.conf.releasever and using download_package() function I got the individual api sample code working now.
Comment 8 Parag Nemade 2014-09-05 13:13:50 EDT
But now I am trying to understand why same sample code not working in a dnf plugin. self.base.install(pkg) is not working there.
Comment 9 Parag Nemade 2014-09-06 05:45:13 EDT
Just take an example of builddep.py where also there is this function call
self.base.install(reldep_str)

this install() in plugins directly do all the steps like resolve, download_packages and do_transaction. Is there any other function for dnf.cli.Command class that will only mark packages for installation and not execute other steps?
Comment 10 Parag Nemade 2014-09-06 11:06:55 EDT
Further deep analysis reveals that self.base.install() when called from non-plugin code then it goes to 
 --- modulename: base, funcname: install
but the same function when called in plugin code its passing through 
 --- modulename: __init__, funcname: base
__init__.py(154):         return self.cli.base

and then both the code pass through dnf/base.py install() function but plugin code execute all the functions automatically like resolve, do_transaction....
Comment 11 Parag Nemade 2014-09-09 03:51:00 EDT
I got the install, resolve, do_transaction functions working in an individual code. Therefore closing this bug.
Comment 12 Radek Holy 2014-10-31 07:26:13 EDT
*** Bug 1159255 has been marked as a duplicate of this bug. ***
Comment 13 Radek Holy 2014-10-31 07:27:48 EDT
It seems that the examples are still needed. Especially during the YUM->DNF porting efforts. I'll take a look.
Comment 14 Tim Lauridsen 2014-10-31 07:43:19 EDT
Think that the misunderstanding here is the difference from plugin with a new command [1] to a standalone api program.

I a plugin using the dnf.cli.Command many actions like sack setup & execution of the transaction, will be done by the dnf cli, depended of that is set in the dnf.cli.demand.DemandSheet for the new cmd.

I a standalone api program, the user need to do everything self.

[1] : http://rpm-software-management.github.io/dnf/api_cli.html
Comment 15 Radek Holy 2014-10-31 07:52:52 EDT
Tim, thank you for the notice.

Nevertheless I think that originally this report concerned the general lack of examples in the documentation. This was the root cause of the Parag's concrete problem. I will emphasise the difference between extensions and plugins in the examples.
Comment 16 Radek Holy 2015-01-29 11:25:07 EST
Some examples have been added by an upstream commit 435b9acb74b71f8deb045a05df8a9c852c828538.
Comment 17 Fedora Update System 2015-02-15 19:03:28 EST
dnf-plugins-core-0.1.5-1.fc21,hawkey-0.5.3-2.fc21,dnf-0.6.4-1.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/dnf-plugins-core-0.1.5-1.fc21,hawkey-0.5.3-2.fc21,dnf-0.6.4-1.fc21
Comment 18 Fedora Update System 2015-02-17 03:04:22 EST
Package hawkey-0.5.3-2.fc21, dnf-plugins-core-0.1.5-1.fc21, dnf-0.6.4-1.fc21:
* should fix your issue,
* was pushed to the Fedora 21 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing hawkey-0.5.3-2.fc21 dnf-plugins-core-0.1.5-1.fc21 dnf-0.6.4-1.fc21'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-2139/dnf-plugins-core-0.1.5-1.fc21,hawkey-0.5.3-2.fc21,dnf-0.6.4-1.fc21
then log in and leave karma (feedback).
Comment 19 Fedora Update System 2015-02-20 03:32:43 EST
hawkey-0.5.3-2.fc21, dnf-plugins-core-0.1.5-1.fc21, dnf-0.6.4-1.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.