partial pylint cleanup
authordol-sen <brian.dolbec@gmail.com>
Wed, 13 Jul 2011 22:37:00 +0000 (15:37 -0700)
committerdol-sen <brian.dolbec@gmail.com>
Wed, 13 Jul 2011 22:37:00 +0000 (15:37 -0700)
pym/gentoolkit/revdep_rebuild/collect.py
pym/gentoolkit/revdep_rebuild/rebuild.py
pym/gentoolkit/revdep_rebuild/settings.py
pym/gentoolkit/revdep_rebuild/stuff.py

index e8075d8071877cd86f9d86502b8863ed3bad6b44..d1b23c0fb257c38265f7f1cf8e3cc56123c42201 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+"""Data collection module"""
+
 import re
 import os
 import glob
@@ -22,8 +24,8 @@ def parse_conf(conf_file, visited=None, logger=None):
 
        for conf in conf_file:
                try:
-                       with open(conf) as f:
-                               for line in f:
+                       with open(conf) as _file:
+                               for line in _file:
                                        line = line.strip()
                                        if line.startswith('#'):
                                                continue
@@ -62,8 +64,8 @@ def prepare_search_dirs(logger, settings):
        lib_dirs = set(['/lib', '/usr/lib', ])
 
        #try:
-       with open(os.path.join(portage.root, settings['DEFAULT_ENV_FILE']), 'r') as f:
-               for line in f:
+       with open(os.path.join(portage.root, settings['DEFAULT_ENV_FILE']), 'r') as _file:
+               for line in _file:
                        line = line.strip()
                        m = re.match("^export (ROOT)?PATH='([^']+)'", line)
                        if m is not None:
@@ -84,10 +86,11 @@ def parse_revdep_config(revdep_confdir):
        masked_files = set()
 
        #TODO: remove hard-coded path
-       for f in os.listdir(revdep_confdir):
-               for line in open(os.path.join('/etc/revdep-rebuild', f)):
+       for _file in os.listdir(revdep_confdir):
+               for line in open(os.path.join('/etc/revdep-rebuild', _file)):
                        line = line.strip()
-                       if not line.startswith('#'): #first check for comment, we do not want to regex all lines
+                       #first check for comment, we do not want to regex all lines
+                       if not line.startswith('#'): 
                                m = re.match('LD_LIBRARY_MASK=\\"([^"]+)\\"', line)
                                if m is not None:
                                        s = m.group(1).split(' ')
@@ -116,8 +119,9 @@ def collect_libraries_from_dir(dirs, mask, logger):
                (symlink_id, library_id) for resolving dependencies
        '''
 
-
-       found_directories = []  # contains list of directories found; allow us to reduce number of fnc calls
+       # contains list of directories found
+       # allows us to reduce number of fnc calls
+       found_directories = []  
        found_files = []
        found_symlinks = []
        found_la_files = [] # la libraries
@@ -172,15 +176,17 @@ def collect_libraries_from_dir(dirs, mask, logger):
                                                                        prv & stat.S_IXOTH == stat.S_IXOTH:
                                                                found_files.append(l)
                except Exception as ex:
-                       logger.debug(yellow('Exception during collecting libraries: ' + blue('%s')  %str(ex)))
+                       logger.debug(
+                               yellow('Exception during collecting libraries: ' + 
+                               blue('%s')  %str(ex)))
 
 
        if found_directories:
-               f,a,l,p = collect_libraries_from_dir(found_directories, mask, logger)
-               found_files+=f
-               found_la_files+=a
-               found_symlinks+=l
-               symlink_pairs+=p
+               f, a, l, p = collect_libraries_from_dir(found_directories, mask, logger)
+               found_files += f
+               found_la_files += a
+               found_symlinks += l
+               symlink_pairs += p
 
        return (found_files, found_la_files, found_symlinks, symlink_pairs)
 
@@ -191,7 +197,9 @@ def collect_binaries_from_dir(dirs, mask, logger):
                Returns list of binaries
        '''
 
-       found_directories = []  # contains list of directories found; allow us to reduce number of fnc calls
+       # contains list of directories found
+       # allows us to reduce number of fnc calls
+       found_directories = []  
        found_files = []
 
        for d in dirs:
