Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1138096 - [doc] add examples on install, resolve, do_transaction api usage
Summary: [doc] add examples on install, resolve, do_transaction api usage
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Radek Holy
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1159255 (view as bug list)
Depends On:
Blocks: 1156485
TreeView+ depends on / blocked
 
Reported: 2014-09-04 05:12 UTC by Parag Nemade
Modified: 2015-10-06 02:14 UTC (History)
8 users (show)

Fixed In Version: hawkey-0.5.3-2.fc21
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-02-20 08:32:43 UTC
Type: Bug
Embargoed:


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

Description Parag Nemade 2014-09-04 05:12:32 UTC
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 05:17:33 UTC
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 05:28:53 UTC
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 12:10:30 UTC
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 12:14:26 UTC
Created attachment 934398 [details]
sample code that fails

Comment 5 Parag Nemade 2014-09-04 12:14:43 UTC
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 07:11:26 UTC
@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 12:57:52 UTC
@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 17:13:50 UTC
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 09:45:13 UTC
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 15:06:55 UTC
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 07:51:00 UTC
I got the install, resolve, do_transaction functions working in an individual code. Therefore closing this bug.

Comment 12 Radek Holy 2014-10-31 11:26:13 UTC
*** Bug 1159255 has been marked as a duplicate of this bug. ***

Comment 13 Radek Holy 2014-10-31 11:27:48 UTC
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 11:43:19 UTC
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 11:52:52 UTC
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 16:25:07 UTC
Some examples have been added by an upstream commit 435b9acb74b71f8deb045a05df8a9c852c828538.

Comment 17 Fedora Update System 2015-02-16 00:03:28 UTC
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 08:04:22 UTC
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 08:32:43 UTC
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.