summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Lint
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2015-02-24 16:29:07 -0600
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2015-02-25 07:59:49 -0600
commitcae39b746051ff5f3257342d0659340283b2d6ef (patch)
tree15754ec473e088b52cc8afc4d9ecaf8ee8d7ca2d /src/lib/Bcfg2/Server/Lint
parent78cac1d0a6923ebc73ff221f8501885c36c112c1 (diff)
downloadbcfg2-cae39b746051ff5f3257342d0659340283b2d6ef.tar.gz
bcfg2-cae39b746051ff5f3257342d0659340283b2d6ef.tar.bz2
bcfg2-cae39b746051ff5f3257342d0659340283b2d6ef.zip
Fix pylint errors
This also pins pylint to <= 0.28 so we don't have to keep playing whack-a-mole with it. Also removes unnecessary suppression of apt warnings. This is no longer necessary in 12.04, so should be safe to remove. If you're on Ubuntu < 12.04, upgrade for heaven's sake.
Diffstat (limited to 'src/lib/Bcfg2/Server/Lint')
-rw-r--r--src/lib/Bcfg2/Server/Lint/Validate.py25
-rw-r--r--src/lib/Bcfg2/Server/Lint/ValidateJSON.py21
-rw-r--r--src/lib/Bcfg2/Server/Lint/__init__.py12
3 files changed, 31 insertions, 27 deletions
diff --git a/src/lib/Bcfg2/Server/Lint/Validate.py b/src/lib/Bcfg2/Server/Lint/Validate.py
index 3efcc890d..1e33ec398 100644
--- a/src/lib/Bcfg2/Server/Lint/Validate.py
+++ b/src/lib/Bcfg2/Server/Lint/Validate.py
@@ -1,12 +1,16 @@
-""" 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
from subprocess import Popen, PIPE, STDOUT
+
import Bcfg2.Server.Lint
@@ -204,17 +208,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(self.config['repo'],
- 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] = []
@@ -225,9 +222,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 1f55962eb..bdbe6a271 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(self.config['repo'],
- 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 \
@@ -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 28644263f..ae2b81a61 100644
--- a/src/lib/Bcfg2/Server/Lint/__init__.py
+++ b/src/lib/Bcfg2/Server/Lint/__init__.py
@@ -1,14 +1,19 @@
""" Base classes for Lint plugins and error handling """
import os
+import fnmatch
+import glob
import sys
import logging
from copy import copy
import textwrap
+import time
+
import lxml.etree
import fcntl
import termios
import struct
+
from Bcfg2.Compat import walk_packages
plugins = [m[1] for m in walk_packages(path=__path__)] # pylint: disable=C0103
@@ -139,6 +144,13 @@ 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(self.config['repo'], path))
+
class ErrorHandler(object):
""" A class to handle errors for bcfg2-lint plugins """