@@ -211,7 +219,9 @@ def collect_binaries_from_dir(dirs, mask, logger):
                                        else:
                                                found_directories.append(l)
                                elif os.path.isfile(l):
-                                       #we're looking for binaries, and with binaries we do not need links, thus we can optimize a bit
+                                       # we're looking for binaries
+                                       # and with binaries we do not need links
+                                       # thus we can optimize a bit
                                        if not os.path.islink(l):
                                                prv = os.stat(l)[stat.ST_MODE]
                                                if prv & stat.S_IXUSR == stat.S_IXUSR or \
@@ -219,7 +229,9 @@ def collect_binaries_from_dir(dirs, mask, logger):
                                                                prv & stat.S_IXOTH == stat.S_IXOTH:
                                                        found_files.append(l)
                except Exception as e:
-                       logger.debug(yellow('Exception during binaries collecting: '+blue('%s') %str(e)))
+                       logger.debug(
+                               yellow('Exception during binaries collecting: '+
+                               blue('%s') %str(e)))
 
        if found_directories:
                found_files += collect_binaries_from_dir(found_directories, mask, logger)
@@ -230,17 +242,20 @@ def collect_binaries_from_dir(dirs, mask, logger):
 
 if __name__ == '__main__':
        import logging
-       bin_dirs, lib_dirs = prepare_search_dirs(logging)
+       mbin_dirs, mlib_dirs = prepare_search_dirs(logging)
 
-       masked_dirs, masked_files, ld = parse_revdep_config()
-       lib_dirs.update(ld)
-       bin_dirs.update(ld)
-       masked_dirs.update(['/lib/modules', '/lib32/modules', '/lib64/modules'])
+       mmasked_dirs, mmasked_files, mld = parse_revdep_config()
+       mlib_dirs.update(mld)
+       mbin_dirs.update(mld)
+       mmasked_dirs.update(['/lib/modules', '/lib32/modules', '/lib64/modules'])
 
-       libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logging)
-       binaries = collect_binaries_from_dir(bin_dirs, masked_dirs, logging)
+       libraries, la_libraries, libraries_links, msymlink_pairs = collect_libraries_from_dir(
+               mlib_dirs, mmasked_dirs, logging)
+       binaries = collect_binaries_from_dir(mbin_dirs, mmasked_dirs, logging)
 
-       logging.debug('Found: %i binaries and %i libraries.' %(len(binaries), len(libraries)))
+       logging.debug(
+               'Found: %i binaries and %i libraries.' %(
+               len(binaries), len(libraries)))
 
 
 
index 9ac4811707f86d4cc2f2ed8b1ccb5c71b0f8e558..04fb96cd6cb4bd102951beab3a5b4415a093d8dc 100644 (file)
 # Creation date: 2010/10/17
 # License: BSD
 
-import subprocess
 import os
 import sys
-import re
 import getopt
-import signal
-import stat
-import time
-import glob
-import portage
 import logging
-from portage import portdb
 from portage.output import bold, red, blue, yellow, green, nocolor
 
 from analyse import analyse
@@ -41,6 +33,7 @@ __productname__ = "revdep-ng"
 # functions
 
 def print_usage():
+       """Outputs the help message"""
        print( APP_NAME + ': (' + VERSION +')')
        print
        print('This is free software; see the source for copying conditions.')
@@ -93,8 +86,8 @@ def init_logger(settings):
 def parse_options():
        """Parses the command line options an sets settings accordingly"""
 
-       # @TODO: Verify: options: no-ld-path, no-order, no-progress are not appliable 
-       # for revdep-ng
+       # TODO: Verify: options: no-ld-path, no-order, no-progress
+       #are not appliable
 
        settings = DEFAULTS.copy()
        try:
@@ -161,14 +154,25 @@ def rebuild(logger, assigned, settings):
 
        emerge_command = emerge_command
 
-       logger.warn(yellow('\nemerge') + args + ' --oneshot --complete-graph=y ' + bold(emerge_command))
+       logger.warn(yellow(
+               '\nemerge') + args + 
+               ' --oneshot --complete-graph=y ' +
+               bold(emerge_command))
        
-       success = os.system('emerge ' + args + ' --oneshot --complete-graph=y ' + emerge_command)
+       success = os.system(
+               'emerge ' + args + 
+               ' --oneshot --complete-graph=y ' + 
+               emerge_command)
        return success
 
 
