Exemple #1
0
def parseConfigXML(fn):
      
    d = {}
    
    f = futil.openFile(fn,'r')
    mg.logger.debug("Config file %s " % fn)
    if f is None : 
        mg.logger.error("Config file %s NOT FOUND !!!" % fn)
        return None
    try: 
        tree = ET.parse(f)
        if tree == '' : 
            mg.logger.error("Empty Config File")
            return d
    
        rn = tree.getroot()
        if ST.upper(rn.tag) != 'RYDINFAP' :
            mg.logger.error("Did not find root element: 'RYDINFAP' ")
            return d 
        
        n =  tree.getiterator('APP_GLOB')
        if len(n) > 0 : d = _parseGlob(n)
        else          :  mg.logger.error("Did not find element: 'APP_GLOB' ")
        

        n =  tree.getiterator('DATA_SOURCE')
        if len(n) > 0 : d.update(_parseDS(n))
        else          :  mg.logger.error("Did not find element: 'DATA_SOURCE' ")
        
    except ET.ParseError: 
            mg.logger.error("==EXCEP %s %s "  % (sys.exc_type, sys.exc_value))
           

    finally:   return d
Exemple #2
0
 def parseAll(self):
     tbls = []
     gb   = []        
     s = fu.openFile(self.fn,'r')
     if s is None : 
         self.log.error("Could not open file %s" % self.fn)
         return gb
     
     tree = ET.parse(s)
     root = tree.getroot()
     d = xu.xml_to_dict(root)
     
     if d.has_key('PROC_GRP') is not True or len(d) != 1:
         self.log.error("Missing root Element %s" % 'PROC_GRP')
         return gb
     
     if type(d['PROC_GRP']) == type(str( )) : 
         self.log.error("Empty XML")
         return gb
     
     self.log.info("Start parsing file %s " % self.fn)
     self.log.debug("type d['PROC_GRP].values Need to be LIST = " , type(d.values()))
     
     for grp in  d.values()[0]:
         gb = self.parseGroup(grp)      
         tbls.append(gb)  
         
     return tbls     
Exemple #3
0
 def writeXmlFile(self,grpbl):
     f = fu.openFile(self.fn, 'w')
     if f is None : 
         self.log.error("Could not create file %s " % self.fn)
         return -1
     rc = 0 
     root = self._build2XML(grpbl)
     try :
         ET.ElementTree(root).write(self.fn)
     except:
         self.log.error("ENV var not set %s %s\n" % (sys.exc_type,sys.exc_value))
         rc = 1
         
     finally:
         fu.closeFile(f)
         return rc
Exemple #4
0
def getAggColList(args):
    fnp = os.path.join(args['gp_nz_home'],'config', '%s_validation.lst' % args['gp_db_sche']) 
    tb_pk = []
    f = fu.openFile(fnp,'r') 
    if f is None : 
        log.error('Cannot open validation file %s ' % fnp)
        return tb_pk

    log.info('read validation file %s ' % fnp)  
    rd = csv.reader(f)

    for l in rd:
       log.debug('tb,pk',l)
       if len(l) != 2 :
           log.error("Error ignoring ", l ," len needs to be 2")
           continue
       tb_pk.append(l)
 
    f.close()
    return tb_pk
Exemple #5
0
def parseSched(fn):
    f = fu.openFile(fn,'r')    
    if f is None : return (1, [], [])
    
    try:
        tree = ET.parse(f)
        # Empty tree
        if tree == '' : return (2, [], [])
            
        rt = tree.getroot()
        
        # 1- Check TREE root
        if ST.upper(rt.tag) != 'IS_SCHED' : return (3, [],[])
        
        for elem in tree.getiterator():
            for e in elem:
                if ST.lower(e.tag) == 'folder' :
                    _parseFolder(e.get('name'), e.getchildren())
    
    except ET.ParseError:
            print ("Error %s \t %s " %  (sys.exc_type, sys.exc_value))
            return (4, [],[])

    finally : return 0, sched, unsched
Exemple #6
0
def readConfigFile(config_file):
    f = fu.openFile(config_file, 'r')
    if f is not None : return f.read().splitlines() 
    else             : return None