Re: [gentoo-portage-dev] [PATCH gentoolkit 1/2] eclean: Rewrite findPackages()

2020-03-01 Thread Zac Medico
On 2/20/20 9:36 PM, Michael 'veremitz' Everitt wrote:
> On 21/02/20 05:29, Matt Turner wrote:
>> I found the original code to be nearly incomprehensible. Instead of
>> populating a dict of potential binpkgs to remove and then removing from
>> the to-be-removed list, just selectively add to-be-removed packages.
>>
>> Signed-off-by: Matt Turner 
>> ---
>> I switched from tabs to spaces in the process. I can revert back if
>> desired.
>>
> Probably best to stick to tabs for consistency with the other portage code,
> although naturally Zac probably better to ACK/NACK that.

Yeah lets stick with tabs unless we're converting everything to spaces.

> Otherwise I think this is a good refresh. +1.

Yes, looks good.
-- 
Thanks,
Zac



Re: [gentoo-portage-dev] [PATCH gentoolkit 1/2] eclean: Rewrite findPackages()

2020-02-20 Thread Michael 'veremitz' Everitt
On 21/02/20 05:29, Matt Turner wrote:
> I found the original code to be nearly incomprehensible. Instead of
> populating a dict of potential binpkgs to remove and then removing from
> the to-be-removed list, just selectively add to-be-removed packages.
>
> Signed-off-by: Matt Turner 
> ---
> I switched from tabs to spaces in the process. I can revert back if
> desired.
>
Probably best to stick to tabs for consistency with the other portage code,
although naturally Zac probably better to ACK/NACK that.

Otherwise I think this is a good refresh. +1.



signature.asc
Description: OpenPGP digital signature


[gentoo-portage-dev] [PATCH gentoolkit 1/2] eclean: Rewrite findPackages()

2020-02-20 Thread Matt Turner
I found the original code to be nearly incomprehensible. Instead of
populating a dict of potential binpkgs to remove and then removing from
the to-be-removed list, just selectively add to-be-removed packages.

Signed-off-by: Matt Turner 
---
I switched from tabs to spaces in the process. I can revert back if
desired.

 pym/gentoolkit/eclean/search.py | 189 
 1 file changed, 94 insertions(+), 95 deletions(-)

diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py
index 58bd97e..831ba39 100644
--- a/pym/gentoolkit/eclean/search.py
+++ b/pym/gentoolkit/eclean/search.py
@@ -489,98 +489,97 @@ class DistfilesSearch(object):
 
 
 def findPackages(
-   options,
-   exclude=None,
-   destructive=False,
-   time_limit=0,
-   package_names=False,
-   pkgdir=None,
-   port_dbapi=portage.db[portage.root]["porttree"].dbapi,
-   var_dbapi=portage.db[portage.root]["vartree"].dbapi
-   ):
-   """Find all obsolete binary packages.
-
-   XXX: packages are found only by symlinks.
-   Maybe i should also return .tbz2 files from All/ that have
-   no corresponding symlinks.
-
-   @param options: dict of options determined at runtime
-   @param exclude: an exclusion dict as defined in
-   exclude.parseExcludeFile class.
-   @param destructive: boolean, defaults to False
-   @param time_limit: integer time value as returned by parseTime()
-   @param package_names: boolean, defaults to False.
-   used only if destructive=True
-   @param pkgdir: path to the binary package dir being checked
-   @param port_dbapi: defaults to 
portage.db[portage.root]["porttree"].dbapi
-   can be overridden for tests.
-   @param var_dbapi: defaults to portage.db[portage.root]["vartree"].dbapi
-   can be overridden for tests.
-
-   @rtype: dict
-   @return clean_me i.e. {'cat/pkg-ver.tbz2': [filepath],}
-   """
-   if exclude is None:
-   exclude = {}
-   clean_me = {}
-   # create a full package dictionary
-
-   # now do an access test, os.walk does not error for "no read permission"
-   try:
-   test = os.listdir(pkgdir)
-   del test
-   except EnvironmentError as er:
-   if options['ignore-failure']:
-   exit(0)
-   print( pp.error("Error accessing PKGDIR." ), file=sys.stderr)
-   print( pp.error("(Check your make.conf file and 
environment)."), file=sys.stderr)
-   print( pp.error("Error: %s" %str(er)), file=sys.stderr)
-   exit(1)
-
-   # if portage supports FEATURES=binpkg-multi-instance, then
-   # cpv_all can return multiple instances per cpv, where
-   # instances are distinguishable by some extra attributes
-   # provided by portage's _pkg_str class
-   bin_dbapi = portage.binarytree(pkgdir=pkgdir, 
settings=var_dbapi.settings).dbapi
-   for cpv in bin_dbapi.cpv_all():
-   mtime = int(bin_dbapi.aux_get(cpv, ['_mtime_'])[0])
-   if time_limit and mtime >= time_limit:
-   # time-limit exclusion
-   continue
-   # dict is cpv->[pkgs] (supports binpkg-multi-instance)
-   clean_me.setdefault(cpv, []).append(cpv)
-
-   # keep only obsolete ones
-   if destructive and package_names:
-   cp_all = dict.fromkeys(var_dbapi.cp_all())
-   else:
-   cp_all = {}
-   for cpv in list(clean_me):
-   if exclDictMatchCP(exclude,portage.cpv_getkey(cpv)):
-   # exclusion because of the exclude file
-   del clean_me[cpv]
-   continue
-   if not destructive and port_dbapi.cpv_exists(cpv):
-   # exclusion because pkg still exists (in porttree)
-   del clean_me[cpv]
-   continue
-   if destructive and var_dbapi.cpv_exists(cpv):
-   buildtime = var_dbapi.aux_get(cpv, ['BUILD_TIME'])[0]
-   clean_me[cpv] = [pkg for pkg in clean_me[cpv]
-   # only keep path if BUILD_TIME is identical 
with vartree
-   if bin_dbapi.aux_get(pkg, ['BUILD_TIME'])[0] != 
buildtime]
-   if not clean_me[cpv]:
-   # nothing we can clean for this package
-   del clean_me[cpv]
-   continue
-   if portage.cpv_getkey(cpv) in cp_all and 
port_dbapi.cpv_exists(cpv):
-   # exclusion because of --package-names
-   del clean_me[cpv]
-
-   # the getname method correctly supports