diff --git a/pym/builder/builder.py b/pym/builder/builder.py index 6ebf1c6..a43b55a 100644 --- a/pym/builder/builder.py +++ b/pym/builder/builder.py @@ -808,6 +808,73 @@ class Builder(Update): return self._cleanpkg( distdir, pkgdir, distdirfiles, pkgfiles, logger) + def regenPackages(self, chrootPath, pkgDirPath): + """Regenerate packages and clean SYNC param""" + + def fixKeywords(s): + if s.startswith("KEYWORDS:"): + return "KEYWORDS: amd64 x86\n" + else: + return s + + pathPackages = pathJoin(chrootPath, pkgDirPath, "Packages") + # remove Packages if it recreated + if path.exists(pathPackages): + os.unlink(pathPackages) + self._update_binhost_packages() + if path.exists(pathPackages): + # remove SYNC param + filtredPackages = \ + map(fixKeywords, + filter(lambda x: not x.startswith("SYNC:"), + open(pathPackages, 'r'))) + open(pathPackages, 'w').writelines(filtredPackages) + + def binaryCleaning(self): + """Clean binary repository""" + # imported from calculate_assemble + chrootPath = self.clVars.Get('cl_builder_path') + pkgDir = pathJoin(chrootPath, + self.clVars.Get('cl_builder_pkgdir')) + dbPkg = pathJoin(chrootPath, 'var/db/pkg') + + try: + if not path.exists(dbPkg): + os.makedirs(dbPkg) + if not path.exists(pkgDir): + os.makedirs(pkgDir) + if path.exists(dbPkg) and path.exists(pkgDir): + # get pkg list from distro + pkgList = \ + reduce(lambda x,y:x+y, + map(lambda x:map(lambda z:path.join(x,"%s.tbz2"%z), + os.listdir(path.join(dbPkg,x))), + os.listdir(dbPkg)),[]) + # get binary packages + binList = \ + reduce(lambda x,y:x+y, + map(lambda x:map(lambda z:path.join(x,z)[len(pkgDir)+1:], + os.listdir(path.join(x))), + filter(lambda x:path.isdir(x), + map(lambda x:path.join(pkgDir,x), + os.listdir(pkgDir)))),[]) + + # remove files which in binary and not in db/pkg + map(lambda x:os.unlink(x), + map(lambda x:pathJoin(pkgDir,x), + list(set(binList)-set(pkgList)))) + + # remove empty directories + map(lambda x:os.rmdir(x), + filter(lambda x:path.isdir(x) and not os.listdir(x), + map(lambda x:path.join(pkgDir,x), + os.listdir(pkgDir)))) + + self.regenPackages(chrootPath,pkgDir[len(chrootPath):]) + except OSError as e: + raise BuilderError(str(e)) + return True + def raiseOutdate(self): """ Установить флаг данные о репозиториях устарели (необходим для выполнения diff --git a/pym/builder/utils/cl_builder_update.py b/pym/builder/utils/cl_builder_update.py index 3cae5c1..49cf177 100644 --- a/pym/builder/utils/cl_builder_update.py +++ b/pym/builder/utils/cl_builder_update.py @@ -290,6 +290,11 @@ class ClBuilderUpdateAction(Action): 'method': 'Builder.dispatchConf()', 'condition': lambda Get: Get('cl_dispatch_conf') != 'skip' }, + {'name': 'update_world:binary_cleaning', + 'message': __("Cleaning the binary repository"), + 'method': 'Builder.binaryCleaning()', + 'condition': lambda Get: Get('cl_builder_binary_set') == "off" + }, ], 'depend': Tasks.has("update_other") },