aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlawek <lis.slawek@gmail.com>2011-01-18 07:18:42 +0100
committerSlawek <lis.slawek@gmail.com>2011-01-18 07:18:42 +0100
commit74b8c16fa6f8ccb173b480093317c9365e66250a (patch)
tree5429f6f20418eb19ad7074f571b3eb55ed6ea1a2
parentSplit to several files. Introduced logging (instead of print_v) (diff)
downloadgentoolkit-74b8c16fa6f8ccb173b480093317c9365e66250a.tar.gz
gentoolkit-74b8c16fa6f8ccb173b480093317c9365e66250a.tar.bz2
gentoolkit-74b8c16fa6f8ccb173b480093317c9365e66250a.zip
Some fixes after file split. Removed unwanted files. Moved settings into module
-rw-r--r--pym/gentoolkit/revdep_rebuild/analyse.py18
-rw-r--r--pym/gentoolkit/revdep_rebuild/assign.py9
-rw-r--r--pym/gentoolkit/revdep_rebuild/cache.py10
-rw-r--r--pym/gentoolkit/revdep_rebuild/collect.py26
-rw-r--r--[-rwxr-xr-x]pym/gentoolkit/revdep_rebuild/revdep-rebuild.py63
-rw-r--r--pym/gentoolkit/revdep_rebuild/revdep_rebuild.kdev43
-rw-r--r--pym/gentoolkit/revdep_rebuild/settings.py26
-rw-r--r--pym/gentoolkit/revdep_rebuild/test.py7
8 files changed, 76 insertions, 86 deletions
diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py
index 5141f6f..004163e 100644
--- a/pym/gentoolkit/revdep_rebuild/analyse.py
+++ b/pym/gentoolkit/revdep_rebuild/analyse.py
@@ -1,17 +1,17 @@
#!/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
@@ -23,7 +23,7 @@ def prepare_checks(files_to_check, libraries, bits):
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?
@@ -143,7 +143,7 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N
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})
@@ -170,7 +170,7 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N
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)
diff --git a/pym/gentoolkit/revdep_rebuild/assign.py b/pym/gentoolkit/revdep_rebuild/assign.py
index 836e792..6dcf6e3 100644
--- a/pym/gentoolkit/revdep_rebuild/assign.py
+++ b/pym/gentoolkit/revdep_rebuild/assign.py
@@ -6,7 +6,7 @@ import logging
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):
@@ -14,9 +14,9 @@ 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:
@@ -71,7 +71,6 @@ def get_slotted_cps(cpvs, logger):
cps = []
for cpv in cpvs:
parts = catpkgsplit(cpv)
- print cpv
cp = parts[0] + '/' + parts[1]
try:
slot = portdb.aux_get(cpv, ["SLOT"])
diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py
index 5f7b932..421e22d 100644
--- a/pym/gentoolkit/revdep_rebuild/cache.py
+++ b/pym/gentoolkit/revdep_rebuild/cache.py
@@ -3,11 +3,11 @@
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
@@ -29,7 +29,7 @@ def read_cache(temp_path=DEFAULT_TMP_DIR):
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
@@ -53,7 +53,7 @@ def save_cache(logger=logging, to_save={}, temp_path=DEFAULT_TMP_DIR):
-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
diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py
index ca71d3d..4a0714b 100644
--- a/pym/gentoolkit/revdep_rebuild/collect.py
+++ b/pym/gentoolkit/revdep_rebuild/collect.py
@@ -7,12 +7,10 @@ import stat
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
@@ -64,15 +62,15 @@ def prepare_search_dirs(logger=logging):
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)
@@ -87,7 +85,7 @@ def parse_revdep_config():
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
diff --git a/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
index c28b1b0..f2fda2e 100755..100644
--- a/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
+++ b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
@@ -25,42 +25,19 @@ from portage import portdb
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
@@ -122,26 +99,26 @@ if __name__ == "__main__":
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:
@@ -152,14 +129,14 @@ if __name__ == "__main__":
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)
@@ -167,7 +144,7 @@ if __name__ == "__main__":
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)
@@ -178,15 +155,15 @@ if __name__ == "__main__":
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:
diff --git a/pym/gentoolkit/revdep_rebuild/revdep_rebuild.kdev4 b/pym/gentoolkit/revdep_rebuild/revdep_rebuild.kdev4
deleted file mode 100644
index 7c395ce..0000000
--- a/pym/gentoolkit/revdep_rebuild/revdep_rebuild.kdev4
+++ /dev/null
@@ -1,3 +0,0 @@
-[Project]
-Manager=KDevGenericManager
-Name=revdep_rebuild
diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py
new file mode 100644
index 0000000..ea6b1ec
--- /dev/null
+++ b/pym/gentoolkit/revdep_rebuild/settings.py
@@ -0,0 +1,26 @@
+#!/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,
+ }
diff --git a/pym/gentoolkit/revdep_rebuild/test.py b/pym/gentoolkit/revdep_rebuild/test.py
deleted file mode 100644
index 9f87f32..0000000
--- a/pym/gentoolkit/revdep_rebuild/test.py
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/python
-
-import logging
-
-logging.basicConfig(format='%(msg)s', level=logging.DEBUG)
-#logging.basicConfig()
-logging.info('test') \ No newline at end of file