summaryrefslogtreecommitdiff
path: root/pym
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2022-07-09 14:41:39 -0700
committerBrian Dolbec <dolsen@gentoo.org>2022-07-09 14:45:04 -0700
commit680dd160e1e5a41f008bd1a47afa2da2eb25714f (patch)
tree277e2b241db2958ea145109f1c93e5a81da2c18b /pym
parent04e8fd5252c9bc1efad66fdb8cb40d376550d580 (diff)
downloadgentoolkit-680dd160e1e5a41f008bd1a47afa2da2eb25714f.tar.gz
eclean: Complete migration to imported emaint code
eclean-pkg now uses imported emaint binhost code to run, Properly handle --quiet option for progressbar suppression from emaint. Keeps the standalone emaint binhost subprocess call as backup. Closes: https://bugs.gentoo.org/688550 Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
Diffstat (limited to 'pym')
-rw-r--r--pym/gentoolkit/eclean/clean.py5
-rw-r--r--pym/gentoolkit/eclean/cli.py2
-rw-r--r--pym/gentoolkit/eclean/pkgindex.py56
3 files changed, 30 insertions, 33 deletions
diff --git a/pym/gentoolkit/eclean/clean.py b/pym/gentoolkit/eclean/clean.py
index a6358a4..37a042a 100644
--- a/pym/gentoolkit/eclean/clean.py
+++ b/pym/gentoolkit/eclean/clean.py
@@ -19,8 +19,9 @@ class CleanUp:
or bypassing/ignoring
"""
- def __init__(self, controller):
+ def __init__(self, controller, quiet):
self.controller = controller
+ self.quiet = quiet
def clean_dist(self, clean_dict):
"""Calculate size of each entry for display, prompt user if needed,
@@ -64,7 +65,7 @@ class CleanUp:
# emaint is not yet importable so call it
# print a blank line here for separation
print()
- clean_size += index_control.call_emaint()
+ clean_size += index_control.clean_pkgs_index(self.quiet)
# return total size of deleted or to delete files
return clean_size
diff --git a/pym/gentoolkit/eclean/cli.py b/pym/gentoolkit/eclean/cli.py
index e3bc21a..23c7f3b 100644
--- a/pym/gentoolkit/eclean/cli.py
+++ b/pym/gentoolkit/eclean/cli.py
@@ -555,7 +555,7 @@ def doAction(action, options, exclude={}, output=None):
)
# initialize our cleaner
- cleaner = CleanUp(output.progress_controller)
+ cleaner = CleanUp(output.progress_controller, options["quiet"])
# actually clean files if something was found
if clean_me:
diff --git a/pym/gentoolkit/eclean/pkgindex.py b/pym/gentoolkit/eclean/pkgindex.py
index 617b437..d0878a1 100644
--- a/pym/gentoolkit/eclean/pkgindex.py
+++ b/pym/gentoolkit/eclean/pkgindex.py
@@ -11,6 +11,11 @@ import gentoolkit.pprinter as pp
from gentoolkit.eprefix import EPREFIX
import portage
+from portage.module import (
+ InvalidModuleName,
+ Modules,
+)
+from portage.emaint.main import TaskHandler
class PkgIndex:
@@ -32,37 +37,36 @@ class PkgIndex:
@sets: self.binhost to BinhostHandler class
@rtype: boolean
"""
- # About noqa below: I don't understand how this code can run at all.
- # TODO: verify soundness
try:
- self.emaint_control = Modules() # noqa
+ self.emaint_control = Modules()
self.binhost = self.emaint_control._get_class("binhost")
- except InvalidModuleName as er: # noqa
+ except InvalidModuleName as er:
print(pp.error("Error importing emaint binhost module"), file=sys.stderr)
print(pp.error("Original error: " + er), file=sys.stderr)
except:
return False
return True
- def _load_modules(self):
- """Import the emaint modules and report the success/fail of them"""
- try:
- from emaint.module import Modules # noqa
- from emaint.main import TaskHandler # noqa
- except ImportError:
- return False
- return True
+ def clean_pkgs_index(self, quiet):
+ """This will clean the binpkgs packages index file
- def clean_pkgs_index(
- self,
- ):
- """This will clean the binpkgs packages index file"""
- go = self._load_modules()
- if go:
- if self.get_emaint_binhost():
- self.taskmaster = TaskHandler(show_progress_bar=True) # noqa
- tasks = [self.binhost]
- self.taskmaster.run_tasks(tasks)
+ @param quiet: boolean
+ @return: the difference in file size
+ """
+ file_ = os.path.join(portage.settings["PKGDIR"], "Packages")
+ statinfo = os.stat(file_)
+ size1 = statinfo.st_size
+ show_progress = not quiet
+ if self.get_emaint_binhost():
+ self.taskmaster = TaskHandler(show_progress_bar=show_progress)
+ tasks = [self.binhost]
+ self.taskmaster.run_tasks(tasks)
+ else:
+ self.call_emaint()
+ statinfo = os.stat(file_)
+ clean_size = size1 - statinfo.st_size
+ self.controller("\n", clean_size, "Packages Index", file_, "Index")
+ return clean_size
def call_emaint(self):
"""Run the stand alone emaint script from
@@ -71,9 +75,6 @@ class PkgIndex:
@rtype: integer
@return: the difference in file size
"""
- file_ = os.path.join(portage.settings["PKGDIR"], "Packages")
- statinfo = os.stat(file_)
- size1 = statinfo.st_size
try:
retcode = subprocess.call(self.emaint_cmd, shell=True)
if retcode < 0:
@@ -83,8 +84,3 @@ class PkgIndex:
)
except OSError as e:
print(pp.error("Execution failed:" + e), file=sys.stderr)
- print()
- statinfo = os.stat(file_)
- clean_size = size1 - statinfo.st_size
- self.controller(clean_size, "Packages Index", file_, "Index")
- return clean_size