From 32d0d61ebbb9a81397932ac3df0a60b8e51001aa Mon Sep 17 00:00:00 2001 From: Scott Sweeny Date: Mon, 12 Dec 2016 10:01:20 -0500 Subject: [PATCH] Make pep8 and flake8 happy --- bin/snaplint | 24 ++++++++++++++---------- snaplint/_rule.py | 2 +- snaplint/rules/copyright.py | 6 +++--- snaplint/rules/developer_cruft.py | 7 ++++--- snaplint/rules/libs.py | 19 ++++++++++--------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/bin/snaplint b/bin/snaplint index 6e8a466..3aab8b3 100755 --- a/bin/snaplint +++ b/bin/snaplint @@ -23,11 +23,13 @@ import os import sys import textwrap + def _snap_path(path): if os.path.exists(path): if os.path.exists(os.path.join(path, 'snapcraft.yaml')): - # a valid snap directory should contain meta/snap.yaml - if os.path.exists(os.path.join(path, 'prime', 'meta', 'snap.yaml')): + # a valid snap directory should contain meta/snap.yaml + if os.path.exists(os.path.join(path, 'prime', 'meta', + 'snap.yaml')): return os.path.join(path, 'prime') else: print("Please run 'snapcraft prime' in your project to" @@ -39,9 +41,11 @@ def _snap_path(path): print("%s does not exist" % path) return None + def _parse_args(): - parser = argparse.ArgumentParser(description='Clean up your snap', - formatter_class=argparse.RawTextHelpFormatter) + parser = argparse.ArgumentParser( + description='Clean up your snap', + formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('project', help=textwrap.dedent('''\ @@ -51,6 +55,7 @@ def _parse_args(): args = parser.parse_args() return args + def _get_scanner(module): for attr in vars(module).values(): if not isinstance(attr, type): @@ -70,17 +75,18 @@ if __name__ == '__main__': args = _parse_args() snap = _snap_path(args.project) - if snap == None: + if snap is None: print("Please specify a valid snapcraft directory") sys.exit(1) - + # This logic stolen shamelessly from snapcraft import snaplint import snaplint.rules rules_to_run = [] - for importer, modname, is_package in pkgutil.iter_modules(snaplint.rules.__path__): + for importer, modname, is_package in pkgutil.iter_modules( + snaplint.rules.__path__): rules_to_run.append(modname) - + print('Rules to run: ', rules_to_run) print("Running scan") @@ -106,5 +112,3 @@ if __name__ == '__main__': sys.exit(1) else: sys.exit(0) - - diff --git a/snaplint/_rule.py b/snaplint/_rule.py index de1b706..084a1d4 100644 --- a/snaplint/_rule.py +++ b/snaplint/_rule.py @@ -17,6 +17,7 @@ import os + class Rule: def __init__(self, path): @@ -42,7 +43,6 @@ def get_dir_list(self): self.path)) return dir_list - def scan(self): '''Override this method to implement your rule checking logic''' pass diff --git a/snaplint/rules/copyright.py b/snaplint/rules/copyright.py index e127c79..d949dfc 100644 --- a/snaplint/rules/copyright.py +++ b/snaplint/rules/copyright.py @@ -19,6 +19,7 @@ from snaplint._rule import Rule + class CopyrightRule(Rule): '''Scan for copyright files in usr/share/doc within the snap. System Enablement Team policy requires that these files be present''' @@ -27,12 +28,12 @@ def __init__(self, path): super().__init__(path) def scan(self): - '''Really dumb check that looks for at least one instance of + '''Really dumb check that looks for at least one instance of usr/share/doc/*/*copyright* ''' print('Scanning {} for copyright compliance...'.format(self.path), end=' ') - + pattern = self.path + 'usr/share/doc/*/*copyright*' if not glob.glob(pattern, recursive=True): print('FAIL') @@ -41,4 +42,3 @@ def scan(self): print('OK') return True - diff --git a/snaplint/rules/developer_cruft.py b/snaplint/rules/developer_cruft.py index d5cd0a4..133e838 100644 --- a/snaplint/rules/developer_cruft.py +++ b/snaplint/rules/developer_cruft.py @@ -17,18 +17,19 @@ from snaplint._rule import Rule -NAUGHTY_FILES=[ +NAUGHTY_FILES = [ '.o', # object files '.a', # static libs '.h', # header files '.hpp', ] -NAUGHTY_DIRS=[ +NAUGHTY_DIRS = [ '.git', '.bzr', ] + class DeveloperCruft(Rule): def __init__(self, path): @@ -37,7 +38,7 @@ def __init__(self, path): def scan(self): print('Scanning {} for developer cruft...'.format(self.path), end=' ') - fail_list=[] + fail_list = [] for f in self.get_file_list(): for suffix in NAUGHTY_FILES: if f.endswith(suffix): diff --git a/snaplint/rules/libs.py b/snaplint/rules/libs.py index 41e6ede..784c4f9 100644 --- a/snaplint/rules/libs.py +++ b/snaplint/rules/libs.py @@ -15,16 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from snaplint._rule import Rule - import os from elftools.common.exceptions import ELFError from elftools.elf.elffile import ELFFile -# Make things work easier on python3 -from elftools.common.py3compat import ( - ifilter, byte2int, bytes2str, itervalues, str2bytes) +from snaplint._rule import Rule + def _traverse_deps(root, elves): for lib in elves[root]['needed']: @@ -34,6 +31,7 @@ def _traverse_deps(root, elves): else: continue + class LibraryRule(Rule): '''Examine the executables in the snap and make sure that only needed libraries are included''' @@ -46,20 +44,23 @@ def _get_elves(self): with open(os.path.join(self.path, filename), "rb") as fp: try: elf = ELFFile(fp) - except ELFError as e: + except ELFError: # Probably not an ELF file continue dynamic = elf.get_section_by_name(b'.dynamic') if dynamic is None: continue - needed = frozenset(tag.needed for tag in dynamic.iter_tags('DT_NEEDED')) + needed = frozenset( + tag.needed for tag in dynamic.iter_tags('DT_NEEDED')) for tag in dynamic.iter_tags('DT_SONAME'): soname = tag.soname - elves[soname] = {'filename': filename, 'needed': needed, 'used': False} + elves[soname] = {'filename': filename, + 'needed': needed, + 'used': False} break else: roots[filename] = needed - except Exception as error: + except Exception: # If we can't open the file just skip to the next one continue