Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 423209 - =app-portage/gentoolkit-0.3.0.6-r3 with >sys-apps/portage-2.1.10.49 - FileOwner raises unexpected AttributeError exception
Summary: =app-portage/gentoolkit-0.3.0.6-r3 with >sys-apps/portage-2.1.10.49 - FileOwn...
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Tools (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage Tools Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 346443
  Show dependency tree
 
Reported: 2012-06-23 20:56 UTC by Alex Brandt (RETIRED)
Modified: 2012-11-06 17:25 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
return string from gentoolkit's Package.__str__ (gentoolkit-0.3.0.6-package-str.patch,428 bytes, patch)
2012-06-24 05:24 UTC, Brennan Shacklett
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Brandt (RETIRED) gentoo-dev 2012-06-23 20:56:07 UTC
When updating portage to anything stable or testing (currently this includes 2.1.10.65 and 2.1.11) the FileOwner helper from gentoolkit-0.3.0.6-r3 raises an AttributeError on Package.  I wasn't sure if this would be a bug in gentoolkit or in portage so I'm indicating both and appropriate versions to help track this down.  I also would understand if this is no longer a recognized way to accomplish this and would be willing to accept advice on how to do this the new way.

Reproducible: Always

Steps to Reproduce:
1.Run the following snippet of code from a python interpreter or script:
from gentoolkit.helpers import FileOwner
finder = FileOwner()
package = unicode(finder(("/usr/bin/python", ))[0][0])
2.Observe exception indicating that a Package can't be split.
Actual Results:  
The exception raised is the following for the snippet provided (including snippet):


alunduil@elijah ~ % ipython

In [1]: from gentoolkit.helpers import FileOwner

In [2]: finder = FileOwner()

In [3]: package = unicode(finder(("/usr/bin/python", ))[0][0])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/alunduil/<ipython-input-3-c6fe5207bc02> in <module>()
----> 1 package = unicode(finder(("/usr/bin/python", ))[0][0])

/usr/lib64/portage/pym/portage/versions.pyc in __init__(self, cpv, slot, repo, eapi)
    346                         cpv = _unicode_decode(cpv)
    347                 _unicode.__init__(cpv)
--> 348                 self.__dict__['cpv_split'] = catpkgsplit(cpv, eapi=eapi)
    349                 if self.cpv_split is None:
    350                         raise InvalidData(cpv)

/usr/lib64/portage/pym/portage/versions.pyc in catpkgsplit(mydata, silent, eapi)
    314         except AttributeError:
    315                 pass
--> 316         mysplit = mydata.split('/', 1)
    317         p_split=None
    318         if len(mysplit)==1:

AttributeError: 'Package' object has no attribute 'split'


Expected Results:  
The expectation (and the results with a compatible version of portage) are as follows (again including snippet):


alunduil@elijah ~ % ipython

In [1]: from gentoolkit.helpers import FileOwner

In [2]: finder = FileOwner()

In [3]: package = unicode(finder(("/usr/bin/python", ))[0][0])

In [4]: print package
app-admin/eselect-python-20111108


I tried looking around to see if this bug was a duplicate but wasn't able to find anything.  I apologize if this is already a known issue.
Comment 1 Brennan Shacklett 2012-06-24 05:24:05 UTC
Created attachment 316121 [details, diff]
return string from gentoolkit's Package.__str__

This seems to be a bug in gentoolkit. It looks like the problem is that gentoolkit has a Package class which has a __str__ method which gets called when this example code is run, but that method doesn't actually return a string, and instead returns a Package, so when the portage code tries to split the variable which it expects to be a string, it can't.

This patch casts the variable returned by the __str__ method into a string.
Comment 2 Alex Brandt (RETIRED) gentoo-dev 2012-06-24 15:13:59 UTC
(In reply to comment #1)
> This patch casts the variable returned by the __str__ method into a string.

Just curious but is it convention to use str in gentoolkit rather than unicode?
Comment 3 Brennan Shacklett 2012-06-24 17:05:28 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > This patch casts the variable returned by the __str__ method into a string.
> 
> Just curious but is it convention to use str in gentoolkit rather than
> unicode?

I used str() because gentoolkit has to be able to work with python3 as well, which automatically is using unicode, and doesn't have the unicode() method.

Regardless, I ran a couple tests and it looks like by the time the variable is passed into the portage code, it is recognized as being of type unicode.

FYI, I'm not a gentoo or a gentoolkit dev, so if you want a completely authoritative answer, I would ask one of them.
Comment 4 Alex Brandt (RETIRED) gentoo-dev 2012-07-24 15:52:50 UTC
With the proposed patch to gentoolkit everything works as expected for this test case.
Comment 5 Paul Varner (RETIRED) gentoo-dev 2012-07-24 17:19:33 UTC
The patch has been committed to the gentoolkit repository and can be tested/verified with gentoolkit-9999
Comment 6 Alex Brandt (RETIRED) gentoo-dev 2012-08-24 13:55:01 UTC
The 9999 version works perfectly.  Loving the performance boost it buys as well.  Thanks for the good work guys.  Looking forward to a stable release of this codebase.
Comment 7 Paul Varner (RETIRED) gentoo-dev 2012-11-06 17:25:00 UTC
Released in gentoolkit-0.3.0.7