Re: Checking dependency

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2002-05-23 at 15:59, Rajkumar S. wrote:
> Hi,
> 
> I have a small script (attached) that I use to copy files from a
> repository of all rpms to the directory from where I burn the CD.
> basically what I intend to do is to make a single RedHat CD with all the
> updates for a server class installation. For that I have trimmed the comps
> file to remove the X and other unwanted stuff. My script (hopefully)
> copies all the packages that are listed in the comps file to the destdir,
> from where I burn the CD.
> 
> Now I want to add dependency check to this script, so that after copying
> it will run the dependency check and will inform if their are any
> problems.
> 
> The anaconda has a function to find out dependency problems, but I could
> not figure out which. Any help here will be much appreciated.

The attached takes one argument - the dir you want depchecked.

this does not do anything with the comps file, at all.

Jeremy mentioned doing something like that. If I thought I had any shot
of intelligently understanding the comps parsing I would work on it, but
I'm not that smart yet.

-sv

#!/usr/bin/python

import os, sys,rpm,re,string

def Usage():
	# yah, duh.
	print "%s (path of dir you'd like depchecked)" % (sys.argv[0])
	sys.exit(1)


def readHeader(rpmfn):
	# read the header from the rpm if its an rpm, from a file its a file
	# return 'source' if its a src.rpm - something useful here would be good probably.
	if string.lower(rpmfn[-4:]) == '.rpm':
		fd = os.open(rpmfn, os.O_RDONLY)
		(h,src) = rpm.headerFromPackage(fd)
		os.close(fd)
		if src:
			return 'source'
		else:
			return h
	else:
		fd = open(rpmfn, "r")
		h = rpm.headerLoad(fd.read())
		fd.close()
		return h

def getfilelist(path, ext, list):
	# get all the files matching the 3 letter extension that is ext in path, recursively
	# store them in append them to list
	# return list
	# ignore symlinks
	dir_list = os.listdir(path)

	for d in dir_list:
		if os.path.isdir(path + '/' + d):
			list = getfilelist(path + '/' + d, ext, list)
		else:
			if string.lower(d[-4:]) == '%s' % (ext):
				if not os.path.islink( path + '/' + d): 
					newpath = os.path.normpath(path + '/' + d)
					list.append(newpath)
	return(list)

def formatRequire (name, version, flags):
    string = name
	    
    if flags:
      if flags & (rpm.RPMSENSE_LESS | rpm.RPMSENSE_GREATER | rpm.RPMSENSE_EQUAL):
         string = string + " "
      if flags & rpm.RPMSENSE_LESS:
         string = string + "<"
      if flags & rpm.RPMSENSE_GREATER:
         string = string + ">"
      if flags & rpm.RPMSENSE_EQUAL:
         string = string + "="
         string = string + " %s" % version
    return string




if len(sys.argv) < 2:
	Usage()
	
ts = rpm.TransactionSet('/')

treerpmlist=getfilelist(sys.argv[1],'.rpm',[])
for rpmfn in treerpmlist:
	h = readHeader(rpmfn)
	if h != 'source':
		ts.add(h, h[rpm.RPMTAG_NAME], 'i')
		print "adding %s" % h[rpm.RPMTAG_NAME]       


errors = ts.depcheck()
if errors:
	for ((name, version, release), (reqname, reqversion),
		flags, suggest, sense) in errors:
		print "depcheck: package %s needs %s" % ( name, formatRequire(reqname, reqversion, flags))
		
else:
	print "All dependencies resolved in %s" % sys.argv[1]
	


Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux