from sfatables.globals import *
class Add(Command):
- options = [('-A','--add')]
- help = 'Add a rule to a chain'
- matches = True
- targets = True
-
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 "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()
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()