Ok, Add and List are working generically.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 2 Sep 2009 22:27:06 +0000 (22:27 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 2 Sep 2009 22:27:06 +0000 (22:27 +0000)
sfatables/commands/Add.py
sfatables/commands/List.py
sfatables/pretty.py

index b62ad6c..5064ee6 100644 (file)
@@ -24,9 +24,7 @@ class Add(Command):
                     if (number>last_rule_number):
                         last_rule_number = number
 
-        return "sfatables-%d-%s"%(last_rule_number,type)
-
-
+        return "sfatables-%d-%s"%(last_rule_number+1,type)
 
     def call(self, command_options, match_options, target_options):
         filename = match_dir + "/"+match_options.match_name+".xml"
@@ -51,10 +49,9 @@ class Add(Command):
 
         chain = command_options.args[0]
         filename = self.getnextfilename('match',chain)
-        xmldoc.saveFile(filename)
+        file_path = sfatables_config + '/' + chain + '/' + filename
+        xmldoc.saveFile(file_path)
         p.xpathFreeContext()
         xmldoc.freeDoc()
 
-
         return True
-
index 3a0bb39..16d1008 100644 (file)
@@ -38,22 +38,29 @@ class List(Command):
         p.xpathFreeContext()
         xmldoc.freeDoc()
 
-        return {'name':ext_name, 'arguments':'argument_str'}
+        return {'name':ext_name, 'arguments':argument_str}
+
+    def get_rule_list(self, chain_dir_path):
+        broken_semantics = os.walk(chain_dir_path)
+        rule_numbers = {}
 
-    def call(self, command_options, match_options, target_options):
-        chain = command_options.args[0]
-        chain_dir = sfatables_config + "/" + chain
-        rule_list = []
-        broken_semantics = os.walk(chain_dir)
         for (root, dirs, files) in broken_semantics:
             for file in files:
                 if (file.startswith('sfatables')):
                     (magic,number,type) = file.split('-')
-                    rule_list.append(int(number))
+                    rule_numbers[int(number)]=1
 
+        rule_list = rule_numbers.keys()
         rule_list.sort()
+        return rule_list
+
+    def call(self, command_options, match_options, target_options):
+        chain = command_options.args[0]
+        chain_dir = sfatables_config + "/" + chain
+
+        rule_list = self.get_rule_list(chain_dir)
 
-        pretty = Pretty(['Rule','Match','Target','Arguments'])
+        pretty = Pretty(['Rule','Match','Arguments','Target','Arguments'])
 
         for number in rule_list:
             match_file = "sfatables-%d-%s"%(number,'match')
@@ -65,7 +72,7 @@ class List(Command):
             match_info = self.get_info (match_path)
             target_info = self.get_info (target_path)
 
-            pretty.push_row(["%d"%number,  match_info['name'], match_info['arguments'], target_info['arguments']])
+            pretty.push_row(["%d"%number,  match_info['name'], match_info['arguments'], target_info['name'], target_info['arguments']])
         
         
         pretty.pprint()
index 9a896ee..9498aac 100644 (file)
@@ -25,8 +25,6 @@ class Pretty:
             cur_line = ""
             num = 0
 
-            import pdb
-            pdb.set_trace()
             for r in rule:
                 cur_line = cur_line + "%s "%r
                 if (self.column_width[num] > len(r)):