From f5194b0cf1858313770d6796411fec30190b5522 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Wed, 12 Aug 2009 18:07:59 +0000 Subject: [PATCH] --- sfatables/__init__.py | 0 sfatables/commands/Add.py | 9 +++++---- sfatables/commands/Delete.py | 9 +++++---- sfatables/commands/List.py | 9 +++++---- sfatables/commands/SetDefault.py | 9 +++++---- sfatables/sfatables.py | 11 +++++++---- 6 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 sfatables/__init__.py diff --git a/sfatables/__init__.py b/sfatables/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sfatables/commands/Add.py b/sfatables/commands/Add.py index 063caab9..79bb2d97 100644 --- a/sfatables/commands/Add.py +++ b/sfatables/commands/Add.py @@ -1,9 +1,10 @@ import os, time +from sfa.sfatables.command import Add -class Command: - options = [] - help = '' - key='' +class Add(Command): + options = [('-A','--add')] + help = 'Add a rule to a chain' + key='add_rule' matches = False targets = False diff --git a/sfatables/commands/Delete.py b/sfatables/commands/Delete.py index 063caab9..e59da62c 100644 --- a/sfatables/commands/Delete.py +++ b/sfatables/commands/Delete.py @@ -1,9 +1,10 @@ import os, time +from sfa.sfatables.command import Add -class Command: - options = [] - help = '' - key='' +class Add(Command): + options = [('-D','--delete')] + help = 'Delete a rule from a chain' + key='delete_rule' matches = False targets = False diff --git a/sfatables/commands/List.py b/sfatables/commands/List.py index 063caab9..38f5ebc1 100644 --- a/sfatables/commands/List.py +++ b/sfatables/commands/List.py @@ -1,9 +1,10 @@ import os, time +from sfa.sfatables.command import Add -class Command: - options = [] - help = '' - key='' +class List(Command): + options = [('-L','--list')] + help = 'List a chain' + key='list_rule' matches = False targets = False diff --git a/sfatables/commands/SetDefault.py b/sfatables/commands/SetDefault.py index 063caab9..8fac405f 100644 --- a/sfatables/commands/SetDefault.py +++ b/sfatables/commands/SetDefault.py @@ -1,9 +1,10 @@ import os, time +from sfa.sfatables.command import Add -class Command: - options = [] - help = '' - key='' +class SetDefault(Command): + options = [('-P','--default')] + help = 'Set the default rule for a chain' + key='add_rule' matches = False targets = False diff --git a/sfatables/sfatables.py b/sfatables/sfatables.py index dbfa7126..d9dbcb54 100755 --- a/sfatables/sfatables.py +++ b/sfatables/sfatables.py @@ -14,7 +14,9 @@ from optparse import OptionParser def load_extensions(module): command_dict={} - commands = __import__(module,fromlist=[".".join(module.split('.')[:-1])]) + module_path = ".".join(module.split('.')[:-1]) + pdb.set_trace() + commands = __import__(module,fromlist=[module_path]) for command_name in commands.all: command_module = getattr(commands, command_name) @@ -40,9 +42,10 @@ def main(): command_parser = create_parser(command_dict) (options, args) = command_parser.parse_args() - if (len(options.keys() != 1): + if (len(options.keys()) != 1): raise Exception("sfatables takes one command at a time.\n") + pdb.set_trace() selected_command = command_dict[options.keys()[0]] match_options = None @@ -51,12 +54,12 @@ def main(): if (selected_command.matches): match_dict = load_extensions("sfa.sfatables.matches") match_parser = create_parser(match_dict) - (options, args) = match_parser.parse_args(args[2:]) # Change to next location of -- + (options, args) = match_parser.parse_args(args[2:]) if (selected_command.targets): match_dict = load_extensions("sfa.sfatables.targets") target_parser = create_parser(match_dict) - (options, args) = target_parser.parse_args(args[5:]) # Change to next location of -- + (options, args) = target_parser.parse_args(args[5:]) command(options, match_options, target_options) -- 2.43.0