From 6491d368d40f3de7d6c49b69b782497151d050a5 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 17 Feb 2015 08:55:23 -0600 Subject: Pylint fixes for pylint 0.28 This also pins Pylint to 0.28 or older so that we don't have to do this again. At some point we should look at upgrading to Pylint 1.x. --- src/lib/Bcfg2/Client/Tools/MacPorts.py | 5 +++-- src/lib/Bcfg2/Client/Tools/POSIXUsers.py | 4 ++-- src/lib/Bcfg2/Client/Tools/Pkgng.py | 9 ++++---- src/lib/Bcfg2/Client/Tools/__init__.py | 10 ++++----- src/lib/Bcfg2/Client/__init__.py | 2 +- src/lib/Bcfg2/Server/FileMonitor/__init__.py | 7 +++++-- src/lib/Bcfg2/Server/Lint/GroupPatterns.py | 11 +++++----- src/lib/Bcfg2/Server/Lint/Validate.py | 25 ++++++++++------------- src/lib/Bcfg2/Server/Lint/ValidateJSON.py | 21 ++++++++----------- src/lib/Bcfg2/Server/Lint/__init__.py | 20 ++++++++++++++---- src/lib/Bcfg2/Server/Plugin/__init__.py | 3 --- src/lib/Bcfg2/Server/Plugins/Packages/__init__.py | 4 ++-- src/lib/Bcfg2/Server/Test.py | 5 ++++- 13 files changed, 67 insertions(+), 59 deletions(-) (limited to 'src/lib/Bcfg2') diff --git a/src/lib/Bcfg2/Client/Tools/MacPorts.py b/src/lib/Bcfg2/Client/Tools/MacPorts.py index 1e9847c42..3c824eaff 100644 --- a/src/lib/Bcfg2/Client/Tools/MacPorts.py +++ b/src/lib/Bcfg2/Client/Tools/MacPorts.py @@ -37,8 +37,9 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): return False if entry.attrib['name'] in self.installed: - if (self.installed[entry.attrib['name']] == entry.attrib['version'] - or entry.attrib['version'] == 'any'): + if (entry.attrib['version'] == 'any' or + self.installed[entry.attrib['name']] == + entry.attrib['version']): # FIXME: We should be able to check this once # http://trac.macports.org/ticket/15709 is implemented return True diff --git a/src/lib/Bcfg2/Client/Tools/POSIXUsers.py b/src/lib/Bcfg2/Client/Tools/POSIXUsers.py index 7200b0fc2..40598541e 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIXUsers.py +++ b/src/lib/Bcfg2/Client/Tools/POSIXUsers.py @@ -160,8 +160,8 @@ class POSIXUsers(Bcfg2.Client.Tools.Tool): """ Get a list of supplmentary groups that the user in the given entry is a member of """ return [g for g in self.existing['POSIXGroup'].values() - if entry.get("name") in g[3] - and self._in_managed_range('POSIXGroup', g[2])] + if entry.get("name") in g[3] and + self._in_managed_range('POSIXGroup', g[2])] def VerifyPOSIXUser(self, entry, _): """ Verify a POSIXUser entry """ diff --git a/src/lib/Bcfg2/Client/Tools/Pkgng.py b/src/lib/Bcfg2/Client/Tools/Pkgng.py index cd70d662d..8989e084d 100644 --- a/src/lib/Bcfg2/Client/Tools/Pkgng.py +++ b/src/lib/Bcfg2/Client/Tools/Pkgng.py @@ -41,8 +41,9 @@ class Pkgng(Bcfg2.Client.Tools.Tool): if (entry.tag == 'Path' and entry.get('name').startswith('/etc/pkg/'))] self.nonexistent = [entry.get('name') for struct in config - for entry in struct if entry.tag == 'Path' - and entry.get('type') == 'nonexistent'] + for entry in struct + if entry.tag == 'Path' and + entry.get('type') == 'nonexistent'] self.actions = {} self.pkg_cache = {} @@ -159,8 +160,8 @@ class Pkgng(Bcfg2.Client.Tools.Tool): else: # version matches if (not Bcfg2.Options.setup.quick and - entry.get('verify', 'true') == 'true' - and checksums): + entry.get('verify', 'true') == 'true' and + checksums): pkgsums = self.VerifyChecksums(entry, modlist) return pkgsums return True diff --git a/src/lib/Bcfg2/Client/Tools/__init__.py b/src/lib/Bcfg2/Client/Tools/__init__.py index 67cdd4d6d..aaadc1428 100644 --- a/src/lib/Bcfg2/Client/Tools/__init__.py +++ b/src/lib/Bcfg2/Client/Tools/__init__.py @@ -573,7 +573,7 @@ class SvcTool(Tool): return self.cmd.run(self.get_svc_command(service, 'stop')) def restart_service(self, service): - """ Restart a service. + """Restart a service. :param service: The service entry to modify :type service: lxml.etree._Element @@ -606,15 +606,15 @@ class SvcTool(Tool): return for entry in bundle: - if (not self.handlesEntry(entry) - or not self._install_allowed(entry)): + if (not self.handlesEntry(entry) or + not self._install_allowed(entry)): continue estatus = entry.get('status') restart = entry.get("restart", "true").lower() if (restart == "false" or estatus == 'ignore' or - (restart == "interactive" and - not Bcfg2.Options.setup.interactive)): + (restart == "interactive" and + not Bcfg2.Options.setup.interactive)): continue success = False diff --git a/src/lib/Bcfg2/Client/__init__.py b/src/lib/Bcfg2/Client/__init__.py index 359d7ac73..1240ad74a 100644 --- a/src/lib/Bcfg2/Client/__init__.py +++ b/src/lib/Bcfg2/Client/__init__.py @@ -874,7 +874,7 @@ class Client(object): else: self.logger.info("%s:%s" % (entry.tag, entry.get('name'))) - self.logger.info('Total managed entries: %d' % + self.logger.info('Total managed entries: %d' % len(list(self.states.values()))) self.logger.info('Unmanaged entries: %d' % len(self.extra)) if phase == 'final' and Bcfg2.Options.setup.show_extra: diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py index 8e0dd2efe..c10677804 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py +++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py @@ -359,8 +359,11 @@ def get_fam(): available = dict() # pylint: disable=C0103 # TODO: loading the monitor drivers should be automatic -from Bcfg2.Server.FileMonitor.Pseudo import Pseudo -available['pseudo'] = Pseudo +try: + from Bcfg2.Server.FileMonitor.Pseudo import Pseudo + available['pseudo'] = Pseudo +except ImportError: + pass try: from Bcfg2.Server.FileMonitor.Gamin import Gamin diff --git a/src/lib/Bcfg2/Server/Lint/GroupPatterns.py b/src/lib/Bcfg2/Server/Lint/GroupPatterns.py index 8ddb9e796..deb91020d 100644 --- a/src/lib/Bcfg2/Server/Lint/GroupPatterns.py +++ b/src/lib/Bcfg2/Server/Lint/GroupPatterns.py @@ -2,6 +2,7 @@ ` """ import sys + from Bcfg2.Server.Lint import ServerPlugin from Bcfg2.Server.Plugins.GroupPatterns import PatternMap @@ -28,15 +29,13 @@ class GroupPatterns(ServerPlugin): def check(self, entry, groups, ptype="NamePattern"): """ Check a single pattern for validity """ - if ptype == "NamePattern": - pmap = lambda p: PatternMap(p, None, groups) - else: - pmap = lambda p: PatternMap(None, p, groups) - for el in entry.findall(ptype): pat = el.text try: - pmap(pat) + if ptype == "NamePattern": + PatternMap(pat, None, groups) + else: + PatternMap(None, pat, groups) except: # pylint: disable=W0702 err = sys.exc_info()[1] self.LintError("pattern-fails-to-initialize", diff --git a/src/lib/Bcfg2/Server/Lint/Validate.py b/src/lib/Bcfg2/Server/Lint/Validate.py index cab5d248d..d6f18afbb 100644 --- a/src/lib/Bcfg2/Server/Lint/Validate.py +++ b/src/lib/Bcfg2/Server/Lint/Validate.py @@ -1,11 +1,15 @@ -""" Ensure that all XML files in the Bcfg2 repository validate -according to their respective schemas. """ +"""Validate XML files. +Ensure that all XML files in the Bcfg2 repository validate according +to their respective schemas. +""" + +import glob import os import sys -import glob -import fnmatch + import lxml.etree + import Bcfg2.Options import Bcfg2.Server.Lint from Bcfg2.Utils import Executor @@ -206,17 +210,10 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin): values are lists of the full paths to all files in the Bcfg2 repository (or given with ``bcfg2-lint --stdin``) that match the glob.""" - if self.files is not None: - listfiles = lambda p: fnmatch.filter(self.files, - os.path.join('*', p)) - else: - listfiles = lambda p: \ - glob.glob(os.path.join(Bcfg2.Options.setup.repository, p)) - for path in self.filesets.keys(): if '/**/' in path: if self.files is not None: - self.filelists[path] = listfiles(path) + self.filelists[path] = self.list_matching_files(path) else: # self.files is None fpath, fname = path.split('/**/') self.filelists[path] = [] @@ -227,9 +224,9 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin): for f in files if f == fname]) else: - self.filelists[path] = listfiles(path) + self.filelists[path] = self.list_matching_files(path) - self.filelists['props'] = listfiles("Properties/*.xml") + self.filelists['props'] = self.list_matching_files("Properties/*.xml") def _load_schema(self, filename): """ Load an XML schema document, returning the Schema object diff --git a/src/lib/Bcfg2/Server/Lint/ValidateJSON.py b/src/lib/Bcfg2/Server/Lint/ValidateJSON.py index 6383a3c99..f7cf5d549 100644 --- a/src/lib/Bcfg2/Server/Lint/ValidateJSON.py +++ b/src/lib/Bcfg2/Server/Lint/ValidateJSON.py @@ -1,11 +1,13 @@ -"""Ensure that all JSON files in the Bcfg2 repository are +"""Validate JSON files. + +Ensure that all JSON files in the Bcfg2 repository are valid. Currently, the only plugins that uses JSON are Ohai and -Properties.""" +Properties. +""" import os import sys -import glob -import fnmatch + import Bcfg2.Server.Lint try: @@ -48,18 +50,11 @@ class ValidateJSON(Bcfg2.Server.Lint.ServerlessPlugin): def get_files(self): """Return a list of all JSON files to validate, based on :attr:`Bcfg2.Server.Lint.ValidateJSON.ValidateJSON.globs`. """ - if self.files is not None: - listfiles = lambda p: fnmatch.filter(self.files, - os.path.join('*', p)) - else: - listfiles = lambda p: glob.glob( - os.path.join(Bcfg2.Options.setup.repository, p)) - rv = [] for path in self.globs: if '/**/' in path: if self.files is not None: - rv.extend(listfiles(path)) + rv.extend(self.list_matching_files(path)) else: # self.files is None fpath, fname = path.split('/**/') for root, _, files in os.walk( @@ -68,5 +63,5 @@ class ValidateJSON(Bcfg2.Server.Lint.ServerlessPlugin): rv.extend([os.path.join(root, f) for f in files if f == fname]) else: - rv.extend(listfiles(path)) + rv.extend(self.list_matching_files(path)) return rv diff --git a/src/lib/Bcfg2/Server/Lint/__init__.py b/src/lib/Bcfg2/Server/Lint/__init__.py index 526bdf159..903ee6326 100644 --- a/src/lib/Bcfg2/Server/Lint/__init__.py +++ b/src/lib/Bcfg2/Server/Lint/__init__.py @@ -1,15 +1,19 @@ """ Base classes for Lint plugins and error handling """ -import os -import sys -import time import copy import fcntl +import fnmatch +import glob +import logging +import os import struct +import sys import termios -import logging import textwrap +import time + import lxml.etree + import Bcfg2.Options import Bcfg2.Server.Core import Bcfg2.Server.Plugins @@ -145,6 +149,14 @@ class Plugin(object): xml_declaration=False).decode("UTF-8").strip() return " line %s: %s" % (element.sourceline, xml) + def list_matching_files(self, path): + """list all files matching the path in self.files or the bcfg2 repo.""" + if self.files is not None: + return fnmatch.filter(self.files, os.path.join('*', path)) + else: + return glob.glob(os.path.join(Bcfg2.Options.setup.repository, + path)) + class ErrorHandler(object): """ A class to handle errors for bcfg2-lint plugins """ diff --git a/src/lib/Bcfg2/Server/Plugin/__init__.py b/src/lib/Bcfg2/Server/Plugin/__init__.py index 6599aa7a5..e28e458b3 100644 --- a/src/lib/Bcfg2/Server/Plugin/__init__.py +++ b/src/lib/Bcfg2/Server/Plugin/__init__.py @@ -12,10 +12,7 @@ documentation it's not necessary to use the submodules. E.g., you can from Bcfg2.Server.Plugin.base import Plugin """ -import os -import sys import Bcfg2.Options -sys.path.append(os.path.dirname(__file__)) # pylint: disable=W0401 from Bcfg2.Server.Plugin.base import * diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py index cb533f4f1..87d42fd1c 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py @@ -127,8 +127,8 @@ class Packages(Bcfg2.Server.Plugin.Plugin, Bcfg2.Options.PathOption( cf=("packages", "apt_config"), help="The default path for generated apt configs", - default= - "/etc/apt/sources.list.d/bcfg2-packages-generated-sources.list")] + default="/etc/apt/sources.list.d/" + "bcfg2-packages-generated-sources.list")] #: Packages is an alternative to #: :mod:`Bcfg2.Server.Plugins.Pkgmgr` and conflicts with it. diff --git a/src/lib/Bcfg2/Server/Test.py b/src/lib/Bcfg2/Server/Test.py index ecbba2fea..9a1d43d12 100644 --- a/src/lib/Bcfg2/Server/Test.py +++ b/src/lib/Bcfg2/Server/Test.py @@ -18,7 +18,10 @@ try: HAS_MULTIPROC = True except ImportError: HAS_MULTIPROC = False - active_children = lambda: [] # pylint: disable=C0103 + + def active_children(): + """active_children() when multiprocessing lib is missing.""" + return [] def get_sigint_handler(core): -- cgit v1.2.3-1-g7c22