3 # Copyright 2003-2010 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License v2
6 from __future__ import print_function
12 import gentoolkit.pprinter as pp
15 from portage import os
18 class PkgIndex(object):
19 """Handle the cleaning of the binpkg Package
23 @param output: optional output class for printing
26 def __init__(self, controller=None):
27 self.controller = controller
30 def _get_emaint_binhost(self):
31 """Obtain a reference to the binhost module class
33 @sets: self.binhost to BinhostHandler class
37 self.emaint_control = Modules()
38 self.binhost = self.emaint_control._get_class('binhost')
39 except InvalidModuleName as er:
40 print( pp.error("Error importing emaint binhost module"), file=sys.stderr)
41 print( pp.error("Original error: " + er), file=sys.stderr)
47 def _load_modules(self):
48 """Import the emaint modules and report the success/fail of them
51 from emaint.module import Modules
52 from emaint.main import TaskHandler
53 except ImportError as e:
58 def clean_pkgs_index(self,):
59 """This will clean the binpkgs packages index file"""
60 go = self._load_modules()
62 if self.get_emaint_binhost():
63 self.taskmaster = TaskHandler(show_progress_bar=True)
64 tasks = [self.binhost]
65 self.taskmaster.run_tasks(tasks)
68 def call_emaint(self):
69 """Run the stand alone emaint script from
73 @return: the difference in file size
75 file_ = os.path.join(portage.settings['PKGDIR'], 'Packages')
76 statinfo = os.stat(file_)
77 size1 = statinfo.st_size
78 command = "emaint --fix binhost"
80 retcode = subprocess.call(command, shell=True)
82 print( pp.error("Child was terminated by signal" + str(-retcode)), file=sys.stderr)
84 print( pp.error("Execution failed:" + e), file=sys.stderr)
86 statinfo = os.stat(file_)
87 clean_size = size1 - statinfo.st_size
88 self.controller(clean_size, "Packages Index", file_, "Index")