#! /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)