From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 92250138330 for ; Thu, 15 Sep 2016 02:03:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6D6B3E0B26; Thu, 15 Sep 2016 02:03:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 81C99E0B26 for ; Thu, 15 Sep 2016 02:03:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AE5E3340A35 for ; Thu, 15 Sep 2016 02:03:07 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A728A2481 for ; Thu, 15 Sep 2016 02:03:05 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1473903822.67fcbccd1b60b599e4e5dcc97f2959164ba6a7eb.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/news.py X-VCS-Directories: pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 67fcbccd1b60b599e4e5dcc97f2959164ba6a7eb X-VCS-Branch: master Date: Thu, 15 Sep 2016 02:03:05 +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: aea059f8-3884-4f90-ba1a-305a53f96f84 X-Archives-Hash: a242d44ec5eaa2c49a6f78bacb154e86 commit: 67fcbccd1b60b599e4e5dcc97f2959164ba6a7eb Author: Mike Gilbert gentoo org> AuthorDate: Thu Sep 15 01:30:38 2016 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Sep 15 01:43:42 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=67fcbccd news: Support News-Item-Format 2.0 Validate Display-If-Installed with EAPI 0 or 5. Add support for trailing wildcard matching for Display-If-Profile. Bug: https://bugs.gentoo.org/577372 pym/portage/news.py | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/pym/portage/news.py b/pym/portage/news.py index 177f9db..28faf83 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -197,6 +197,7 @@ _formatRE = re.compile("News-Item-Format:\s*([^\s]*)\s*$") _installedRE = re.compile("Display-If-Installed:(.*)\n") _profileRE = re.compile("Display-If-Profile:(.*)\n") _keywordRE = re.compile("Display-If-Keyword:(.*)\n") +_valid_profile_RE = re.compile(r'^[^*]+(/\*)?$') class NewsItem(object): """ @@ -266,14 +267,24 @@ class NewsItem(object): f.close() self.restrictions = {} invalids = [] + news_format = None + + # Look for News-Item-Format for i, line in enumerate(lines): - # Optimization to ignore regex matchines on lines that - # will never match format_match = _formatRE.match(line) - if (format_match is not None and - not fnmatch.fnmatch(format_match.group(1), '1.*')): + if format_match is not None: + news_format = format_match.group(1) + if fnmatch.fnmatch(news_format, '[12].*'): + break invalids.append((i + 1, line.rstrip('\n'))) - break + + if news_format is None: + invalids.append((0, 'News-Item-Format unspecified')) + + # Parse the rest + for i, line in enumerate(lines): + # Optimization to ignore regex matches on lines that + # will never match if not line.startswith('D'): continue restricts = { _installedRE : DisplayInstalledRestriction, @@ -282,13 +293,14 @@ class NewsItem(object): for regex, restriction in restricts.items(): match = regex.match(line) if match: - restrict = restriction(match.groups()[0].strip()) + restrict = restriction(match.groups()[0].strip(), news_format) if not restrict.isValid(): invalids.append((i + 1, line.rstrip("\n"))) else: self.restrictions.setdefault( id(restriction), []).append(restrict) continue + if invalids: self._valid = False msg = [] @@ -321,13 +333,21 @@ class DisplayProfileRestriction(DisplayRestriction): if the user is running a specific profile. """ - def __init__(self, profile): + def __init__(self, profile, news_format): self.profile = profile + self.format = news_format + + def isValid(self): + if fnmatch.fnmatch(self.format, '1.*') and '*' in self.profile: + return False + if fnmatch.fnmatch(self.format, '2.*') and not _valid_profile_RE.match(self.profile): + return False + return True def checkRestriction(self, **kwargs): - if self.profile == kwargs['profile']: - return True - return False + if fnmatch.fnmatch(self.format, '2.*') and self.profile.endswith('/*'): + return (kwargs['profile'].startswith(self.profile[:-1])) + return (kwargs['profile'] == self.profile) class DisplayKeywordRestriction(DisplayRestriction): """ @@ -335,8 +355,9 @@ class DisplayKeywordRestriction(DisplayRestriction): if the user is running a specific keyword. """ - def __init__(self, keyword): + def __init__(self, keyword, news_format): self.keyword = keyword + self.format = news_format def checkRestriction(self, **kwargs): if kwargs['config'].get('ARCH', '') == self.keyword: @@ -349,10 +370,15 @@ class DisplayInstalledRestriction(DisplayRestriction): if the user has that item installed. """ - def __init__(self, atom): + def __init__(self, atom, news_format): self.atom = atom + self.format = news_format def isValid(self): + if fnmatch.fnmatch(self.format, '1.*'): + return isvalidatom(self.atom, eapi='0') + if fnmatch.fnmatch(self.format, '2.*'): + return isvalidatom(self.atom, eapi='5') return isvalidatom(self.atom) def checkRestriction(self, **kwargs):