From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B8F541386F0 for ; Sat, 8 Aug 2015 17:51:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 83AE81412D; Sat, 8 Aug 2015 17:51:34 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 13A3A1412D for ; Sat, 8 Aug 2015 17:51:33 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B88D8340E47 for ; Sat, 8 Aug 2015 17:51:32 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 18AA3C2 for ; Sat, 8 Aug 2015 17:51:27 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1439056477.6a34bce8dbd3dd31caa62e2e44d7ae58dd609457.blueness@gentoo> Subject: [gentoo-commits] proj/grss:master commit in: grs/ X-VCS-Repository: proj/grss X-VCS-Files: grs/WorldConf.py X-VCS-Directories: grs/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 6a34bce8dbd3dd31caa62e2e44d7ae58dd609457 X-VCS-Branch: master Date: Sat, 8 Aug 2015 17:51:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 378c0849-95c7-4585-84eb-bfc4cb900c72 X-Archives-Hash: 889ea15b637d0e1a5326ab1d3078a146 commit: 6a34bce8dbd3dd31caa62e2e44d7ae58dd609457 Author: Anthony G. Basile gentoo org> AuthorDate: Sat Aug 8 17:54:37 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Aug 8 17:54:37 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=6a34bce8 grs/Worldconf.py: clear out managed directories before installing. grs/WorldConf.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/grs/WorldConf.py b/grs/WorldConf.py index b102e7d..63daace 100644 --- a/grs/WorldConf.py +++ b/grs/WorldConf.py @@ -9,15 +9,28 @@ import re from grs.Constants import CONST class WorldConf(): - """ doc here - more doc - """ + """ Manage files in /etc/portage based on /etc/grs/world.conf """ + + # TODO: This needs to be expanded. + manageddirs = ['env', 'package.env', 'package.accept_keywords', \ + 'package.use', 'package.mask', 'package.unmask']: @staticmethod def install(): - """ doc here - more doc + """ Restore /etc/portage to a prestine stage (removing all files + in manageddirs, and copy in all files specified in world.conf. """ + # This is harsh, but we need to start from a clean slate because + # world.conf can drop sections. If it does, then those files are + # orphaned and can inject flags/envvars which are problematic. + for directory in WorldConf.manageddirs: + dpath = os.path.join(CONST.PORTAGE_CONFIGDIR, directory) + for f in os.listdir(dpath): + fpath = os.path.join(dpath, f) + if os.path.isfile(fpath): + os.remove(fpath) + + # Now we can read world.conf and populate an empty /etc/portage. config = configparser.RawConfigParser(delimiters=':', allow_no_value=True, comment_prefixes=None) config.read(CONST.WORLD_CONFIG) for s in config.sections(): @@ -32,12 +45,14 @@ class WorldConf(): @staticmethod def clean(): - """ doc here - more doc + """ Remove any files from /etc/portage that are unnecessary, ie that + do not correspond to installed pkgs. """ + # We need to look at all portage provide pkgs and all installed pkgs. portdb = portage.db[portage.root]["porttree"].dbapi vardb = portage.db[portage.root]["vartree"].dbapi + # Remove all installed pkgs from the set of all portage packages. uninstalled = portdb.cp_all() for p in vardb.cp_all(): try: @@ -45,6 +60,7 @@ class WorldConf(): except ValueError: print('%s installed on local system, but not in portage repo anymore.' % p) + # Construct a list of canonical named files for uninstalled pkgs. slot_atoms = [] for p in uninstalled: cpv = portdb.cp_list(p)[0] @@ -56,12 +72,10 @@ class WorldConf(): slot = slotvar slot_atoms.append(re.sub('[/:]', '_', '%s:%s' % (p, slot))) + # Walk through all files in /etc/portage and remove any files for uninstalled pkgs. for dirpath, dirnames, filenames in os.walk(CONST.PORTAGE_CONFIGDIR): # Only look at select files and directories. - # TODO: This needs to be expanded. - if not os.path.basename(dirpath) in ['env', 'package.env', \ - 'package.accept_keywords', 'package.use', \ - 'package.mask', 'package.unmask']: + if not os.path.basename(dirpath) in WorldConf.manageddirs: continue for f in filenames: