On Mon, Jan 06, 2014 at 04:56:27PM +0100, Michael Schaller wrote: > >If you think they are needed, go ahead. We have some other > >places using CompType() in the C++ code, though, and adding > >_deb variants for them would be complicated. > > > BaseDependency.relation_deb would only be a nice to have. I'm more > interested in having a string that represents the original > dependency string. A property that returns something like "python > (>= 2.7)" for a BaseDependency. > > Would it be okay to add something like this to BaseDependency? > Maybe BaseDependency.rawstr similar to BaseDependency.rawtype. > What do you think?
You'd still need a comp_type_deb in apt_pkg.Dependency in order to construct that string, or you simply replace "<" by "<<" and ">" by ">>" manually. You can write this, and make it the __str__() method of the dependency. While writing this I noticed that there is no DepIterator::CompTypeDeb, so I need to do it a bit more complicated if I want to implement comp_type_deb. diff --git a/python/cache.cc b/python/cache.cc index c0f1ede..443710b 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -1431,6 +1431,12 @@ static PyObject *DependencyGetCompType(PyObject *Self,void*) return PyString_FromString(Dep.CompType()); } +static PyObject *DependencyGetCompTypeDeb(PyObject *Self,void*) +{ + pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self); + return PyString_FromString(pkgCache::CompTypeDeb(Dep->CompareOp)); +} + static PyObject *DependencyGetDepType(PyObject *Self,void*) { pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self); @@ -1459,6 +1465,9 @@ static PyGetSetDef DependencyGetSet[] = { {"comp_type",DependencyGetCompType,0, "The type of comparison, as a string, namely one of:\n" "'<', '<=', '=', '!=', '>=', '>', ''."}, + {"comp_type_deb",DependencyGetCompTypeDeb,0, + "The type of comparison in Debian format, as a string, namely one of:\n" + "'<<', '<=', '=', '!=', '>=', '>>', ''."}, {"dep_type",DependencyGetDepType,0, "The type of the dependency; may be translated"}, {"dep_type_untranslated",DependencyGetDepTypeUntranslated,0, It still needs test cases and documentation in doc, but should work. I thus did not commit it. > >It's very simple. We only use __dstr("<") and __dstr(">"), so > >everything works as expected this way. > > > It is also used for "=" to let "==" equal "=". Is that also intentional? Most likely yes. Some docs mentioned "==" previously. > > >> > >>Can you elaborate what's the rationale behind this compatibility code? > >> > > > >In old python-apt versions, this was one of the cases where we returned > ><< instead of <. Using this compatibility code, old code keeps working. > > > I see. Is this code still needed? Shouldn't all these issues be > fixed in python-apt by now...? No issues in python-apt, but potential issues in client code. Removing it might silently break code. > Furthermore the code is hard to read and so no one realized that > there was a bug in it for nearly 4 years. I personally would write > it this way: > > # Relation verification and replaces for compatibility '>>' with '>' > # and '<<' with '<'. > RELATION_COMPAT = { > '>>': '>', '<<': '<', > '>': '>', '<': '<', > '>=': '>=', '<=': '<=', > '=': '=', '!=': '!=', > '': '', > } > > def __init__(self, name, rel, ver, pre, rawtype=None): > self.name = name > self.relation = RELATION_COMPAT[rel] > ... > > What do you think about this code? It does something completely different. The point of __dstr is not to make the self.relation member something modern, but to make client code that does dep.relation == "<<" checks work. -- Julian Andres Klode - Debian Developer, Ubuntu Member See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/. Please do not top-post if possible. -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org