(no commit message)
[sfa.git] / sfatables / sfatables
index 8762a50..cbef86e 100755 (executable)
 import sys
 import os
 import pdb
+import libxml2
 from optparse import OptionParser
 
 from sfatables import commands, matches, targets
+from sfatables.xmlextension import Xmlextension
 
-def load_extensions(module, list):
+def load_commands(module, list):
     command_dict={}
 
     for command_name in list:
@@ -24,6 +26,16 @@ def load_extensions(module, list):
 
     return command_dict
 
+def load_xml_extensions(module, list):
+    ext_dict={}
+
+    for ext_name in list:
+        module = Xmlextension(ext_name)
+        ext_dict[ext_name]=module
+
+    return ext_dict
+
+
 def create_parser(command_dict):
     parser = OptionParser(usage="sfatables [command] [chain] [match] [target]",
                              description='See "man sfatables" for more detail.')
@@ -35,6 +47,17 @@ def create_parser(command_dict):
 
     return parser
 
+def xml_ext_create_parser(ext_dict):
+    parser = OptionParser(usage="sfatables [command] [chain] [match] [target]",
+                             description='See "man sfatables" for more detail.')
+    
+    for k in ext_dict.keys():
+        command = ext_dict[k]
+        for arg in command.arguments:
+            parser.add_option(None,"--"+arg,dest=arg,help=command.help,metavar=command.operand)
+
+    return parser
+
 
 def partition(sep, lst):
     ret = []
@@ -55,7 +78,7 @@ def main():
     
     pargs = partition('--', sys.argv[1:])
 
-    command_dict = load_extensions("sfatables.commands",commands.all)
+    command_dict = load_commands("sfatables.commands",commands.all)
     command_parser = create_parser(command_dict)
     (options, args) = command_parser.parse_args()
 
@@ -64,7 +87,7 @@ def main():
     if (command.matches):
         if (len(pargs)<2):
             raise Exception("Must specify match for this command")
-        match_dict = load_extensions("sfatables.matches",matches.all)
+        match_dict = load_xml_extensions("sfatables.matches",matches.all)
         match_parser = create_parser(match_dict)
         (match_options, args) = match_parser.parse_args(pargs[1])
     else:
@@ -73,7 +96,7 @@ def main():
     if (command.targets):
         if (len(pargs)<3):
             raise Exception("Must specify a target for this command")
-        match_dict = load_extensions("sfatables.targets",targets.all)
+        match_dict = load_xml_extensions("sfatables.targets",targets.all)
         target_parser = create_parser(match_dict)
         (target_options, args) = target_parser.parse_args(pargs[2])
     else: