Commit caeffaa0 authored by Iustin Pop's avatar Iustin Pop
Browse files

Partial cherry-pick of 6c881c52 from the 2.1 branch



This cherry-picks the utils.FieldSet.Matches changes and the significant
jqueue.py change. These are stable in the 2.1 branch and therefore make
sense to backport to 2.0 (are basically cleanups).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent 2b32e20c
...@@ -509,33 +509,37 @@ class _JobQueueWorkerPool(workerpool.WorkerPool): ...@@ -509,33 +509,37 @@ class _JobQueueWorkerPool(workerpool.WorkerPool):
self.queue = queue self.queue = queue
class JobQueue(object): def _RequireOpenQueue(fn):
"""Queue used to manage the jobs. """Decorator for "public" functions.
@cvar _RE_JOB_FILE: regex matching the valid job file names This function should be used for all 'public' functions. That is,
functions usually called from other classes. Note that this should
be applied only to methods (not plain functions), since it expects
that the decorated function is called with a first argument that has
a '_queue_lock' argument.
""" @warning: Use this decorator only after utils.LockedMethod!
_RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
def _RequireOpenQueue(fn): Example::
"""Decorator for "public" functions. @utils.LockedMethod
@_RequireOpenQueue
def Example(self):
pass
This function should be used for all 'public' functions. That is, """
functions usually called from other classes. def wrapper(self, *args, **kwargs):
assert self._queue_lock is not None, "Queue should be open"
return fn(self, *args, **kwargs)
return wrapper
@warning: Use this decorator only after utils.LockedMethod!
Example:: class JobQueue(object):
@utils.LockedMethod """Queue used to manage the jobs.
@_RequireOpenQueue
def Example(self):
pass
""" @cvar _RE_JOB_FILE: regex matching the valid job file names
def wrapper(self, *args, **kwargs):
assert self._queue_lock is not None, "Queue should be open" """
return fn(self, *args, **kwargs) _RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
return wrapper
def __init__(self, context): def __init__(self, context):
"""Constructor for JobQueue. """Constructor for JobQueue.
......
...@@ -2125,12 +2125,12 @@ class FieldSet(object): ...@@ -2125,12 +2125,12 @@ class FieldSet(object):
@type field: str @type field: str
@param field: the string to match @param field: the string to match
@return: either False or a regular expression match object @return: either None or a regular expression match object
""" """
for m in itertools.ifilter(None, (val.match(field) for val in self.items)): for m in itertools.ifilter(None, (val.match(field) for val in self.items)):
return m return m
return False return None
def NonMatching(self, items): def NonMatching(self, items):
"""Returns the list of fields not matching the current set """Returns the list of fields not matching the current set
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment