From e57b7150dee76d42fc15f9477a3045e5171c8878 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Fri, 2 Oct 2009 14:00:54 +0000 Subject: [PATCH] - make matches and targets loaded w/o making hem python packages - rename example files with .example postfix --- setup.py | 13 ++++++++----- sfa.spec | 5 ++--- sfatables/globals.py | 6 ++++-- sfatables/matches/__init__.py | 5 ----- ...nput.xml => example_sfa_input.xml.example} | 0 .../matches/{test.xml => test.xml.example} | 0 sfatables/runtime.py | 1 - sfatables/sfatables | 19 ++++++++++++------- ...xml => RESTRICT_TO_NODE_GROUP.xml.example} | 2 +- sfatables/targets/__init__.py | 6 ------ ...pec.xml => example_vini_rspec.xml.example} | 0 sfatables/xmlextension.py | 5 ++--- 12 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 sfatables/matches/__init__.py rename sfatables/matches/{example_sfa_input.xml => example_sfa_input.xml.example} (100%) rename sfatables/matches/{test.xml => test.xml.example} (100%) rename sfatables/targets/{RESTRICT_TO_NODE_GROUP.xml => RESTRICT_TO_NODE_GROUP.xml.example} (98%) delete mode 100644 sfatables/targets/__init__.py rename sfatables/targets/{example_vini_rspec.xml => example_vini_rspec.xml.example} (100%) diff --git a/setup.py b/setup.py index e36bada8..36487dd0 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,6 @@ bins = [ 'config/sfa-config-tty', 'sfa/client/genidump.py', 'sfatables/sfatables', ] -remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ] package_dirs = [ 'sfa', 'sfa/client', @@ -38,12 +37,13 @@ package_dirs = [ 'sfa', 'sfatables/processors', ] + data_files = [('/etc/sfa/', [ 'config/aggregates.xml', 'config/registries.xml', 'config/sfa_config', 'config/sfi_config']), - ('/etc/sfatables/matches/', glob('sfatables/matches/*')), - ('/etc/sfatables/targets/', glob('sfatables/targets/*')), + ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')), + ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')), ('/etc/init.d/', ['sfa/init.d/sfa'])] # add sfatables processors as data_files @@ -59,8 +59,10 @@ initscripts = [ '/etc/init.d/sfa' ] if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']: python_path = sys.path - site_packages_path = [ path + os.sep + 'sfa' for path in python_path if path.endswith('site-packages')] - remove_dirs = ['/etc/sfa/'] + site_packages_path + site_packages_path = [ os.path.join(p,'sfa') for p in python_path if p.endswith('site-packages')] + site_packages_path += [ os.path.join(p,'sfatables') for p in python_path if p.endswith('site-packages')] + remove_dirs = ['/etc/sfa/', '/etc/sfatables'] + site_packages_path + remove_bins = [ '/usr/bin/' + os.path.basename(bin) for bin in bins ] remove_files = remove_bins + initscripts # remove files @@ -71,6 +73,7 @@ if sys.argv[1] in ['uninstall', 'remove', 'delete', 'clean']: print "success" except: print "failed" # remove directories + print remove_dirs for directory in remove_dirs: print "removing", directory, "...", try: diff --git a/sfa.spec b/sfa.spec index 6131d19e..7f83bed6 100644 --- a/sfa.spec +++ b/sfa.spec @@ -86,12 +86,11 @@ make install DESTDIR="$RPM_BUILD_ROOT" rm -rf $RPM_BUILD_ROOT %files +# sfa and sfatables depend each other. +/etc/sfatables/* %{python_sitelib}/* /usr/bin/keyconvert /var/www/html/wsdl/*.wsdl -# sfa and sfatables depend each other. -/etc/sfatables/* -%{python_sitelib}/sfatables/* %files plc diff --git a/sfatables/globals.py b/sfatables/globals.py index 676722b5..fe6788d7 100644 --- a/sfatables/globals.py +++ b/sfatables/globals.py @@ -1,3 +1,5 @@ +import os.path + sfatables_config = '/etc/sfatables' -match_dir = 'matches' -target_dir = 'targets' +match_dir = os.path.join(sfatables_config, "matches") +target_dir = os.path.join(sfatables_config, "targets") diff --git a/sfatables/matches/__init__.py b/sfatables/matches/__init__.py deleted file mode 100644 index 2329359f..00000000 --- a/sfatables/matches/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -all=""" -hrn -slice-whitelist -all -""".split() diff --git a/sfatables/matches/example_sfa_input.xml b/sfatables/matches/example_sfa_input.xml.example similarity index 100% rename from sfatables/matches/example_sfa_input.xml rename to sfatables/matches/example_sfa_input.xml.example diff --git a/sfatables/matches/test.xml b/sfatables/matches/test.xml.example similarity index 100% rename from sfatables/matches/test.xml rename to sfatables/matches/test.xml.example diff --git a/sfatables/runtime.py b/sfatables/runtime.py index 9e9b49aa..0a73482a 100644 --- a/sfatables/runtime.py +++ b/sfatables/runtime.py @@ -7,7 +7,6 @@ import libxml2 from optparse import OptionParser from sfatables import commands, matches, targets -from sfatables.xmlextension import Xmlextension from sfatables.globals import * from sfatables.commands.List import * from sfatables.xmlrule import * diff --git a/sfatables/sfatables b/sfatables/sfatables index 2f20f3f9..0693020d 100755 --- a/sfatables/sfatables +++ b/sfatables/sfatables @@ -9,10 +9,11 @@ import sys import os import pdb +import glob import libxml2 from optparse import OptionParser -from sfatables import commands, matches, targets +from sfatables import commands from sfatables.xmlextension import Xmlextension from sfatables.globals import * @@ -26,12 +27,16 @@ 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 + print "Loaded:", ext_name, ext return ext_dict @@ -87,7 +92,7 @@ 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') @@ -109,10 +114,10 @@ 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: diff --git a/sfatables/targets/RESTRICT_TO_NODE_GROUP.xml b/sfatables/targets/RESTRICT_TO_NODE_GROUP.xml.example similarity index 98% rename from sfatables/targets/RESTRICT_TO_NODE_GROUP.xml rename to sfatables/targets/RESTRICT_TO_NODE_GROUP.xml.example index bb4465ba..4922baff 100644 --- a/sfatables/targets/RESTRICT_TO_NODE_GROUP.xml +++ b/sfatables/targets/RESTRICT_TO_NODE_GROUP.xml.example @@ -16,4 +16,4 @@ - + diff --git a/sfatables/targets/__init__.py b/sfatables/targets/__init__.py deleted file mode 100644 index 1dcc2d1e..00000000 --- a/sfatables/targets/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -all=""" -RESTRICT_SLICE_DOMAIN -ACCEPT -REJECT -RESTRICT_SLICE_PROP -""".split() diff --git a/sfatables/targets/example_vini_rspec.xml b/sfatables/targets/example_vini_rspec.xml.example similarity index 100% rename from sfatables/targets/example_vini_rspec.xml rename to sfatables/targets/example_vini_rspec.xml.example diff --git a/sfatables/xmlextension.py b/sfatables/xmlextension.py index 4fc1ab58..813cd6d3 100644 --- a/sfatables/xmlextension.py +++ b/sfatables/xmlextension.py @@ -8,15 +8,14 @@ import libxml2 from sfatables.globals import * class Xmlextension: - def __init__(self, dir, component_name): + def __init__(self, file_path): self.context = "" self.processor = "" self.operand = "VALUE" self.arguments = [] self.terminal = 0 - filename = dir+"/"+component_name+".xml" - self.xmldoc = libxml2.parseFile(filename) + self.xmldoc = libxml2.parseFile(file_path) # TODO: Check xmldoc against a schema p = self.xmldoc.xpathNewContext() -- 2.43.0