5 """Modprobe is a utility to read/modify/write /etc/modprobe.conf"""
10 def __init__(self,filename="/etc/modprobe.conf"):
12 self.origconffile = {}
13 for keyword in ("alias","options","install","remove","blacklist","MODULES"):
14 self.conffile[keyword]={}
15 self.filename = filename
17 def input(self,filename=None):
18 if filename==None: filename=self.filename
19 fb = file(filename,"r")
20 for line in fb.readlines():
22 command = parts[0].lower()
24 table = self.conffile.get(command,None)
26 print "WARNING: command %s not recognize. Ignoring!" % command
29 if command == "alias":
32 self.aliasset(wildcard,modulename)
35 options=" ".join(parts[3:])
36 self.optionsset(modulename,options)
37 self.conffile['MODULES']={}
38 self.conffile['MODULES'][modulename]=options
41 rest=" ".join(parts[2:])
42 self._set(command,modulename,rest)
43 if command == "options":
44 self.conffile['MODULES'][modulename]=rest
46 self.origconffile = self.conffile.copy()
48 def _get(self,command,key):
49 return self.conffile[command].get(key,None)
51 def _set(self,command,key,value):
52 self.conffile[command][key]=value
54 def aliasget(self,key):
55 return self._get('alias',key)
57 def optionsget(self,key):
58 return self._get('options',key)
60 def aliasset(self,key,value):
61 self._set("alias",key,value)
63 def optionsset(self,key,value):
64 self._set("options",key,value)
66 def _comparefiles(self,a,b):
68 if not os.path.exists(a): return False
73 if not os.path.exists(b): return False
82 def output(self,filename="/etc/modprobe.conf",program="NodeManager"):
85 fb.write("# Written out by %s\n" % program)
87 for command in ("alias","options","install","remove","blacklist"):
88 table = self.conffile[command]
93 fb.write("%s %s %s\n" % (command,k,v))
96 if not self._comparefiles(tmpnam,filename):
97 os.rename(tmpnam,filename)
98 os.chmod(filename,0644)
103 def probe(self,name):
104 o = os.popen("/sbin/modprobe %s" % name)
107 def checkmodules(self):
108 syspath="/sys/module"
109 modules = os.listdir(syspath)
110 for module in modules:
111 path="%/%s/parameters"%(syspath,module)
112 if os.path.exists(path):
116 fb = file("%s/%s"%(path,p),"r")
117 parameters[p]=fb.readline()
120 if __name__ == '__main__':
123 m = Modprobe(sys.argv[1])
128 m.aliasset("bond0","bonding")
129 m.optionsset("bond0","miimon=100")