|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /proc/21571/root/usr/share/doc/readahead-1.3/ |
Upload File : |
#!/usr/bin/python
#
# This script is helper for readahead lists mainrainers.
#
# Basic features:
#
# - replaces arch specific paths with RPM macros, because we have to
# distribute architecture independent lists of files in src.rpm
# (e.g /usr/lib --> /usr/%{_lib})
#
# - checks for missing files and suggest possible solution
# (you need to run this script with --check option)
#
#
# Copyright, 2006 Red Hat, Inc.
# Karel Zak <kzak@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# $Id: readahead-check,v 1.1 2006/07/19 22:47:58 kzak Exp $
#
import sys
import os
import getopt
import re
from stat import *
NOREPLACE = [ '/lib/kbd/keymaps' ]
REPLACE = {
'%{_arch}' : '%{_arch}',
'/%{_lib}/' : '/%{_lib}/',
'/usr/%{_lib}/' : '/usr/%{_lib}/'
}
class RahGenerator:
def __init__(self):
self.files = []
self.evaled = {}
self.replace = {}
self.noreplace = []
for k,v in REPLACE.iteritems():
k = self.evalString(k)
self.replace[k] = v
for v in NOREPLACE:
v = self.evalString(v)
self.noreplace.append(v)
def evalRpm(self, str):
if self.evaled.has_key(str):
return self.evaled[str]
f = os.popen("rpm --eval %s" % str)
data = f.readlines()
f.close()
if data and len(data):
e = data[0][:-1]
self.evaled[str] = e
return e
print "WARNING: cannot evaluate '%s'" % str
return ''
def evalString(self, str):
xstr = str
vals = re.findall('%{[a-zA-Z_]*}', str)
for name in vals:
data = self.evalRpm(name)
str = str.replace(name, data)
return str
def templateLoad(self, filename):
f = open(filename, "r")
fl = f.readlines()
f.close()
for line in fl:
file = line.strip()
if file:
self.files.append( self.evalString(file) )
def templateCheck(self):
for file in self.files:
if not os.path.exists(file):
f = self.fileSearch(file)
if f:
print 'SUGGEST: %s --> %s' % (file, f)
else:
print 'NOTFOUND: %s' % file
def filesWrite(self, filename):
siz = 0
num = 0
fnum = 0
f = open(filename, "w")
for file in self.files:
if os.path.exists(file):
siz += os.stat(file)[ST_SIZE]
num += 1
else:
fnum += 1
f.write( self.filePathIndep(file) )
f.write('\n')
f.close()
if fnum:
print "\n%d kB in %d files (%d files not found)\n" % (siz / 1024, num, fnum)
else:
print "\n%d kB in %d files\n" % (siz / 1024, num)
def fileSearch(self, filename, recur=0):
idx = filename.rfind('/')
if idx >= 0:
filename = filename[idx+1:]
f = os.popen("locate -q -r /%s$" % filename.replace('.', '\.'))
data = f.readlines()
f.close()
if len(data):
return data[0][:-1]
if recur==0:
nums = re.findall('[0-9]+', filename)
for num in nums:
filename = filename.replace(num, '[0-9]*')
if len(nums):
return self.fileSearch(filename, 1)
return None
def filePathIndep(self, filename):
fsz = len(filename)
for n in self.noreplace:
nsz = len(n)
if nsz > fsz:
continue
if filename[:nsz] == n:
return filename
for k,v in self.replace.iteritems():
ksz = len(k)
if ksz > fsz:
continue
if filename[:ksz] == k:
f = v + filename[ksz:]
return f
return filename
def usage():
print "\nreadahead-gen [options]\n"
print " -h | --help this help"
print " --template=<filename> list of files"
print " --output=<filename> output file"
print " --check run with check"
print "\n"
sys.exit(0)
def main():
optlist, args = getopt.getopt(sys.argv[1:], 'h',
['template=', 'output=', 'help', 'check'])
if ('--help', '') in optlist or ('-h', '') in optlist:
usage()
tpl=None
check=0
out=None
for o in optlist:
if o[0] == '--template' and len(o[1]):
tpl=o[1]
elif o[0] == '--check':
check=1
elif o[0] == '--output' and len(o[1]):
out=o[1]
if tpl==None:
usage()
gen = RahGenerator()
gen.templateLoad(tpl)
if check==1:
gen.templateCheck()
else:
gen.nfiles = gen.files
if out:
gen.filesWrite(out)
if __name__ == "__main__":
main()
# vim: set tabstop=4:
# vim: set shiftwidth=4:
# vim: set expandtab: