* [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 @ 2016-09-02 20:49 Mike Gilbert 2016-09-03 15:50 ` Zac Medico 2016-09-04 16:58 ` [gentoo-portage-dev] [PATCH v2] " Mike Gilbert 0 siblings, 2 replies; 12+ messages in thread From: Mike Gilbert @ 2016-09-02 20:49 UTC (permalink / raw To: gentoo-portage-dev Display-If-Installed already supported EAPI 5 atoms. Use fnmatch for wildcard support on Display-If-Profile. --- pym/portage/news.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pym/portage/news.py b/pym/portage/news.py index 177f9db..d6d2f07 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -271,7 +271,7 @@ class NewsItem(object): # will never match format_match = _formatRE.match(line) if (format_match is not None and - not fnmatch.fnmatch(format_match.group(1), '1.*')): + not fnmatch.fnmatch(format_match.group(1), '[12].*')): invalids.append((i + 1, line.rstrip('\n'))) break if not line.startswith('D'): @@ -325,7 +325,7 @@ class DisplayProfileRestriction(DisplayRestriction): self.profile = profile def checkRestriction(self, **kwargs): - if self.profile == kwargs['profile']: + if fnmatch.fnmatch(kwargs['profile'], self.profile): return True return False -- 2.9.3 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 2016-09-02 20:49 [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 Mike Gilbert @ 2016-09-03 15:50 ` Zac Medico 2016-09-03 18:27 ` Ulrich Mueller 2016-09-03 22:12 ` Mike Gilbert 2016-09-04 16:58 ` [gentoo-portage-dev] [PATCH v2] " Mike Gilbert 1 sibling, 2 replies; 12+ messages in thread From: Zac Medico @ 2016-09-03 15:50 UTC (permalink / raw To: gentoo-portage-dev On 09/02/2016 01:49 PM, Mike Gilbert wrote: > Display-If-Installed already supported EAPI 5 atoms. > Use fnmatch for wildcard support on Display-If-Profile. > --- > pym/portage/news.py | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/pym/portage/news.py b/pym/portage/news.py > index 177f9db..d6d2f07 100644 > --- a/pym/portage/news.py > +++ b/pym/portage/news.py > @@ -271,7 +271,7 @@ class NewsItem(object): > # will never match > format_match = _formatRE.match(line) > if (format_match is not None and > - not fnmatch.fnmatch(format_match.group(1), '1.*')): > + not fnmatch.fnmatch(format_match.group(1), '[12].*')): > invalids.append((i + 1, line.rstrip('\n'))) > break > if not line.startswith('D'): > @@ -325,7 +325,7 @@ class DisplayProfileRestriction(DisplayRestriction): > self.profile = profile > > def checkRestriction(self, **kwargs): > - if self.profile == kwargs['profile']: > + if fnmatch.fnmatch(kwargs['profile'], self.profile): > return True > return False > > Looks good. If we wanted to be more strict about the input that we accept, we could limit the profile wildcard match to so that it only works if the format is 2.* and only supports a terminal /* since that's all that the spec says is supported. -- Thanks, Zac ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 2016-09-03 15:50 ` Zac Medico @ 2016-09-03 18:27 ` Ulrich Mueller 2016-09-03 22:12 ` Mike Gilbert 1 sibling, 0 replies; 12+ messages in thread From: Ulrich Mueller @ 2016-09-03 18:27 UTC (permalink / raw To: gentoo-portage-dev [-- Attachment #1: Type: text/plain, Size: 479 bytes --] >>>>> On Sat, 3 Sep 2016, Zac Medico wrote: > If we wanted to be more strict about the input that we accept, we > could limit the profile wildcard match to so that it only works if > the format is 2.* and only supports a terminal /* since that's all > that the spec says is supported. Please do. GLEP 42 says: "In news item format 2.0, a terminal asterisk immediately following a slash acts as a wildcard for any further path components, for example default/linux/*." Ulrich [-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 2016-09-03 15:50 ` Zac Medico 2016-09-03 18:27 ` Ulrich Mueller @ 2016-09-03 22:12 ` Mike Gilbert 1 sibling, 0 replies; 12+ messages in thread From: Mike Gilbert @ 2016-09-03 22:12 UTC (permalink / raw To: gentoo-portage-dev On Sat, Sep 3, 2016 at 11:50 AM, Zac Medico <zmedico@gentoo.org> wrote: > On 09/02/2016 01:49 PM, Mike Gilbert wrote: >> Display-If-Installed already supported EAPI 5 atoms. >> Use fnmatch for wildcard support on Display-If-Profile. >> --- >> pym/portage/news.py | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/pym/portage/news.py b/pym/portage/news.py >> index 177f9db..d6d2f07 100644 >> --- a/pym/portage/news.py >> +++ b/pym/portage/news.py >> @@ -271,7 +271,7 @@ class NewsItem(object): >> # will never match >> format_match = _formatRE.match(line) >> if (format_match is not None and >> - not fnmatch.fnmatch(format_match.group(1), '1.*')): >> + not fnmatch.fnmatch(format_match.group(1), '[12].*')): >> invalids.append((i + 1, line.rstrip('\n'))) >> break >> if not line.startswith('D'): >> @@ -325,7 +325,7 @@ class DisplayProfileRestriction(DisplayRestriction): >> self.profile = profile >> >> def checkRestriction(self, **kwargs): >> - if self.profile == kwargs['profile']: >> + if fnmatch.fnmatch(kwargs['profile'], self.profile): >> return True >> return False >> >> > > Looks good. > > If we wanted to be more strict about the input that we accept, we could > limit the profile wildcard match to so that it only works if the format > is 2.* and only supports a terminal /* since that's all that the spec > says is supported. I don't know how to implement such a thing off the top if my head. Feel free to replace my code with something more strict. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-portage-dev] [PATCH v2] news: Support News-Item-Format 2.0 2016-09-02 20:49 [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 Mike Gilbert 2016-09-03 15:50 ` Zac Medico @ 2016-09-04 16:58 ` Mike Gilbert 2016-09-04 17:04 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert 1 sibling, 1 reply; 12+ messages in thread From: Mike Gilbert @ 2016-09-04 16:58 UTC (permalink / raw To: gentoo-portage-dev Validate Display-If-Installed with EAPI 0 or 5. Add support for trailing wildcard matching. 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..d530c34 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 + # 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])) + 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') + if fnmatch.fnmatch(self.format, '2.*'): + return isvalidatom(self.atom, eapi='5') return isvalidatom(self.atom) def checkRestriction(self, **kwargs): -- 2.10.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [gentoo-portage-dev] [PATCH v3] news: Support News-Item-Format 2.0 2016-09-04 16:58 ` [gentoo-portage-dev] [PATCH v2] " Mike Gilbert @ 2016-09-04 17:04 ` Mike Gilbert 2016-09-07 7:26 ` Zac Medico 0 siblings, 1 reply; 12+ messages in thread From: Mike Gilbert @ 2016-09-04 17:04 UTC (permalink / raw To: gentoo-portage-dev 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 + # 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])) + 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') + if fnmatch.fnmatch(self.format, '2.*'): + return isvalidatom(self.atom, eapi='5') return isvalidatom(self.atom) def checkRestriction(self, **kwargs): -- 2.10.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v3] news: Support News-Item-Format 2.0 2016-09-04 17:04 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert @ 2016-09-07 7:26 ` Zac Medico 2016-09-07 21:03 ` [gentoo-portage-dev] [PATCH v4] " Mike Gilbert 2016-09-07 21:06 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert 0 siblings, 2 replies; 12+ messages in thread From: Zac Medico @ 2016-09-07 7:26 UTC (permalink / raw To: gentoo-portage-dev 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 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-portage-dev] [PATCH v4] news: Support News-Item-Format 2.0 2016-09-07 7:26 ` Zac Medico @ 2016-09-07 21:03 ` Mike Gilbert 2016-09-08 0:31 ` Zac Medico 2016-09-07 21:06 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert 1 sibling, 1 reply; 12+ messages in thread From: Mike Gilbert @ 2016-09-07 21:03 UTC (permalink / raw To: gentoo-portage-dev 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..e53e905 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") +_bad_wc_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 _bad_wc_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): -- 2.10.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v4] news: Support News-Item-Format 2.0 2016-09-07 21:03 ` [gentoo-portage-dev] [PATCH v4] " Mike Gilbert @ 2016-09-08 0:31 ` Zac Medico 2016-09-08 5:31 ` [gentoo-portage-dev] [PATCH v5] " Mike Gilbert 0 siblings, 1 reply; 12+ messages in thread From: Zac Medico @ 2016-09-08 0:31 UTC (permalink / raw To: gentoo-portage-dev On 09/07/2016 02:03 PM, 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 | 50 ++++++++++++++++++++++++++++++++++++++------------ > 1 file changed, 38 insertions(+), 12 deletions(-) > > diff --git a/pym/portage/news.py b/pym/portage/news.py > index 177f9db..e53e905 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") > +_bad_wc_RE = re.compile(r'.*([^/]\*|\*.)') Maybe it's better if we use a regex that defines a valid profile string: _valid_profile_RE = re.compile(r'^[^*]+(/\*)?$') -- Thanks, Zac ^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-portage-dev] [PATCH v5] news: Support News-Item-Format 2.0 2016-09-08 0:31 ` Zac Medico @ 2016-09-08 5:31 ` Mike Gilbert 2016-09-10 22:05 ` Zac Medico 0 siblings, 1 reply; 12+ messages in thread From: Mike Gilbert @ 2016-09-08 5:31 UTC (permalink / raw To: gentoo-portage-dev 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): -- 2.10.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v5] news: Support News-Item-Format 2.0 2016-09-08 5:31 ` [gentoo-portage-dev] [PATCH v5] " Mike Gilbert @ 2016-09-10 22:05 ` Zac Medico 0 siblings, 0 replies; 12+ messages in thread From: Zac Medico @ 2016-09-10 22:05 UTC (permalink / raw To: gentoo-portage-dev On 09/07/2016 10:31 PM, 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 | 50 ++++++++++++++++++++++++++++++++++++++------------ > 1 file changed, 38 insertions(+), 12 deletions(-) LGTM, thanks for addressing all of my concerns. -- Thanks, Zac ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v3] news: Support News-Item-Format 2.0 2016-09-07 7:26 ` Zac Medico 2016-09-07 21:03 ` [gentoo-portage-dev] [PATCH v4] " Mike Gilbert @ 2016-09-07 21:06 ` Mike Gilbert 1 sibling, 0 replies; 12+ messages in thread From: Mike Gilbert @ 2016-09-07 21:06 UTC (permalink / raw To: gentoo-portage-dev On Wed, Sep 7, 2016 at 3:26 AM, Zac Medico <zmedico@gentoo.org> wrote: > On 09/04/2016 10:04 AM, Mike Gilbert wrote: >> 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. > Good idea. I cleared out /var/lib/gentoo/news, and did not hit any errors when emerge re-evaluated them. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2016-09-10 22:05 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-09-02 20:49 [gentoo-portage-dev] [PATCH] news: Support News-Item-Format 2.0 Mike Gilbert 2016-09-03 15:50 ` Zac Medico 2016-09-03 18:27 ` Ulrich Mueller 2016-09-03 22:12 ` Mike Gilbert 2016-09-04 16:58 ` [gentoo-portage-dev] [PATCH v2] " Mike Gilbert 2016-09-04 17:04 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert 2016-09-07 7:26 ` Zac Medico 2016-09-07 21:03 ` [gentoo-portage-dev] [PATCH v4] " Mike Gilbert 2016-09-08 0:31 ` Zac Medico 2016-09-08 5:31 ` [gentoo-portage-dev] [PATCH v5] " Mike Gilbert 2016-09-10 22:05 ` Zac Medico 2016-09-07 21:06 ` [gentoo-portage-dev] [PATCH v3] " Mike Gilbert
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox