Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/dataloader/readers/associations.py

    r5dfdfa7 rfd5ac0d  
    1717import sys 
    1818import logging 
    19 import json 
     19from lxml import etree 
     20# Py2exe compatibility: import _elementpath to ensure that py2exe finds it 
     21from lxml import _elementpath 
    2022 
    21 FILE_NAME = 'defaults.json' 
     23## Format version for the XML settings file 
     24VERSION = 'sasloader/1.0' 
    2225 
    23 def read_associations(loader, settings=FILE_NAME): 
     26 
     27def read_associations(loader, settings='defaults.xml'): 
    2428    """ 
    2529    Read the specified settings file to associate 
     
    2731     
    2832    :param loader: Loader object 
    29     :param settings: path to the json settings file [string] 
     33    :param settings: path to the XML settings file [string] 
    3034    """ 
    3135    reader_dir = os.path.dirname(__file__) 
     
    4347        path = "./%s" % settings 
    4448    if os.path.isfile(path): 
    45         with open(path) as fh: 
    46             json_tree = json.load(fh) 
     49        tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 
     50         
     51        # Check the format version number 
     52        # Specifying the namespace will take care of the file format version 
     53        root = tree.getroot() 
    4754         
    4855        # Read in the file extension associations 
    49         entry_list = json_tree['SasLoader']['FileType'] 
     56        entry_list = root.xpath('/ns:SasLoader/ns:FileType', 
     57                                 namespaces={'ns': VERSION}) 
    5058 
    5159        # For each FileType entry, get the associated reader and extension 
    5260        for entry in entry_list: 
    53             reader = entry['-reader'] 
    54             ext = entry['-extension'] 
     61            reader = entry.get('reader') 
     62            ext = entry.get('extension') 
    5563             
    5664            if reader is not None and ext is not None: 
Note: See TracChangeset for help on using the changeset viewer.