* implement a database of files

* implement a search-file command, not tested yet
This commit is contained in:
Eray Özkural
2005-10-10 10:52:59 +00:00
parent c6a8087c47
commit 987a4b8417
3 changed files with 71 additions and 1 deletions
+1
View File
@@ -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()
+50 -1
View File
@@ -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 <search pattern>
"""
pass
class SearchFile(Command):
"""Search for a file
Usage: search-file <path1> <path2> ... <pathn>
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
+20
View File
@@ -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]