[PATCH 06/10] parser: Use full regexps for delegation rules paths
Finucane, Stephen
stephen.finucane at intel.com
Fri Dec 25 01:06:58 AEDT 2015
On 28 Nov 10:14, Mauro Carvalho Chehab wrote:
> From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>
> Paths are validated by trying to compile it as a regexp using a custom
> validator.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab at osg.samsung.com>
Some small nits that I can fix myself. Other than that,
Acked-by: Stephen Finucane <stephen.finucane at intel.com>
> ---
> patchwork/bin/parsemail.py | 19 +++++++++++++++++--
> patchwork/models.py | 9 ++++++++-
> 2 files changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
> index 4f22c7f2d6a0..5d6ddf45d264 100755
> --- a/patchwork/bin/parsemail.py
> +++ b/patchwork/bin/parsemail.py
> @@ -339,18 +339,33 @@ def get_state(state_name):
> pass
> return get_default_initial_patch_state()
>
> +class Rule(object):
> + pass
> +
nit: a defaultdict ({user: [path, path...]}) would be more semantic
here. I can change this, unless you've any reason I shouldn't.
> def auto_delegate(project, filenames):
> if not filenames:
> return None
>
> - rules = list(DelegationRule.objects.filter(project = project))
> + # Precompile the path regexps
> + rules = []
> + for rule in DelegationRule.objects.filter(project = project):
> + r = Rule()
> + r.user = rule.user
> +
> + try:
> + r.path = re.compile(rule.path)
> + except:
I'm going to make this capture 're.error' only, if that's OK.
> + print '%s is not a valid regular expression' % rule.path
> + continue
> +
> + rules.append(r)
>
> patch_delegate = None
>
> for filename in filenames:
> file_delegate = None
> for rule in rules:
> - if fnmatch(filename, rule.path):
> + if rule.path.match(filename):
> file_delegate = rule.user
> break;
>
> diff --git a/patchwork/models.py b/patchwork/models.py
> index 101a9af9746f..e552217a3cbc 100644
> --- a/patchwork/models.py
> +++ b/patchwork/models.py
> @@ -19,6 +19,7 @@
>
> from django.db import models
> from django.contrib.auth.models import User
> +from django.core.exceptions import ValidationError
> from django.core.urlresolvers import reverse
> from django.contrib.sites.models import Site
> from django.conf import settings
> @@ -78,9 +79,15 @@ class Project(models.Model):
> ordering = ['linkname']
>
>
> +def validate_rule_path(value):
> + try:
> + re.compile(value)
> + except:
> + raise ValidationError(u'`%s\' is not a valid regulator expression' % value)
> +
> class DelegationRule(models.Model):
> user = models.ForeignKey(User)
> - path = models.CharField(max_length=255)
> + path = models.CharField(max_length = 255, validators = [validate_rule_path])
> project = models.ForeignKey(Project)
> priority = models.IntegerField(default = 0)
>
> --
> 2.5.0
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list