source: sasview/src/sas/sascalc/dataloader/readers/associations.py @ 5582b078

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 5582b078 was 574adc7, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

convert sascalc to python 2/3 syntax

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"""
2Module to associate default readers to file extensions.
3The module reads an xml file to get the readers for each file extension.
4The readers are tried in order they appear when reading a file.
5"""
6############################################################################
7#This software was developed by the University of Tennessee as part of the
8#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
9#project funded by the US National Science Foundation.
10#If you use DANSE applications to do scientific research that leads to
11#publication, we ask that you acknowledge the use of the software with the
12#following sentence:
13#This work benefited from DANSE software developed under NSF award DMR-0520547.
14#copyright 2009, University of Tennessee
15#############################################################################
16import sys
17import logging
18
19logger = logging.getLogger(__name__)
20
21FILE_ASSOCIATIONS = {
22    ".xml": "cansas_reader",
23    ".ses": "sesans_reader",
24    ".h5": "cansas_reader_HDF5",
25    ".txt": "ascii_reader",
26    ".dat": "red2d_reader",
27    ".abs": "abs_reader",
28    ".sans": "danse_reader",
29    ".pdh": "anton_paar_saxs_reader"
30}
31
32
33def read_associations(loader, settings=FILE_ASSOCIATIONS):
34    """
35    Read the specified settings file to associate
36    default readers to file extension.
37
38    :param loader: Loader object
39    :param settings: path to the json settings file [string]
40    """
41    # For each FileType entry, get the associated reader and extension
42    for ext, reader in settings.items():
43        if reader is not None and ext is not None:
44            # Associate the extension with a particular reader
45            # TODO: Modify the Register code to be case-insensitive
46            # FIXME: Remove exec statements
47            # and remove the extra line below.
48            try:
49                exec("from . import %s" % reader)
50                exec("loader.associate_file_type('%s', %s)"
51                     % (ext.lower(), reader))
52                exec("loader.associate_file_type('%s', %s)"
53                     % (ext.upper(), reader))
54            except:
55                msg = "read_associations: skipping association"
56                msg += " for %s\n  %s" % (ext.lower(), sys.exc_value)
57                logger.error(msg)
Note: See TracBrowser for help on using the repository browser.