removed unnecessary stuff from modcalc.py
authorMichael Gebetsroither <michael.geb@gmx.at>
Thu, 2 Nov 2006 18:07:12 +0000 (19:07 +0100)
committerMichael Gebetsroither <michael.geb@gmx.at>
Thu, 2 Nov 2006 18:07:12 +0000 (19:07 +0100)
modcalc.py

index 68c81fc..a50183c 100755 (executable)
@@ -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()