- make matches and targets loaded w/o making hem python packages
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Fri, 2 Oct 2009 14:00:54 +0000 (14:00 +0000)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Fri, 2 Oct 2009 14:00:54 +0000 (14:00 +0000)
- rename example files with .example postfix

12 files changed:
setup.py
sfa.spec
sfatables/globals.py
sfatables/matches/__init__.py [deleted file]
sfatables/matches/example_sfa_input.xml.example [moved from sfatables/matches/example_sfa_input.xml with 100% similarity]
sfatables/matches/test.xml.example [moved from sfatables/matches/test.xml with 100% similarity]
sfatables/runtime.py
sfatables/sfatables
sfatables/targets/RESTRICT_TO_NODE_GROUP.xml.example [moved from sfatables/targets/RESTRICT_TO_NODE_GROUP.xml with 98% similarity]
sfatables/targets/__init__.py [deleted file]
sfatables/targets/example_vini_rspec.xml.example [moved from sfatables/targets/example_vini_rspec.xml with 100% similarity]
sfatables/xmlextension.py

index e36bada..36487dd 100755 (executable)
--- 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: 
index 6131d19..7f83bed 100644 (file)
--- 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
index 676722b..fe6788d 100644 (file)
@@ -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 (file)
index 2329359..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-all="""
-hrn
-slice-whitelist
-all
-""".split()
index 9e9b49a..0a73482 100644 (file)
@@ -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 *
index 2f20f3f..0693020 100755 (executable)
@@ -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:
@@ -16,4 +16,4 @@
         </argument>
     </rule>
     <processor filename="restrict_to_nodes.xsl"/>
-</match>
+</target>
diff --git a/sfatables/targets/__init__.py b/sfatables/targets/__init__.py
deleted file mode 100644 (file)
index 1dcc2d1..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-all="""
-RESTRICT_SLICE_DOMAIN
-ACCEPT
-REJECT
-RESTRICT_SLICE_PROP
-""".split()
index 4fc1ab5..813cd6d 100644 (file)
@@ -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()