Пример #1
0
 def build_iRules(self, Files):
     iRules = []
     for f in Files:
         for iRule in self.config.get('iRules', []):
             if iRule['file'] == f or iRule['file'] == os.path.basename(f):
                 if f in [r['file'] for r in iRules]:
                     self.logger.debug(u"%s File is allready in iRules -------------> OLD" % f)
                     for _iRule in iRules:
                         if f == _iRule.get('file', False):
                             for rule in iRule.get('rules', []):
                                 _iRule['actions'][rule['action']] = _iRule['actions'].get(rule['action'], []) \
                                         + self.get_default_rule_data(rule, _iRule)
                 else:
                     self.logger.debug(u"%s File Doesn't Exists in iRules --------------> NEW" % f)
                     _iRule = {}
                     _iRule['file'] = f
                     _iRule['output'] = u''
                     _iRule['actions'] = {}
                     _iRule['exec_order'] = self.config.get('ExecOrder',['delete', 'append', 'clone', 'modify'])
                     _iRule['xfile'] = ElementTree.open_xfile(_iRule['file'])
                     _iRule['root'] = _iRule['xfile'].getroot_extend()
                     for rule in iRule.get('rules', []):
                         _iRule['actions'][rule['action']] = _iRule['actions'].get(rule['action'], []) \
                                 + self.get_default_rule_data(rule, _iRule)
                     if [ True for i in _iRule.get('actions', {}).values() if i]:
                         iRules.append(_iRule)
     return iRules       
Пример #2
0
#!/usr/bin/env python

from PyelementTree import ElementTree
import pdb
import sys, os
if len(sys.argv) != 3:
    print "USAGE - %s <filename> <xpath>" % os.path.basename(sys.argv[0])
    print "<xpath> must be given with single quates if xpath contain \"$\"'"
    sys.exit(3)
    
file_name = sys.argv[1]
xpath = sys.argv[2]

f = ElementTree.open_xfile(file_name)
root = f.getroot_extend()
print 'file_name:', file_name
print 'XML Encoding:', f.docinfo.encoding
print 'XML Version:',  f.docinfo.xml_version
print 'XML Header:',  f.docinfo.header
print 'XML DOCTYPE:\n%s' % '\n'.join(f.docinfo.doctype)
print 'xpath:', xpath
print 'xpath data:'
i = 0
for x in ElementTree.list_xpath(xpath):
    i+=1
    print i, ')' ,x

elements = root.xpath_query(xpath)
print 

for e in elements: