X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fcommands%2FAdd.py;h=f5193eb6d8a7fe5ca558c2521b710baa7358a9f3;hb=6c41d17ff2f98c362ad1db112d22bede960d8202;hp=36b22c3c7a879d434355b07a2be1c882bd385287;hpb=7a3131ef03d2a4b30cce63cb6f671a4e35da836d;p=sfa.git diff --git a/sfatables/commands/Add.py b/sfatables/commands/Add.py index 36b22c3c..f5193eb6 100644 --- a/sfatables/commands/Add.py +++ b/sfatables/commands/Add.py @@ -14,11 +14,11 @@ class Add(Command): def getnextfilename(self,type,chain): dir = sfatables_config + "/"+chain; - last_rule_number = 1 + last_rule_number = 0 for (root, dirs, files) in os.walk(dir): for file in files: - if (file.startswith('sfatables-')): + if (file.startswith('sfatables-') and file.endswith(type)): number_str = file.split('-')[1] number = int(number_str) if (number>last_rule_number): @@ -33,14 +33,19 @@ class Add(Command): p = xmldoc.xpathNewContext() supplied_arguments = options.arguments + 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) if (hasattr(options,option_name)): - context = p.xpathEval("//rule/argument[name='%s']"%option_name) + context = p.xpathEval("//rule[@element='%s' or @element='*']/argument[name='%s']"%(element, option_name)) 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')