python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfatables / commands / Delete.py
1 import os, time
2 from sfatables.globals import sfatables_config
3 from sfatables.command import Command
4
5 class Delete(Command):
6     options = [('-D','--delete')]
7     help = 'Delete a rule from a chain'
8     key='delete_rule'
9     matches = False
10     targets = False
11
12     def __init__(self):
13         return
14
15     def call(self, command_options, match_options, target_options):
16
17         if (len(command_options.args)<2):
18             print("Please specify the chain and the rule number to delete, e.g. sfatables -D INCOMING 1.")
19             return
20
21         chain = command_options.args[0]
22
23
24         rule_number = command_options.args[1]
25         chain_dir = sfatables_config + "/" + chain
26
27         match_path = chain_dir + "/" + "sfatables-%s-match"%rule_number
28         target_path = chain_dir + "/" + "sfatables-%s-target"%rule_number
29
30         os.unlink(match_path)
31         os.unlink(target_path)
32