X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fsfatables;h=6bf4408b67ccfad1f9d7fd6095297ca816073f90;hb=4a9e6751f9f396f463932133b9d62fc925a99ef6;hp=379b749c1b3e75683580a3f88186bb3d928bdb37;hpb=7a3131ef03d2a4b30cce63cb6f671a4e35da836d;p=sfa.git diff --git a/sfatables/sfatables b/sfatables/sfatables index 379b749c..6bf4408b 100755 --- a/sfatables/sfatables +++ b/sfatables/sfatables @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # This file parses an sfatables command and generates XML files that parameterize # matches and targets. Each such XML file defines a rule. Rules are dropped in directories @@ -8,13 +8,12 @@ import sys import os -import pdb -import libxml2 +import glob from optparse import OptionParser -from sfatables import commands, matches, targets +from sfatables import commands from sfatables.xmlextension import Xmlextension -from sfatables.globals import * +from sfatables.globals import target_dir, match_dir def load_commands(module, list): command_dict={} @@ -26,11 +25,14 @@ def load_commands(module, list): return command_dict -def load_xml_extensions(module, dir, list): +def load_xml_extensions(module, ext_dir): ext_dict={} - for ext_name in list: - module = Xmlextension(dir, ext_name) + exts = glob.glob(ext_dir + os.path.sep + "*") + for ext in exts: + module = Xmlextension(ext) + # get the filename and get rid of the ".xml" extension + ext_name = os.path.extsep.join(os.path.splitext(os.path.basename(ext))[:-1]) ext_dict[ext_name]=module return ext_dict @@ -87,10 +89,11 @@ def main(): if (command.matches): if (len(pargs)<2): raise Exception("Must specify match for this command") - match_dict = load_xml_extensions("sfatables.matches",match_dir, matches.all) + match_dict = load_xml_extensions("sfatables.matches",match_dir) match_parser = create_parser_xml_ext(match_dict) matches_str = ",".join(match_dict.keys()) match_parser.add_option('-m','--match',dest='name',help='Match name (one of %s)'%matches_str, metavar = 'MATCH') + match_parser.add_option('-n','--negate',dest='negate',help='Negate result',action='store_true') (match_options, args) = match_parser.parse_args(pargs[1]) try: name = match_options.name @@ -108,15 +111,16 @@ def main(): if (command.targets): if (len(pargs)<3): raise Exception("Must specify a target for this command") - target_dict = load_xml_extensions("sfatables.targets",target_dir,targets.all) + target_dict = load_xml_extensions("sfatables.targets",target_dir) target_parser = create_parser_xml_ext(target_dict) targets_str = ",".join(target_dict.keys()) - target_parser.add_option('-j','--jump',dest='name',help='Target name (one of %s)'%targets, metavar = 'TARGET') + target_parser.add_option('-j','--jump',dest='name',help='Target name (one of %s)'%targets_str, metavar = 'TARGET') + target_parser.add_option('-e','--element',dest='element',help='Element name', metavar = 'ELEMENT') (target_options, args) = target_parser.parse_args(pargs[2]) try: name = target_options.name except Exception: - print "Must specify target name with -m" + print "Must specify target name with -j" if (target_dict.has_key(name)): setattr(target_options, 'arguments', target_dict[name].arguments)