Changeset 5dfdfa7 in sasview


Ignore:
Timestamp:
Feb 16, 2015 12:27:41 PM (8 years ago)
Author:
krzywon
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
4ec242e, b45cde3, 66f21cd
Parents:
8836849
Message:

Changed the default dataloader association file from xml to json to
allow easier integration into a stand-alone data loader package with no
external dependencies.

Location:
src/sas/dataloader/readers
Files:
1 added
1 deleted
1 edited

Legend:

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

    rfd5ac0d r5dfdfa7  
    1717import sys 
    1818import logging 
    19 from lxml import etree 
    20 # Py2exe compatibility: import _elementpath to ensure that py2exe finds it 
    21 from lxml import _elementpath 
     19import json 
    2220 
    23 ## Format version for the XML settings file 
    24 VERSION = 'sasloader/1.0' 
     21FILE_NAME = 'defaults.json' 
    2522 
    26  
    27 def read_associations(loader, settings='defaults.xml'): 
     23def read_associations(loader, settings=FILE_NAME): 
    2824    """ 
    2925    Read the specified settings file to associate 
     
    3127     
    3228    :param loader: Loader object 
    33     :param settings: path to the XML settings file [string] 
     29    :param settings: path to the json settings file [string] 
    3430    """ 
    3531    reader_dir = os.path.dirname(__file__) 
     
    4743        path = "./%s" % settings 
    4844    if os.path.isfile(path): 
    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() 
     45        with open(path) as fh: 
     46            json_tree = json.load(fh) 
    5447         
    5548        # Read in the file extension associations 
    56         entry_list = root.xpath('/ns:SasLoader/ns:FileType', 
    57                                  namespaces={'ns': VERSION}) 
     49        entry_list = json_tree['SasLoader']['FileType'] 
    5850 
    5951        # For each FileType entry, get the associated reader and extension 
    6052        for entry in entry_list: 
    61             reader = entry.get('reader') 
    62             ext = entry.get('extension') 
     53            reader = entry['-reader'] 
     54            ext = entry['-extension'] 
    6355             
    6456            if reader is not None and ext is not None: 
Note: See TracChangeset for help on using the changeset viewer.