#!/usr/bin/python
+"""Data collection module"""
+
import re
import os
import glob
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
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:
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(' ')
(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
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)
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:
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 \
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)
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)))
# 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
# functions
def print_usage():
+ """Outputs the help message"""
print( APP_NAME + ': (' + VERSION +')')
print
print('This is free software; see the source for copying conditions.')
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:
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...")
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(
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:
#!/usr/bin/python
+"""Default settings"""
+
import os
import sys
'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,