From 49310544d96a6ec47a6afd2b2c48b324804379eb Mon Sep 17 00:00:00 2001 From: Michael Gebetsroither Date: Thu, 2 Nov 2006 19:07:12 +0100 Subject: [PATCH 1/1] removed unnecessary stuff from modcalc.py --- modcalc.py | 134 ++++--------------------------------------------------------- 1 file changed, 8 insertions(+), 126 deletions(-) diff --git a/modcalc.py b/modcalc.py index 68c81fc..a50183c 100755 --- a/modcalc.py +++ b/modcalc.py @@ -2,46 +2,9 @@ import sys import os -import fileinput - -def modulesFromSubprocess(): - import subprocess - return subprocess.Popen('awk "/ethernet/{print \$3}" /lib/discover/pci.lst |sort |uniq', - stdout=subprocess.PIPE, shell=True).communicate()[0].splitlines() - -def modulesFromOwnFileinput(): - modlist = [] - for i in fileinput.input('/lib/discover/pci.lst'): - #i = i.lstrip(' \t') - tmplist = i.split('\t', 3) - try: - type = tmplist[2] - mod = tmplist[3] - except: - continue - if type == 'ethernet' and mod != 'unknown': - modlist.append(mod) - fileinput.close() - return modlist - -def modulesFromOwn(): - modlist = set() - f = open('/lib/discover/pci.lst', 'r') - for i in f: - #i = i.lstrip(' \t') - tmplist = i.split('\t', 4) - try: - type = tmplist[2] - mod = tmplist[3] - except: - continue - if type == 'ethernet' and mod != 'unknown': - modlist.add(mod) - f.close() - return modlist - -def modulesFromOwn2(): +def getNicModules(): + """Get all NIC modules which discover is able to find""" f = open('/lib/discover/pci.lst', 'r') import re ethlinefilter = re.compile('ethernet') @@ -59,34 +22,13 @@ def modulesFromOwn2(): f.close() return new_modlist - def basename(p): + """Quite faster implementation of os.path.basename, submitted and accepted""" i = p.rfind('/') + 1 return p[i:] -def osbasename(p): - return os.path.split(p)[1] - -def generateModDep_basename(): - moddep = {} - moddepfile = open(sys.argv[1], 'r') - for i in moddepfile: - tmplist = i.split() - mainmod = tmplist.pop(0) - mainmod = mainmod.rstrip(':') - rawmod = mainmod.rstrip('.ko') - rawmod = osbasename(rawmod) - newlist = [] - newlist.append((rawmod, mainmod)) - for i in tmplist: - a = i.rstrip('.ko') - a = osbasename(a) - newlist.append((a, i)) - moddep[rawmod] = newlist - moddepfile.close() - return moddep - -def generateModDep_mybasename(): +def generateModDep(): + """Generate an in-memory represenation of all module dependencies""" moddep = {} moddepfile = open(sys.argv[1], 'r') for i in moddepfile: @@ -105,60 +47,8 @@ def generateModDep_mybasename(): moddepfile.close() return moddep -def ossplit(p): - i = p.rfind('/') + 1 - head, tail = p[:i], p[i:] - if head and head != '/'*len(head): - head = head.rstrip('/') - return head, tail - -def split(p): - i = p.rfind('/') + 1 - head, tail = p[:i], p[i:] - head = head.rstrip('/') - if not head: - head = '/' - return head, tail - -def generateModDep_split(): - moddep = {} - moddepfile = open(sys.argv[1], 'r') - for i in moddepfile: - tmplist = i.split() - mainmod = tmplist.pop(0) - mainmod = mainmod.rstrip(':') - rawmod = mainmod.rstrip('.ko') - (a, rawmod) = ossplit(rawmod) - newlist = [] - newlist.append((rawmod, mainmod)) - for i in tmplist: - a = i.rstrip('.ko') - (x, a) = ossplit(a) - newlist.append((a, i)) - moddep[rawmod] = newlist - moddepfile.close() - return moddep - -def generateModDep_mysplit(): - moddep = {} - moddepfile = open(sys.argv[1], 'r') - for i in moddepfile: - tmplist = i.split() - mainmod = tmplist.pop(0) - mainmod = mainmod.rstrip(':') - rawmod = mainmod.rstrip('.ko') - (a, rawmod) = split(rawmod) - newlist = [] - newlist.append((rawmod, mainmod)) - for i in tmplist: - a = i.rstrip('.ko') - (x, a) = split(a) - newlist.append((a, i)) - moddep[rawmod] = newlist - moddepfile.close() - return moddep - def generateOutput(modlist, moddep): + """Function to filter all keys from moddep not in modlist""" output = {} for i in modlist: try: @@ -169,16 +59,8 @@ def generateOutput(modlist, moddep): return output def calculateModuleDep(): - #modlist = modulesFromSubprocess() - #modlist = modulesFromOwnFileinput() - #modlist = modulesFromOwn() - modlist = modulesFromOwn2() - - #moddep = generateModDep_basename() - #moddep = generateModDep_split() - #moddep = generateModDep_mysplit() - moddep = generateModDep_mybasename() - + modlist = getNicModules() + moddep = generateModDep() output = generateOutput(modlist, moddep) return output.values() -- 2.1.4