From 1bdd4e1b3d132ba9254343fad783a1ac989b6a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 14 Nov 2005 23:32:04 +0000 Subject: [PATCH] * a new fast tool to find library dependencies! * some comments --- pisi.e3p | 16 +++++++++--- pisi/cli/commands.py | 8 +++--- pisi/package.py | 2 +- tools/find-lib-deps.py | 59 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 8 deletions(-) create mode 100755 tools/find-lib-deps.py diff --git a/pisi.e3p b/pisi.e3p index 9e2f631f..3a74b889 100644 --- a/pisi.e3p +++ b/pisi.e3p @@ -1,7 +1,7 @@ - + Python @@ -418,6 +418,14 @@ pxml xmlfilepiks.py + + tools + cat-source-repo.py + + + tools + find-lib-deps.py + @@ -459,10 +467,10 @@ {'standardLayout': 1} - - - + + + diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 02219b7d..fbda94b8 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -952,6 +952,8 @@ Finds the installed package which contains the specified file. self.parser.add_option("-f", "--fuzzy", action="store_true", default=False, help=_("fuzzy search")) + # and what does exact mean? -- exa + @staticmethod #fuck python 2.3 compatibility I don't care about it def search_exact(path): files = [] path = path.lstrip('/') #FIXME: this shouldn't be necessary :/ @@ -960,18 +962,18 @@ Finds the installed package which contains the specified file. if ctx.filesdb.has_file(path): files.append(ctx.filesdb.get_file(path)) else: + #FIXME: this linear search thing is not working well -- exa files = ctx.filesdb.get_files(path) if files: for (pkg_name, file_info) in files: #FIXME: files of the same package can be grouped under package name - ctx.ui.info(_('Package: %s has File: %s') % (pkg_name, file_info.path)) + ctx.ui.info(_("Package %s has file %s") % (pkg_name, file_info.path)) if ctx.config.options.long: ctx.ui.info(_('Type: %s, Hash: %s') % (file_info.type, file_info.hash)) else: - ctx.ui.error(_('Path %s does not belong to an installed package') % path) - search_exact=staticmethod(search_exact) + ctx.ui.error(_("Path '%s' does not belong to an installed package") % path) def run(self): diff --git a/pisi/package.py b/pisi/package.py index 1f65a583..2e436450 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -45,7 +45,7 @@ class Package: dest = ctx.config.packages_dir() self.filepath = join(dest, url.filename()) - # FIXME: exists is not enough, also sha1sum check needed \ + # FIXME: exists is not enough, also sha1sum check needed # when implemented in pisi-index.xml if not exists(self.filepath): fetch_url(url, dest, ctx.ui.Progress) diff --git a/tools/find-lib-deps.py b/tools/find-lib-deps.py new file mode 100755 index 00000000..f655fa4e --- /dev/null +++ b/tools/find-lib-deps.py @@ -0,0 +1,59 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- +# +# find library dependencies of a package +# author: exa (Eray Ă–zkural) + +import locale +import sys +import os +import fnmatch + +import gettext +__trans = gettext.translation('pisi', fallback=True) +_ = __trans.ugettext + +import pisi +import pisi.api +import pisi.config +import pisi.specfile as specfile +import pisi.context as ctx +import pisi.util as util +from pisi.package import Package + +locale.setlocale(locale.LC_ALL, '') +options = pisi.config.Options() +if len(sys.argv) > 2: + options.destdir=sys.argv[2] +else: + options.destdir = '/' +pisi.api.init(database=True, comar=False, options=options) + +filename = sys.argv[1] +package = Package(filename) +package.read() +util.clean_dir('/tmp/install') +package.extract_dir_flat('install', '/tmp/install') +deps = set() +needed = set() +for file in package.files.list: + #print file.path, file.type + if file.type == 'binary': + (ret, lines) = util.run_batch('objdump -p %s' % util.join_path('/tmp/install', file.path)) + for x in lines: + if x.startswith(' NEEDED'): + needed.add(x[8:].strip()) + +#print 'needed guys', needed + +for lib in needed: + + (ret, out) = util.run_batch('locate %s' % lib) + path = out[0].strip().lstrip('/') + try: + (pkg_name, file_info) = ctx.filesdb.get_file(path) + ctx.ui.info("Library dependency: '%s' due to library '%s'" % (pkg_name, file_info.path)) + except: + ctx.ui.warning('Cannot find an installed package for library %s' % lib) + +pisi.api.finalize()