Script per trovare a quale pacchetto appartiene un file
Inviato: mar 16 giu 2009, 19:47
Perdonate la lunghezza del titolo ma è quello che fa lo script che ho scritto per puro sfizio serale 
esempi di output sono
lo script è questo
ciao
Gio
esempi di output sono
Codice: Seleziona tutto
root@darkstar:~/findbasepkg# python filebelong.py /usr/lib64/libglib.a
/var/log/packages/glib-1.2.10-x86_64-3
root@darkstar:~/findbasepkg# python filebelong.py /usr/bin/lshal
/var/log/packages/hal-0.5.11-x86_64-5
root@darkstar:~/findbasepkg# python filebelong.py /bin/ls
/var/log/packages/coreutils-7.4-x86_64-1
root@darkstar:~/findbasepkg# python filebelong.py /bin/cat
/var/log/packages/coreutils-7.4-x86_64-1
root@darkstar:~/findbasepkg# python filebelong.py /usr/lib64/kde4/amarok_service_jamendo.so
/var/log/packages/amarok-2.1-x86_64-2
root@darkstar:~/findbasepkg# python filebelong.py /usr/lib64/vattelapesca.so
File /usr/lib64/vattelapesca.so not belongs to any package
root@darkstar:~/findbasepkg#
Codice: Seleziona tutto
#! /bin/python
# -*- coding: iso-8859-1 -*-
#Filebelong search to wich slackware package belongs a file
#Copyright (C) 2009 Giovanni Santostefano
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along
#with this program; if not, write to the Free Software Foundation, Inc.,
#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import os
c = 0
for arg in sys.argv:
c=c+1
if c < 2:
print "USAGE: python filebelong.py fullpath_of_file"
sys.exit(1)
basefilename=sys.argv[1]
basefilename.strip(' ')
if basefilename == "--help":
print "filebelong is a search utility for Slackware"
print "developed by Giovanni Santostefano."
print "filebelong search to wich slackware package belongs a file"
print "USAGE: python filebelong.py fullpath_of_file"
exit(1)
#basefilename = basefilename+"\n"
found = 0
packlist = os.walk("/var/log/packages/")
for root, dirs, filenames in packlist:
for filename in filenames:
if found == 1:
break
filelines = open("/var/log/packages/"+filename,"rU").readlines()
flag = 0
for line in filelines:
line = "/"+line
if (line.find("FILE LIST:") != -1):
flag = 1
if (flag == 0):
continue
if (line.find(basefilename) != -1 and len(line) == len(basefilename)+1):
found=1
print "/var/log/packages/"+filename
break
if found == 0:
print "File " + basefilename + " does not belongs to any package"
exit(1)
exit(0)
Gio