Commit 6c881c52 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix pylint 'E' (error) codes



This patch adds some silences and tweaks the code slightly so that
“pylint --rcfile pylintrc -e ganeti” doesn't give any errors.

The biggest change is in jqueue.py, the move of _RequireOpenQueue out of
the JobQueue class. Since that is actually a function and not a method
(never used as such) this makes sense, and also silences two pylint
errors.

Another real code change is in utils.py, where FieldSet.Matches will
return None instead of False for failure; this still works with the way
this class/method is used, and makes more sense (it resembles more
closely the re.match return values).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent bfe61b0b
......@@ -26,6 +26,12 @@
"""
# pylint: disable-msg=E1103
# E1103: %s %r has no %r member (but some types could not be
# inferred), because the _TryOSFromDisk returns either (True, os_obj)
# or (False, "string") which confuses pylint
import os
import os.path
......
......@@ -45,6 +45,11 @@ confirming what you already got.
"""
# pylint: disable-msg=E0203
# E0203: Access to member %r before its definition, since we use
# objects.py which doesn't explicitely initialise its members
import socket
import time
import random
......@@ -400,4 +405,3 @@ class ConfdFilterCallback:
if not filter_upcall:
self._callback(up)
......@@ -22,6 +22,13 @@
"""
# pylint: disable-msg=E1103
# # E1103: %s %r has no %r member (but some types could not be
# inferred), since _socketobject could be ssl or not and pylint
# doesn't parse that
import os
import select
import socket
......
......@@ -540,33 +540,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.
......
......@@ -26,6 +26,11 @@ pass to and from external parties.
"""
# pylint: disable-msg=E0203
# E0203: Access to member %r before its definition, since we use
# objects.py which doesn't explicitely initialise its members
import ConfigParser
import re
......
......@@ -328,6 +328,7 @@ class LvmPvStorage(_LvmBase):
"""LVM Physical Volume storage unit.
"""
@staticmethod
def _GetAllocatable(attr):
if attr:
return (attr[0] == "a")
......
......@@ -2413,12 +2413,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