Setting tag pyplnet-7.0-0
[pyplnet.git] / modprobe.py
index 04ca7d8..f48fa8d 100644 (file)
@@ -1,7 +1,4 @@
 #
-# $Id$
-#
-
 """Modprobe is a utility to read/modify/write /etc/modprobe.conf"""
 
 import os
@@ -75,8 +72,8 @@ class Modprobe:
                 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)
@@ -121,7 +118,7 @@ class Modprobe:
             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"):
@@ -131,7 +128,7 @@ class Modprobe:
 
         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]
@@ -140,7 +137,7 @@ class Modprobe:
         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)
@@ -165,12 +162,19 @@ class Modprobe:
          
 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")