#
-# $Id$
-#
-
"""Modprobe is a utility to read/modify/write /etc/modprobe.conf"""
import os
command = parts[0].lower()
# check if its a command we support
- if not self.conffile.has_key(command):
- print "WARNING: command %s not recognized." % command
+ if command not in self.conffile:
+ print("WARNING: command %s not recognized." % command)
continue
func = funcs.get(command,__default)
fb.close()
return buf_a == buf_b
- except IOError, e:
+ except IOError as e:
return False
def output(self,filename="/etc/modprobe.conf",program="NodeManager"):
for command in ("alias","options","install","remove","blacklist"):
table = self.conffile[command]
- keys = table.keys()
+ keys = list(table.keys())
keys.sort()
for k in keys:
v = table[k]
fb.close()
if not self._comparefiles(tmpnam,filename):
os.rename(tmpnam,filename)
- os.chmod(filename,0644)
+ os.chmod(filename,0o644)
return True
else:
os.unlink(tmpnam)
if __name__ == '__main__':
import sys
+ m = Modprobe()
if len(sys.argv)>1:
- m = Modprobe(sys.argv[1])
+ fn = sys.argv[1]
else:
- m = Modprobe()
+ fn = "/etc/modprobe.conf"
m.input()
- m.aliasset("bond0","bonding")
- m.optionsset("bond0","miimon=100")
- m.output("/tmp/x")
+
+ blacklist = Modprobe()
+ blacklistfiles = os.listdir("/etc/modprobe.d")
+ for blf in blacklistfiles:
+ if os.path.exists("/etc/modprobe.d/%s"%blf):
+ blacklist.input("/etc/modprobe.d/%s"%blf)
+
+ m.output("/tmp/%s-tmp"%os.path.basename(fn),"TEST")
+ blacklist.output("/tmp/blacklist-tmp.txt","TEST")