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):
self.queue = queue
class JobQueue(object):
"""Queue used to manage the jobs.
def _RequireOpenQueue(fn):
"""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.
"""
_RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
@warning: Use this decorator only after utils.LockedMethod!
def _RequireOpenQueue(fn):
"""Decorator for "public" functions.
Example::
@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::
@utils.LockedMethod
@_RequireOpenQueue
def Example(self):
pass
class JobQueue(object):
"""Queue used to manage the jobs.
"""
def wrapper(self, *args, **kwargs):
assert self._queue_lock is not None, "Queue should be open"
return fn(self, *args, **kwargs)
return wrapper
@cvar _RE_JOB_FILE: regex matching the valid job file names
"""
_RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
def __init__(self, context):
"""Constructor for JobQueue.
......
......@@ -2125,12 +2125,12 @@ class FieldSet(object):
@type field: str
@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)):
return m
return False
return None
def NonMatching(self, items):
"""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