summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-01-23 17:09:23 +0100
committerMichal Minar <miminar@redhat.com>2013-01-23 17:09:23 +0100
commita245eb3990843d24a30180c836602c265c71a709 (patch)
tree5054cd5f24677ffea8d26242a59ae18a010930aa /tools
parentaad492d79c9451dc24391d0b7bef6898046cf854 (diff)
downloadopenlmi-providers-a245eb3990843d24a30180c836602c265c71a709.tar.gz
openlmi-providers-a245eb3990843d24a30180c836602c265c71a709.tar.xz
openlmi-providers-a245eb3990843d24a30180c836602c265c71a709.zip
pyling plugins improvements
added allow_cmpi_logging module for suppressing errors concerning logging statements disabled our custom C9904 warning message because of providers like CapabilitiesProvider having no prefix - but still checking for consistency in module name and class name
Diffstat (limited to 'tools')
-rw-r--r--tools/pylint/plugins/allow_cmpi_logging.py90
-rw-r--r--tools/pylint/plugins/cim_provider_checker.py16
-rw-r--r--tools/pylint/pylintrc2
3 files changed, 95 insertions, 13 deletions
diff --git a/tools/pylint/plugins/allow_cmpi_logging.py b/tools/pylint/plugins/allow_cmpi_logging.py
new file mode 100644
index 0000000..4597301
--- /dev/null
+++ b/tools/pylint/plugins/allow_cmpi_logging.py
@@ -0,0 +1,90 @@
+# -*- encoding: utf-8 -*-
+# Software Management Providers
+#
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Michal Minar <miminar@redhat.com>
+"""
+Pylint plugin supressing error concerning the use of cmpi_logging
+facilities.
+"""
+from logilab.astng import scoped_nodes
+from logilab.astng import MANAGER
+from logilab.astng.builder import ASTNGBuilder
+from pylint.interfaces import IASTNGChecker
+from pylint.checkers import BaseChecker
+
+def logging_transform(module):
+ """
+ Make the logging.RootLogger look, like it has following methods:
+ * trace_warn
+ * trace_info
+ * trace_verbose
+ These are actually defined in its subclass CMPILogger.
+ But pylint thinks, that RootLogger is used all the time.
+ """
+ if module.name != 'logging' or 'RootLogger' not in module:
+ return
+ fake = ASTNGBuilder(MANAGER).string_build('''
+
+def trace_warn(self, msg, *args, **kwargs):
+ print(self, msg, args, kwargs)
+
+def trace_info(self, msg, *args, **kwargs):
+ print(self, msg, args, kwargs)
+
+def trace_verbose(self, msg, *args, **kwargs):
+ print(self, msg, args, kwargs)
+
+''')
+ for level in ('warn', 'info', 'verbose'):
+ method_name = 'trace_' + level
+ for child in module.locals['RootLogger']:
+ if not isinstance(child, scoped_nodes.Class):
+ continue
+ child.locals[method_name] = fake.locals[method_name]
+
+class CMPILoggingChecker(BaseChecker):
+ """
+ Checker that only disables some error messages of our custom
+ cmpi_logging facilities.
+ """
+
+ __implements__ = IASTNGChecker
+
+ name = 'cmpi_logging'
+ # When we do have some real warning messages/reports,
+ # remote W9921. We need it just to get registered.
+ msgs = { 'W9921': ('Dummy', "This is a dummy message.")}
+
+ def visit_class(self, node):
+ """
+ This supresses some warnings for CMPILogger class.
+ """
+ if ( isinstance(node.parent, scoped_nodes.Module)
+ and node.parent.name.split('.')[-1] == "cmpi_logging"
+ and node.name == "CMPILogger"):
+ # supress warning about too many methods defined
+ self.linter.disable('R0904', scope='module', line=node.lineno)
+
+def register(linter):
+ """
+ Called when loaded by pylint --load-plugins.
+ Let's register our tranformation function and checker here.
+ """
+ MANAGER.register_transformer(logging_transform)
+ linter.register_checker(CMPILoggingChecker(linter))
diff --git a/tools/pylint/plugins/cim_provider_checker.py b/tools/pylint/plugins/cim_provider_checker.py
index 8691b5a..a1b557b 100644
--- a/tools/pylint/plugins/cim_provider_checker.py
+++ b/tools/pylint/plugins/cim_provider_checker.py
@@ -78,10 +78,6 @@ class CIMProviderChecker(BaseChecker):
name = 'cim_provider'
msgs = {
- 'C9904': ('Invalid provider class name %s',
- "Class name representing cim provider should be in inform "
- "<prefix>_<name>. Where <prefix> and <name> should be both "
- "written in CamelCase."),
'C9905': ('Invalid provider module name %s',
"Module containing cim provider(s) should be named as "
"<prefix>_<name>. Where both <prefix> and <name> are "
@@ -114,21 +110,17 @@ class CIMProviderChecker(BaseChecker):
"""
if "CIMProvider2" in [a.name for a in node.ancestors()]:
supress_cim_provider_messages(self.linter, node)
- clsm = _RE_PROVIDER_CLASS_NAME.match(node.name)
- if not clsm:
- self.add_message('C9904', node=node, args=node.name)
parent = node.parent
while not isinstance(parent, scoped_nodes.Module):
parent = parent.parent
+ clsm = _RE_PROVIDER_CLASS_NAME.match(node.name)
modm = _RE_PROVIDER_MODULE_NAME.match(parent.name)
- if not modm:
+ if clsm and not modm:
self.add_message('C9905', node=node, args=parent.name)
- if not clsm:
- return
- if clsm.group('prefix') != modm.group('prefix'):
+ if clsm and clsm.group('prefix') != modm.group('prefix'):
self.add_message('C9906', node=node,
args=(modm.group('prefix'), clsm.group('prefix')))
- if clsm.group('prefix') != 'LMI':
+ if clsm and clsm.group('prefix') != 'LMI':
self.add_message('C9910', node=node, args=clsm.group('prefix'))
if not 'get_providers' in parent.keys():
self.add_message('E9907', node=parent, args=parent.name)
diff --git a/tools/pylint/pylintrc b/tools/pylint/pylintrc
index f065e65..45a25ea 100644
--- a/tools/pylint/pylintrc
+++ b/tools/pylint/pylintrc
@@ -19,7 +19,7 @@ persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
-load-plugins=unittest_checker,cim_provider_checker
+load-plugins=unittest_checker,cim_provider_checker,allow_cmpi_logging
[MESSAGES CONTROL]