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 BB0BB138330 for ; Wed, 7 Sep 2016 07:26:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8B734E0B26; Wed, 7 Sep 2016 07:26:22 +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 82D93E0B24 for ; Wed, 7 Sep 2016 07:26:21 +0000 (UTC) Received: from [10.128.12.197] (unknown [100.42.98.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id AEB60340861 for ; Wed, 7 Sep 2016 07:26:20 +0000 (UTC) Subject: Re: [gentoo-portage-dev] [PATCH v3] news: Support News-Item-Format 2.0 To: gentoo-portage-dev@lists.gentoo.org References: <20160904165829.17331-1-floppym@gentoo.org> <20160904170430.17543-1-floppym@gentoo.org> From: Zac Medico Message-ID: <52d220b8-b6b6-5c4e-6940-31deb1fc3ba0@gentoo.org> Date: Wed, 7 Sep 2016 00:26:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 In-Reply-To: <20160904170430.17543-1-floppym@gentoo.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Archives-Salt: f10ca917-3d77-44a0-9b22-c10a9bfefe54 X-Archives-Hash: 46131ca3898c3166698e2321663e0fa3 On 09/04/2016 10:04 AM, Mike Gilbert wrote: > 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 | 42 ++++++++++++++++++++++++++++++------------ > 1 file changed, 30 insertions(+), 12 deletions(-) > > diff --git a/pym/portage/news.py b/pym/portage/news.py > index 177f9db..fa6fb00 100644 > --- a/pym/portage/news.py > +++ b/pym/portage/news.py > @@ -266,14 +266,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 matchines on lines that s/matchines/matches/ > + # will never match > if not line.startswith('D'): > continue > restricts = { _installedRE : DisplayInstalledRestriction, > @@ -282,13 +292,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 +332,14 @@ 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 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])) Maybe we should raise an exception if a wildcard is used but the format doesn't allow it? We could also raise an exception for any unsupported wildcards that do not occur at the end of the string. > + return (kwargs['profile'] == self.profile) > > class DisplayKeywordRestriction(DisplayRestriction): > """ > @@ -335,8 +347,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 +362,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') We might want to check the existing news items to make sure that they are all conformant here. > + if fnmatch.fnmatch(self.format, '2.*'): > + return isvalidatom(self.atom, eapi='5') > return isvalidatom(self.atom) > > def checkRestriction(self, **kwargs): > -- Thanks, Zac