#!/usr/bin/env python # # pkgdepcheck.py # # Script to find missing dependencies in current based on stable #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# # # # pkgdepcheck - a script to find subdependencies # # # # Copyright Tim Beech . # # # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# def main(): #open the package data (CSV format) #for each repo, find out whether it is present #and get the dependency list #if appropriate, print its deps #then send it to a function to recursively check #it and its deps #some output to cover other cases while True: package = raw_input("Please enter name of package: ") salixCurrent = 'salix32-current.csv' salixStable = 'salix32-13.37.csv' slackCurrent = 'slack32-current.csv' slackStable = 'slack32-13.37.csv' presentSalixStable, depSalixStable = checkRepo(package, salixStable) presentSalixCurrent, depSalixCurrent = checkRepo(package, salixCurrent) presentSlackStable, depSlackStable = checkRepo(package, slackStable) presentSlackCurrent, depSlackCurrent = checkRepo(package, slackCurrent) if presentSalixStable and not presentSalixCurrent: print "The package ", package, "is present in stable but has not been packaged for current yet." print if presentSlackCurrent: print "Aha! present in Slackware current." if presentSlackStable: print "It was present in Salix stable too, so a Salix package is probably still needed." print print "Its dependencies are ", print for i in depSalixStable.split(","): print i, print print "We will now check whether any of these deps remain unpackaged in current." print "The following packages are missing:" checkDeps(package) if presentSalixCurrent: print "The package ", package, "has already been packaged for current." elif not presentSalixStable: if presentSlackStable or presentSlackCurrent: print "The package ", package, " is a Slackware package." if presentSalixCurrent: print "However, it was packaged in Salix stable, so \ probably will be this time too." else: print "The package ", package, "is not present in stable." def checkRepo(package, repo): #for each row in the package data for one repo, #get the package name and the deps field #if it is the requested package, return true and the deps #if not, return False and an empty string import csv repoReader = csv.reader(open(repo)) pkgnameCell, depCell = 0,5 for row in repoReader: rawText = ','.join(row) name = getEntry(rawText, pkgnameCell) dep = getEntry(rawText, depCell) if package == name: return True, dep return False, "" def checkDeps(package): #a recursive function #if the package is present return #if it isn't, print its name #if it has no deps return #if it has them, recurse for each one salixStable = 'salix32-13.37.csv' salixCurrent = 'salix32-current.csv' slackStable = 'slack32-13.37.csv' slackCurrent = 'slack32-current.csv' #maybe not all these are necessary ... package = checkVel(package) presentSalixStable, depSalixStable = checkRepo(package, salixStable) presentSalixCurrent, depSalixCurrent = checkRepo(package, salixCurrent) presentSlackStable, depSlackStable = checkRepo(package, slackStable) presentSlackCurrent, depSlackCurrent = checkRepo(package, slackCurrent) if presentSalixCurrent: return elif presentSlackCurrent and not presentSalixStable: #If it was packaged in Salix stable, it probably needs to be again now. return else: print package if depSalixStable == "": return for dep in depSalixStable.split(","): checkDeps(dep) def checkVel(package): #deal with depX|depY items #this recursive function should cope with more than two #if it finds | it sends the remainder for checking #during which it will be called again # #however this doesn't entirely solve it #it requires *both* (or all) options to be present firstHalf, otherHalf, count = "", "", 0 for char in package: count = count + 1 if char == "|": otherHalf = checkVel(package[count:]) break else: firstHalf = firstHalf + char if otherHalf != "": checkDeps(otherHalf) return firstHalf def getEntry(rawText,cell): #from a row of CSV data, extract the nth cell #delimited by semicolons count = 0 for i in rawText.split(";"): if count == cell: return stripQuotes(i) count = count + 1 def stripQuotes(text): # remove leading or trailing quotation marks if text[0] == '"': text = text[1:] if text[-1] == '"': text = text[:-1] return text main()