From: Sapan Bhatia Date: Wed, 2 Sep 2009 22:27:06 +0000 (+0000) Subject: Ok, Add and List are working generically. X-Git-Tag: sfa-0.9-1~32 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=f21fb08570a1cf9b0c663e364b332eeebb669c59;p=sfa.git Ok, Add and List are working generically. --- diff --git a/sfatables/commands/Add.py b/sfatables/commands/Add.py index b62ad6c4..5064ee69 100644 --- a/sfatables/commands/Add.py +++ b/sfatables/commands/Add.py @@ -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 - diff --git a/sfatables/commands/List.py b/sfatables/commands/List.py index 3a0bb396..16d10084 100644 --- a/sfatables/commands/List.py +++ b/sfatables/commands/List.py @@ -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() diff --git a/sfatables/pretty.py b/sfatables/pretty.py index 9a896ee3..9498aac1 100644 --- a/sfatables/pretty.py +++ b/sfatables/pretty.py @@ -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)):