-# Runs from here
 def main(settings=None, logger=None):
+       """Main program operation method....
+       
+       @param settings: dict.  defaults to settings.DEFAULTS
+       @param logger: python logging module defaults to init_logger(settings)
+       @return boolean  success/failure
+       """
 
        if settings is None:
                print("NO Input settings, using defaults...")
@@ -193,9 +197,9 @@ def main(settings=None, logger=None):
                        yellow('This is a development version, '
                                'so it may not work correctly'))
                logger.warn(blue(' * ') + 
-                       yellow('The original revdep-rebuild script is installed as revdep-rebuild.sh'))
+                       yellow('The original revdep-rebuild script is '
+                               'installed as revdep-rebuild.sh'))
 
-       analyze_cache = {}
        if settings['USE_TMP_FILES'] \
                        and check_temp_files(settings['DEFAULT_TMP_DIR']):
                libraries, la_libraries, libraries_links, binaries = read_cache(
@@ -218,13 +222,13 @@ def main(settings=None, logger=None):
 
        has_masked = False
        tmp = []
-       for a in assigned:
-               if get_masking_status(a):
+       for ebuild in assigned:
+               if get_masking_status(ebuild):
                        has_masked = True
                        logger.warn('!!! ' + red('All ebuilds that could satisfy: ') + 
-                               green(a) + red(' have been masked'))
+                               green(ebuild) + red(' have been masked'))
                else:
-                       tmp.append(a)
+                       tmp.append(ebuild)
        assigned = tmp
 
        if has_masked:
index 96aa491a51918b0aaf4ea4c5b616d9ac0cb7464a..b56f8127c4cf541f76135c6b01e55c122b710df3 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+"""Default settings"""
+
 import os
 import sys
 
@@ -12,17 +14,18 @@ DEFAULTS = {
                'PKG_DIR': os.path.join(portage.root, 'var/db/pkg/'),
                'DEFAULT_TMP_DIR': '/tmp/revdep-rebuild', #cache default location
 
-
-               'USE_TMP_FILES': True, #if program should use temporary files from previous run
-               'CMD_MAX_ARGS': 1000, # number of maximum allowed files to be parsed at once
+               # number of maximum allowed files to be parsed at once
+               'CMD_MAX_ARGS': 1000, 
 
                'PRETEND': False,     #pretend only
                'EXACT': False,      #exact package version
-               'USE_TMP_FILES': True, #if program should use temporary files from previous run
+               #if program should use temporary files from previous run
+               'USE_TMP_FILES': True, 
 
-               'IS_DEV': True,       #True for dev. version, False for stable
-                               #used when IS_DEV is True, False forces to call emerge with --pretend
-                               # can be set True from the cli with the --no-pretend option
+               #True for dev. version, False for stable
+               #used when IS_DEV is True, False forces to call emerge with --pretend
+               # can be set True from the cli with the --no-pretend option
+               'IS_DEV': True,
                'NO_PRETEND': False,
                'VERBOSITY': 1,
                
index 1ab21f255db0607a431ffe4021c45990d3ecc6ac..163cc7d154fcae252d45386fc46ccdca11ade2a1 100644 (file)
@@ -1,5 +1,8 @@
 #!/usr/bin/python
 
+"""Utilities submodule"""
+
+
 import subprocess
 
 import portage
@@ -27,15 +30,17 @@ def scan(params, files, max_args):
        '''
        out = []
        for i in range(0, len(files), max_args):
-               out += call_program(['scanelf'] + params + files[i:i+max_args]).strip().split('\n')
+               out += call_program(
+                       ['scanelf'] + params + files[i:i+max_args]).strip().split('\n')
        return out
 
 
-def exithandler(signum, frame):
-       sys.exit(1)
-
-
 def get_masking_status(ebuild):
+       """returns the masking status of an ebuild
+       
+       @param ebuild: str
+       @return list
+       """
        try:
                status = portage.getmaskingstatus(ebuild)
        except KeyError:
@@ -44,6 +49,11 @@ def get_masking_status(ebuild):
 
 
 def _match_str_in_list(lst, stri):
+       """
+       @param lst: list
+       @param stri: string
+       @return boolean or list menber that matches stri.endswith(member)
+       """
        for l in lst:
                if stri.endswith(l):
                        return l