From 987a4b84176ccfbc178c1852c85dcd95712a4a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 10 Oct 2005 10:52:59 +0000 Subject: [PATCH] * implement a database of files * implement a search-file command, not tested yet --- pisi/api.py | 1 + pisi/cli/commands.py | 51 +++++++++++++++++++++++++++++++++++++++++++- pisi/files.py | 20 +++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/pisi/api.py b/pisi/api.py index e28caef9..a5dddf73 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -61,6 +61,7 @@ def init(database = True, options = None, ui = None, comar = True): if database: ctx.repodb = pisi.repodb.init() ctx.installdb = pisi.installdb.init() + ctx.filesdb = pisi.files.FilesDB() # TODO: bunun da ctx'de olmasi gerek, global hesabi packagedb.init() diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index ae3f9547..fb41efd9 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -142,7 +142,8 @@ class Command(object): def help(self): """print help for the command""" ctx.ui.info(self.format_name() + ': ') - ctx.ui.info(__trans.ugettext(__doc__) + '\n') + trans = gettext.translation('pisi', fallback=True) + ctx.ui.info(trans.ugettext(self.__doc__) + '\n') ctx.ui.info(self.parser.format_option_help()) def die(self): @@ -788,6 +789,54 @@ Usage: search """ pass +class SearchFile(Command): + """Search for a file + +Usage: search-file ... + +Finds the installed package which contains the specified file. +""" + __metaclass__ = autocommand + + def __init__(self): + super(SearchFile, self).__init__() + + name = ("search-file", "sf") + + def options(self): + self.parser.add_option("-l", "--long", action="store_true", + default=False, help="show in long format") + + @staticmethod + def search_exact(path): + if ctx.filesdb.has_file(path): + (pkg_name, file_info) = ctx.filesdb.get_info(path) + ctx.ui.info(_('Package: %s') % pkg_name) + if ctx.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) + + def run(self): + + self.init(True) + + if not self.args: + self.help() + return + + # search among existing files + for path in self.args: + ctx.ui.info(_('Searching for %s') % path) + if os.path.exists(path): + search_exact(os.path.realpath(path)) + else: + pisi.api.error(_('%s cannot be found')) + + self.finalize() + + # Partial build commands diff --git a/pisi/files.py b/pisi/files.py index 9e29651f..868ec76b 100644 --- a/pisi/files.py +++ b/pisi/files.py @@ -16,6 +16,7 @@ from pisi.xmlext import * from pisi.xmlfile import XmlFile from pisi.util import Checks +import pisi.lockeddbshelve as shelve class FileInfo: """FileInfo holds the information for a File node/tag in files.xml""" @@ -95,3 +96,22 @@ class Files(XmlFile): for finfo in self.list: err.join(finfo.has_errors()) return err.list + +class FilesDB(shelve.LockedDBShelf): + + def __init__(self): + shelve.LockedDBShelf.__init__(self, 'files') + #self.files_dir = pisi.util.join_path(ctx.config.db_dir(), 'files') + + def add_files(pkg_name, files): + for x in files.list: + self[x.path] = (pkg_name, x) + + def has_file(path): + return self.has_key(path) + + def get_file_info(path): + if not self.has_key(path): + return None + else: + return self[path]