From dd28e90f183972cc2a395094ce3e3f72e861953f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 21 Sep 2012 13:55:05 -0400 Subject: run pylint for errors on almost everything, full runs on some selected stuff --- .../Bcfg2/Server/Plugins/Packages/Collection.py | 28 ++++++++------- .../Server/Plugins/Packages/PackagesSources.py | 3 ++ src/lib/Bcfg2/Server/Plugins/Packages/Source.py | 11 +++--- src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 42 +++++++++++++--------- src/lib/Bcfg2/Server/Plugins/Packages/__init__.py | 8 ++++- 5 files changed, 58 insertions(+), 34 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Packages') diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py index d0e4a3665..bb98fe1e5 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py @@ -78,8 +78,7 @@ import copy import logging import lxml.etree import Bcfg2.Server.Plugin -from Bcfg2.Compat import any, md5 -from Bcfg2.Server.Plugins.Packages.Source import Source +from Bcfg2.Compat import any, md5 # pylint: disable=W0622 LOGGER = logging.getLogger(__name__) @@ -180,15 +179,18 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): return "\n".join(srcs) def get_relevant_groups(self): - groups = [] - for source in self: - groups.extend(source.get_relevant_groups(self.metadata)) - return sorted(list(set(groups))) - get_relevant_groups.__doc__ = Source.get_relevant_groups.__doc__ + """ + """ Get all groups that might be relevant to determining which + sources apply to this collection's client. The base implementation simply aggregates the results of :func:`Bcfg2.Server.Plugins.Packages.Source.Source.get_relevant_groups` + + :return: list of strings - group names """ + groups = [] + for source in self: + groups.extend(source.get_relevant_groups(self.metadata)) + return sorted(list(set(groups))) @property def basegroups(self): @@ -253,8 +255,8 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): :ref:`pkg-objects` """ if not self.__package_groups__: - self.logger.error("Packages: Package groups are not supported by %s" - % self.__class__.__name__) + self.logger.error("Packages: Package groups are not supported by " + "%s" % self.__class__.__name__) return [] for source in self: @@ -484,7 +486,7 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): """ return list(complete.difference(initial)) - def complete(self, packagelist): + def complete(self, packagelist): # pylint: disable=R0912,R0914 """ Build a complete list of all packages and their dependencies. :param packagelist: Set of initial packages computed from the @@ -562,7 +564,8 @@ class Collection(list, Bcfg2.Server.Plugin.Debuggable): if len(vpkg_cache[current]) == 1: self.debug_log("Packages: requirement %s satisfied by %s" % (current, vpkg_cache[current])) - unclassified.update(vpkg_cache[current].difference(examined)) + unclassified.update( + vpkg_cache[current].difference(examined)) satisfied_vpkgs.add(current) else: satisfiers = [item for item in vpkg_cache[current] @@ -623,7 +626,8 @@ def get_collection_class(source_type): try: cclass = getattr(module, source_type.title() + "Collection") except AttributeError: - msg = "Packages: No collection class found for %s sources" % source_type + msg = "Packages: No collection class found for %s sources" % \ + source_type LOGGER.error(msg) raise Bcfg2.Server.Plugin.PluginExecutionError(msg) return cclass diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py index 329dfc394..2519ddff6 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py @@ -1,3 +1,6 @@ +""" PackagesSources handles the +:ref:`server-plugins-generators-packages` ``sources.xml`` file""" + import os import sys import Bcfg2.Server.Plugin diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py index 26f3ab92f..22d488121 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py @@ -92,7 +92,7 @@ class SourceInitError(Exception): REPO_RE = re.compile(r'(?:pulp/repos/|/RPMS\.|/)([^/]+)/?$') -class Source(Bcfg2.Server.Plugin.Debuggable): +class Source(Bcfg2.Server.Plugin.Debuggable): # pylint: disable=R0902 """ ``Source`` objects represent a single tag in ``sources.xml``. Note that a single Source tag can itself describe multiple repositories (if it uses the "url" attribute @@ -116,7 +116,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable): #: when they are handled by :mod:`Bcfg2.Server.Plugins.Packages`. ptype = None - def __init__(self, basepath, xsource, setup): + def __init__(self, basepath, xsource, setup): # pylint: disable=R0912 """ :param basepath: The base filesystem path under which cache data for this source should be stored @@ -301,7 +301,8 @@ class Source(Bcfg2.Server.Plugin.Debuggable): """ Get all groups that might be relevant to determining which sources apply to this collection's client. - :return: list of strings - group names""" + :return: list of strings - group names + """ return sorted(list(set([g for g in metadata.groups if (g in self.basegroups or g in self.groups or @@ -349,6 +350,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable): upstream repository. :type force_update: bool """ + # pylint: disable=W0702 if not force_update: if os.path.exists(self.cachefile): try: @@ -379,6 +381,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable): self.logger.error("Packages: Failed to load data for %s: %s" % (self, err)) self.logger.error("Some Packages will be missing") + # pylint: enable=W0702 def get_repo_name(self, url_map): """ Try to find a sensible name for a repository. Since @@ -485,7 +488,7 @@ class Source(Bcfg2.Server.Plugin.Debuggable): vdict[key].update(value) return vdict - def is_virtual_package(self, metadata, package): + def is_virtual_package(self, metadata, package): # pylint: disable=W0613 """ Return True if a name is a virtual package (i.e., is a symbol provided by a real package), False otherwise. diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index 1d7eca808..4224798a8 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -59,15 +59,17 @@ import logging import lxml.etree from subprocess import Popen, PIPE import Bcfg2.Server.Plugin +# pylint: disable=W0622 from Bcfg2.Compat import StringIO, cPickle, HTTPError, URLError, \ ConfigParser, json, any +# pylint: enable=W0622 from Bcfg2.Server.Plugins.Packages.Collection import Collection from Bcfg2.Server.Plugins.Packages.Source import SourceInitError, Source, \ fetch_url -logger = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) -# pylint: disable=E0611 +# pylint: disable=E0611,F0401 try: from pulp.client.consumer.config import ConsumerConfig from pulp.client.api.repository import RepositoryAPI @@ -82,9 +84,9 @@ try: HAS_YUM = True except ImportError: HAS_YUM = False - logger.info("Packages: No yum libraries found; forcing use of internal " + LOGGER.info("Packages: No yum libraries found; forcing use of internal " "dependency resolver") -# pylint: enable=E0611 +# pylint: enable=E0611,F0401 XP = '{http://linux.duke.edu/metadata/common}' RP = '{http://linux.duke.edu/metadata/rpm}' @@ -108,7 +110,7 @@ def _setup_pulp(setup): if not HAS_PULP: msg = "Packages: Cannot create Pulp collection: Pulp libraries " + \ "not found" - logger.error(msg) + LOGGER.error(msg) raise Bcfg2.Server.Plugin.PluginInitError(msg) if PULPSERVER is None: @@ -117,12 +119,12 @@ def _setup_pulp(setup): password = setup.cfp.get("packages:pulp", "password") except ConfigParser.NoSectionError: msg = "Packages: No [pulp] section found in bcfg2.conf" - logger.error(msg) + LOGGER.error(msg) raise Bcfg2.Server.Plugin.PluginInitError(msg) except ConfigParser.NoOptionError: msg = "Packages: Required option not found in bcfg2.conf: %s" % \ sys.exc_info()[1] - logger.error(msg) + LOGGER.error(msg) raise Bcfg2.Server.Plugin.PluginInitError(msg) PULPCONFIG = ConsumerConfig() @@ -265,7 +267,7 @@ class YumCollection(Collection): yumconf.write(open(self.cfgfile, 'w')) - def get_config(self, raw=False): + def get_config(self, raw=False): # pylint: disable=W0221 """ Get the yum configuration for this collection. :param raw: Return a :class:`ConfigParser.SafeConfigParser` @@ -528,7 +530,7 @@ class YumCollection(Collection): ptype = "default" gdicts.append(dict(group=group, type=ptype)) - return self.call_helper("get_groups", gdicts) + return self.call_helper("get_groups", inputdata=gdicts) def packages_from_entry(self, entry): """ When using the Python yum libraries, convert a Package @@ -543,6 +545,7 @@ class YumCollection(Collection): name = entry.get("name") def _tag_to_pkg(tag): + """ Convert a Package or Instance tag to a package tuple """ rv = (name, tag.get("arch"), tag.get("epoch"), tag.get("version"), tag.get("release")) if rv[3] in ['any', 'auto']: @@ -584,6 +587,9 @@ class YumCollection(Collection): :returns: None """ def _get_entry_attrs(pkgtup): + """ Given a package tuple, return a dict of attributes + suitable for applying to either a Package or an Instance + tag """ attrs = dict(version=self.setup.cfp.get("packages", "version", default="auto")) @@ -685,7 +691,7 @@ class YumCollection(Collection): else: return set(), set() - def call_helper(self, command, input=None): + def call_helper(self, command, inputdata=None): """ Make a call to :ref:`bcfg2-yum-helper`. The yum libs have horrific memory leaks, so apparently the right way to get around that in long-running processes it to have a short-lived @@ -694,10 +700,10 @@ class YumCollection(Collection): :param command: The :ref:`bcfg2-yum-helper` command to call. :type command: string - :param input: The input to pass to ``bcfg2-yum-helper`` on - stdin. If this is None, no input will be given - at all. - :type input: Any JSON-encodable data structure. + :param inputdata: The input to pass to ``bcfg2-yum-helper`` on + stdin. If this is None, no input will be + given at all. + :type inputdata: Any JSON-encodable data structure. :returns: Varies depending on the return value of the ``bcfg2-yum-helper`` command. """ @@ -715,8 +721,8 @@ class YumCollection(Collection): (" ".join(cmd), err)) return None - if input: - idata = json.dumps(input) + if inputdata: + idata = json.dumps(inputdata) (stdout, stderr) = helper.communicate(idata) else: (stdout, stderr) = helper.communicate() @@ -938,7 +944,7 @@ class YumSource(Source): try: self.packages['global'] = copy.deepcopy(sdata.pop()) except IndexError: - logger.error("Packages: No packages in repo") + self.logger.error("Packages: No packages in repo") while sdata: self.packages['global'] = \ self.packages['global'].intersection(sdata.pop()) @@ -951,6 +957,7 @@ class YumSource(Source): self.save_state() def parse_filelist(self, data, arch): + """ parse filelists.xml.gz data """ if arch not in self.filemap: self.filemap[arch] = dict() for pkg in data.findall(FL + 'package'): @@ -963,6 +970,7 @@ class YumSource(Source): set([pkg.get('name')]) def parse_primary(self, data, arch): + """ parse primary.xml.gz data """ if arch not in self.packages: self.packages[arch] = set() if arch not in self.deps: diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py index fd6369619..6f8e3ecad 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py @@ -1,3 +1,7 @@ +""" Packages resolves Package entries on the Bcfg2 server in order to +present a complete list of Package entries to the client in order to +determine the completeness of the client configuration. """ + import os import sys import glob @@ -68,6 +72,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, self.logger.warning("You can disable magic groups by setting " "magic_groups=0 in [packages] in bcfg2.conf") + # pylint: disable=C0301 #: The #: :class:`Bcfg2.Server.Plugins.Packages.PackagesSources.PackagesSources` #: object used to generate @@ -98,12 +103,13 @@ class Packages(Bcfg2.Server.Plugin.Plugin, self.collections = dict() #: clients is a cache mapping of hostname -> - #: :attr:`Bcfg2.Server.Plugins.Packages.Collection.Collection.cachekey`. + #: :attr:`Bcfg2.Server.Plugins.Packages.Collection.Collection.cachekey` #: Unlike :attr:`collections`, this _is_ used to return a #: :class:`Bcfg2.Server.Plugins.Packages.Collection.Collection` #: object when one is requested, so each entry is very #: short-lived -- it's purged at the end of each client run. self.clients = dict() + # pylint: enable=C0301 __init__.__doc__ = Bcfg2.Server.Plugin.Plugin.__init__.__doc__ -- cgit v1.2.3-1-g7c22