From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH v3] news: Support News-Item-Format 2.0
Date: Wed, 7 Sep 2016 00:26:18 -0700 [thread overview]
Message-ID: <52d220b8-b6b6-5c4e-6940-31deb1fc3ba0@gentoo.org> (raw)
In-Reply-To: <20160904170430.17543-1-floppym@gentoo.org>
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
next prev parent reply other threads:[~2016-09-07 7:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52d220b8-b6b6-5c4e-6940-31deb1fc3ba0@gentoo.org \
--to=zmedico@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox