#!/usr/bin/python
+import os
+import re
import platform
import logging
import glob
from portage.output import bold, red, blue, yellow, green, nocolor
-from stuff import *
-from collect import *
+from stuff import scan
+from collect import prepare_search_dirs, parse_revdep_config, collect_libraries_from_dir, collect_binaries_from_dir
from assign import assign_packages
-
-
-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
+from cache import save_cache
+from settings import SETTINGS
dependencies = [] # list of lists of files (from file_to_check) that uses
# library (for dependencies[id] and libs[id] => id==id)
- for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, CMD_MAX_ARGS):
+ for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, SETTINGS['CMD_MAX_ARGS']):
#call_program(['scanelf', '-M', str(bits), '-nBF', '%F %n',]+files_to_check).strip().split('\n'):
r = line.strip().split(' ')
if len(r) < 2: # no dependencies?
libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logger)
binaries = collect_binaries_from_dir(bin_dirs, masked_dirs, logger)
- if USE_TMP_FILES:
+ if SETTINGS['USE_TMP_FILES']:
save_cache(to_save={'libraries':libraries, 'la_libraries':la_libraries, 'libraries_links':libraries_links, 'binaries':binaries})
for av_bits in glob.glob('/lib[0-9]*') or ('/lib32',):
bits = int(av_bits[4:])
- _libraries = scan(['-M', str(bits), '-BF', '%F'], libraries+libraries_links, CMD_MAX_ARGS)
+ _libraries = scan(['-M', str(bits), '-BF', '%F'], libraries+libraries_links, SETTINGS['CMD_MAX_ARGS'])
#call_program(['scanelf', '-M', str(bits), '-BF', '%F',] + libraries+libraries_links).strip().split('\n')
found_libs, dependencies = prepare_checks(libs_and_bins, _libraries, bits)
import portage
from portage import portdb
from portage.output import bold, red, blue, yellow, green, nocolor
-
+from settings import SETTINGS
def assign_packages(broken, logger=logging):
Broken is list of files
'''
assigned = set()
- for group in os.listdir('/var/db/pkg'):
- for pkg in os.listdir('/var/db/pkg/' + group):
- f = '/var/db/pkg/' + group + '/' + pkg + '/CONTENTS'
+ for group in os.listdir(SETTINGS['PKG_DIR']):
+ for pkg in os.listdir(SETTINGS['PKG_DIR'] + group):
+ f = SETTINGS['PKG_DIR'] + group + '/' + pkg + '/CONTENTS'
if os.path.exists(f):
try:
with open(f, 'r') as cnt:
cps = []
for cpv in cpvs:
parts = catpkgsplit(cpv)
- print cpv
cp = parts[0] + '/' + parts[1]
try:
slot = portdb.aux_get(cpv, ["SLOT"])
import os
import time
import logging
+from portage.output import red
+from settings import SETTINGS
-DEFAULT_TMP_DIR = '/tmp/revdep-rebuild' #cache default location
-
-def read_cache(temp_path=DEFAULT_TMP_DIR):
+def read_cache(temp_path=SETTINGS['DEFAULT_TMP_DIR']):
''' Reads cache information needed by analyse function.
This function does not checks if files exists nor timestamps,
check_temp_files should be called first
return (ret['libraries'], ret['la_libraries'], ret['libraries_links'], ret['binaries'])
-def save_cache(logger=logging, to_save={}, temp_path=DEFAULT_TMP_DIR):
+def save_cache(logger=logging, to_save={}, temp_path=SETTINGS['DEFAULT_TMP_DIR']):
''' Tries to store caching information.
@param logger
@param to_save have to be dict with keys: libraries, la_libraries, libraries_links and binaries
-def check_temp_files(temp_path=DEFAULT_TMP_DIR, max_delay=3600):
+def check_temp_files(temp_path=SETTINGS['DEFAULT_TMP_DIR'], max_delay=3600):
''' Checks if temporary files from previous run are still available
and if they aren't too old
@param temp_path is directory, where temporary files should be found
import logging
import portage
from portage.output import bold, red, blue, yellow, green, nocolor
+from settings import SETTINGS
-DEFAULT_LD_FILE = 'etc/ld.so.conf'
-DEFAULT_ENV_FILE = 'etc/profile.env'
-
-def parse_conf(conf_file=os.path.join(portage.root, DEFAULT_LD_FILE), visited=None, logger=logging):
+def parse_conf(conf_file=SETTINGS['DEFAULT_LD_FILE'], visited=None, logger=logging):
''' Parses supplied conf_file for libraries pathes.
conf_file is file or files to parse
visited is set of files already parsed
bin_dirs = set(['/bin', '/usr/bin', ])
lib_dirs = set(['/lib', '/usr/lib', ])
- try:
- with open(os.path.join(portage.root, DEFAULT_ENV_FILE), 'r') as f:
- for line in f.readlines():
- line = line.strip()
- m = re.match("^export (ROOT)?PATH='([^']+)'", line)
- if m is not None:
- bin_dirs = bin_dirs.union(set(m.group(2).split(':')))
- except EnvironmentError:
- logger.debug(yellow('Could not open file %s' % f))
+ #try:
+ with open(os.path.join(portage.root, SETTINGS['DEFAULT_ENV_FILE']), 'r') as f:
+ for line in f.readlines():
+ line = line.strip()
+ m = re.match("^export (ROOT)?PATH='([^']+)'", line)
+ if m is not None:
+ bin_dirs = bin_dirs.union(set(m.group(2).split(':')))
+ #except EnvironmentError:
+ #logger.debug(yellow('Could not open file %s' % f))
lib_dirs = parse_conf(logger=logger)
return (bin_dirs, lib_dirs)
masked_files = set()
#TODO: remove hard-coded path
- for f in os.listdir('/etc/revdep-rebuild/'):
+ for f in os.listdir(SETTINGS['REVDEP_CONFDIR']):
for line in open(os.path.join('/etc/revdep-rebuild', f)):
line = line.strip()
if not line.startswith('#'): #first check for comment, we do not want to regex all lines
from portage.output import bold, red, blue, yellow, green, nocolor
from analyse import analyse
-from stuff import *
-from cache import *
+from stuff import exithandler
+from cache import check_temp_files, read_cache
from assign import get_slotted_cps
+from settings import SETTINGS
APP_NAME = sys.argv[0]
-VERSION = '0.1-r5'
-
+VERSION = '0.1-r6'
__productname__ = "revdep-ng"
-# configuration variables
-DEFAULT_LD_FILE = 'etc/ld.so.conf'
-DEFAULT_ENV_FILE = 'etc/profile.env'
-
-
-# global variables
-PRINT_DEBUG = False #program in debug mode
-
-PRETEND = False #pretend only
-EXACT = False #exact package version
-USE_TMP_FILES = True #if program should use temporary files from previous run
-DEFAULT_TMP_DIR = '/tmp/revdep-rebuild' #cache default location
-VERBOSITY = 1 #verbosity level; 0-quiet, 1-norm., 2-verbose
-
-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
-NO_PRETEND = False
-
-CMD_MAX_ARGS = 1000 # number of maximum allowed files to be parsed at once
-
-
-
def print_usage():
print APP_NAME + ': (' + VERSION +')'
print
print_usage()
sys.exit(0)
elif key in ('-q', '--quiet'):
- VERBOSITY = 0
logger.setLevel(logging.ERROR)
+ SETTINGS['VERBOSITY'] = 0
elif key in ('-v', '--verbose'):
- VERBOSITY = 2
logger.setLevel(logging.INFO)
+ SETTINGS['VERBOSITY'] = 2
elif key in ('-d', '--debug'):
- PRINT_DEBUG = True
logger.setLevel(logging.DEBUG)
+ SETTINGS['VERBOSITY'] = 3
elif key in ('-p', '--pretend'):
- PRETEND = True
+ SETTINGS['PRETEND'] = True
elif key == '--no-pretend':
- NO_PRETEND = True
+ SETTINGS['NO_PRETEND'] = True
elif key in ('-e', '--exact'):
- EXACT = True
+ SETTINGS['EXACT'] = True
elif key in ('-C', '--nocolor', '--no-color'):
nocolor()
elif key in ('-L', '--library', '--library='):
_libs_to_check = _libs_to_check.union(val.split(','))
elif key in ('-i', '--ignore'):
- USE_TMP_FILES = False
+ SETTINGS['USE_TMP_FILES'] = False
args = " " + " ".join(args)
except getopt.GetoptError:
if not sys.stdout.isatty():
nocolor()
- if os.getuid() != 0 and not PRETEND:
+ if os.getuid() != 0 and not SETTINGS['PRETEND']:
logger.warn(blue(' * ') + yellow('You are not root, adding --pretend to portage options'))
- PRETEND = True
- elif not PRETEND and IS_DEV and not NO_PRETEND:
+ SETTINGS['PRETEND'] = True
+ elif not SETTINGS['PRETEND'] and SETTINGS['IS_DEV'] and not SETTINGS['NO_PRETEND']:
logger.warn(blue(' * ') + yellow('This is a development version, so it may not work correctly'))
logger.warn(blue(' * ') + yellow('Adding --pretend to portage options anyway'))
logger.info(blue(' * ') + 'If you\'re sure, you can add --no-pretend to revdep options')
- PRETEND = True
+ SETTINGS['PRETEND'] = True
signal.signal(signal.SIGINT, exithandler)
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
analyze_cache = {}
- if USE_TMP_FILES and check_temp_files():
+ if SETTINGS['USE_TMP_FILES'] and check_temp_files():
libraries, la_libraries, libraries_links, binaries = read_cache()
assigned = analyse(libraries=libraries, la_libraries=la_libraries, \
libraries_links=libraries_links, binaries=binaries, _libs_to_check=_libs_to_check)
logger.warn('\n' + bold('Your system is consistent'))
sys.exit(0)
- if EXACT:
+ if SETTINGS['EXACT']:
emerge_command = '=' + ' ='.join(assigned)
else:
emerge_command = ' '.join(get_slotted_cps(assigned, logger))
- if PRETEND:
+ if SETTINGS['PRETEND']:
args += ' --pretend'
- if VERBOSITY >= 2:
+ if SETTINGS['VERBOSITY'] >= 2:
args += ' --verbose'
- elif VERBOSITY < 1:
+ elif SETTINGS['VERBOSITY'] < 1:
args += ' --quiet'
if len(emerge_command) == 0:
+++ /dev/null
-[Project]
-Manager=KDevGenericManager
-Name=revdep_rebuild
--- /dev/null
+#!/usr/bin/python
+
+import os
+import portage
+
+SETTINGS = {
+ 'DEFAULT_LD_FILE': os.path.join(portage.root, 'etc/ld.so.conf'),
+ 'DEFAULT_ENV_FILE': os.path.join(portage.root, 'etc/profile.env'),
+ 'REVDEP_CONFDIR': os.path.join(portage.root, 'etc/revdep-rebuild/'),
+ '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
+
+ 'PRETEND': False, #pretend only
+ 'EXACT': False, #exact package version
+ 'USE_TMP_FILES': True, #if program should use temporary files from previous run
+
+ '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
+ 'NO_PRETEND': False,
+ 'VERBOSITY': 1,
+ }
+++ /dev/null
-#!/usr/bin/python
-
-import logging
-
-logging.basicConfig(format='%(msg)s', level=logging.DEBUG)
-#logging.basicConfig()
-logging.info('test')
\ No newline at end of file