Changes in src/sas/dataloader/readers/associations.py [fd5ac0d:5dfdfa7] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/dataloader/readers/associations.py
rfd5ac0d r5dfdfa7 17 17 import sys 18 18 import logging 19 from lxml import etree 20 # Py2exe compatibility: import _elementpath to ensure that py2exe finds it 21 from lxml import _elementpath 19 import json 22 20 23 ## Format version for the XML settings file 24 VERSION = 'sasloader/1.0' 21 FILE_NAME = 'defaults.json' 25 22 26 27 def read_associations(loader, settings='defaults.xml'): 23 def read_associations(loader, settings=FILE_NAME): 28 24 """ 29 25 Read the specified settings file to associate … … 31 27 32 28 :param loader: Loader object 33 :param settings: path to the XMLsettings file [string]29 :param settings: path to the json settings file [string] 34 30 """ 35 31 reader_dir = os.path.dirname(__file__) … … 47 43 path = "./%s" % settings 48 44 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) 54 47 55 48 # 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'] 58 50 59 51 # For each FileType entry, get the associated reader and extension 60 52 for entry in entry_list: 61 reader = entry .get('reader')62 ext = entry .get('extension')53 reader = entry['-reader'] 54 ext = entry['-extension'] 63 55 64 56 if reader is not None and ext is not None:
Note: See TracChangeset
for help on using the changeset viewer.