]> git.ipfire.org Git - people/arne_f/ipfire-3.x.git/blobdiff - kernel/scripts/configcommon.py
Merge remote-tracking branch 'ms/kernel-3.2'
[people/arne_f/ipfire-3.x.git] / kernel / scripts / configcommon.py
diff --git a/kernel/scripts/configcommon.py b/kernel/scripts/configcommon.py
new file mode 100755 (executable)
index 0000000..54f355a
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+###############################################################################
+# IPFire.org    - An Open Source Firewall Solution                            #
+# Copyright (C) - IPFire Development Team <info@ipfire.org>                   #
+###############################################################################
+
+import re
+import sys
+
+filelist = sys.argv[1:]
+
+lines = []
+options_state   = {}
+options_counter = {}
+
+first_file = True
+for filename in filelist:
+       f = open(filename)
+
+       for line in f.readlines():
+               # Strip newline.
+               line = line.rstrip()
+
+               if line.startswith("# Automatically generated file;"):
+                       continue
+
+               if line.endswith("Kernel Configuration"):
+                       continue
+
+               option = value = None
+
+               m = re.match("^# (.*) is not set$", line)
+               if m:
+                       option = m.group(1)
+                       value  = "n"
+
+               m = re.match("^(.*)=(.*)$", line)
+               if m:
+                       option = m.group(1)
+                       value  = m.group(2)
+
+               if option:
+                       option_value = "%s=%s" % (option, value or "")
+
+                       try:
+                               options_counter[option_value] += 1
+                               continue
+
+                       except KeyError:
+                               options_counter[option_value] = 1
+
+               if first_file:
+                       lines.append(line)
+
+       f.close()
+       first_file = False
+
+for line in lines:
+       m = re.match("^# (.*) is not set$", line)
+       if m:
+               if options_counter.get("%s=n" % m.group(1), 0) == len(filelist):
+                       print "# %s is not set" % m.group(1)
+
+               continue
+
+       m = re.match("^(.*)=(.*)$", line)
+       if m:
+               if options_counter.get(m.group(0), 0) == len(filelist):
+                       print m.group(0)
+
+               continue
+
+       print line