git://git.onelab.eu
/
sfa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
(no commit message)
[sfa.git]
/
sfatables
/
commands
/
Add.py
diff --git
a/sfatables/commands/Add.py
b/sfatables/commands/Add.py
index
e0c190f
..
e7657ff
100644
(file)
--- a/
sfatables/commands/Add.py
+++ b/
sfatables/commands/Add.py
@@
-4,12
+4,11
@@
from sfatables.command import Command
from sfatables.globals import *
class Add(Command):
from sfatables.globals import *
class Add(Command):
- options = [('-A','--add')]
- help = 'Add a rule to a chain'
- matches = True
- targets = True
-
def __init__(self):
def __init__(self):
+ self.options = [('-A','--add')]
+ self.help = 'Add a rule to a chain'
+ self.matches = True
+ self.targets = True
return
def getnextfilename(self,type,chain):
return
def getnextfilename(self,type,chain):
@@
-27,21
+26,25
@@
class Add(Command):
return "sfatables-%d-%s"%(last_rule_number+1,type)
def call_gen(self, chain, type, dir, options):
return "sfatables-%d-%s"%(last_rule_number+1,type)
def call_gen(self, chain, type, dir, options):
- filename =
dir + "/"+options.name+".xml"
+ filename =
os.path.join(dir, options.name+".xml")
xmldoc = libxml2.parseFile(filename)
p = xmldoc.xpathNewContext()
supplied_arguments = options.arguments
xmldoc = libxml2.parseFile(filename)
p = xmldoc.xpathNewContext()
supplied_arguments = options.arguments
- element = options.element
+ if (hasattr(options,'element') and options.element):
+ element = options.element
+ else:
+ element='*'
+
for option in supplied_arguments:
option_name = option['name']
option_value = getattr(options,option_name)
for option in supplied_arguments:
option_name = option['name']
option_value = getattr(options,option_name)
- if (hasattr(options,option_name)):
- context = p.xpathEval("//rule[@element='%s' or @element='*']/argument[name='%s']"%
element, option_name
)
+ if (hasattr(options,option_name)
and getattr(options,option_name)
):
+ context = p.xpathEval("//rule[@element='%s' or @element='*']/argument[name='%s']"%
(element, option_name)
)
if (not context):
if (not context):
- raise Exception('Unknown option %s for match %s
'%(option,option['name']
))
+ raise Exception('Unknown option %s for match %s
and element %s'%(option,option['name'], element
))
else:
# Add the value of option
valueNode = libxml2.newNode('value')
else:
# Add the value of option
valueNode = libxml2.newNode('value')
@@
-49,7
+52,9
@@
class Add(Command):
context[0].addChild(valueNode)
filename = self.getnextfilename(type,chain)
context[0].addChild(valueNode)
filename = self.getnextfilename(type,chain)
- file_path = sfatables_config + '/' + chain + '/' + filename
+ file_path = os.path.join(sfatables_config, chain, filename)
+ if not os.path.isdir(os.path.dirname(file_path)):
+ os.makedirs(os.path.dirname(file_path))
xmldoc.saveFile(file_path)
p.xpathFreeContext()
xmldoc.freeDoc()
xmldoc.saveFile(file_path)
p.xpathFreeContext()
xmldoc.freeDoc()