Changeset 7a5d066 in sasview


Ignore:
Timestamp:
Apr 20, 2017 3:00:56 PM (7 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
5d8f9b3
Parents:
080d88e
git-author:
Jeff Krzywon <krzywon@…> (04/20/17 15:00:56)
git-committer:
krzywon <krzywon@…> (04/20/17 15:00:56)
Message:

Replace defaults.json file with constant to eliminate json dependency

Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • sasview/setup_exe.py

    rf36e01f r7a5d066  
    227227# Copy the settings file for the sas.dataloader file extension associations 
    228228import sas.sascalc.dataloader.readers 
    229 f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') 
     229f = os.path.join(sas.sascalc.dataloader.readers.get_data_path()) 
    230230if os.path.isfile(f): 
    231231    data_files.append(('.', [f])) 
     
    241241if os.path.isfile(f): 
    242242    data_files.append(('.', [f])) 
    243  
    244 #f = 'default_categories.json' 
    245 #if os.path.isfile(f): 
    246 #    data_files.append(('.', [f])) 
    247243 
    248244# numerical libraries 
  • sasview/setup_mac.py

    rb854587 r7a5d066  
    4949 
    5050#CANSAxml reader data files 
    51 RESOURCES_FILES.append(os.path.join(sas.sascalc.dataloader.readers.get_data_path(),'defaults.json')) 
     51RESOURCES_FILES.append(os.path.join(sas.sascalc.dataloader.readers.get_data_path())) 
    5252 
    5353DATA_FILES.append('logging.ini') 
  • setup.py

    rb854587 r7a5d066  
    221221package_dir["sas.sascalc.dataloader"] = os.path.join( 
    222222    "src", "sas", "sascalc", "dataloader") 
    223 package_data["sas.sascalc.dataloader.readers"] = [ 
    224     'defaults.json', 'schema/*.xsd'] 
     223package_data["sas.sascalc.dataloader.readers"] = ['schema/*.xsd'] 
    225224packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers", 
    226225                 "sas.sascalc.dataloader.readers.schema"]) 
  • src/sas/sascalc/dataloader/readers/__init__.py

    r959eb01 r7a5d066  
    1 # Backward compatibility with the previous implementation of the default readers 
    2 from associations import register_readers 
     1# Method to associate extensions to default readers 
     2from associations import read_associations 
    33 
    4 # Method to associate extensions to default readers  
    5 from associations import read_associations 
    64 
    75# Method to return the location of the XML settings file 
  • src/sas/sascalc/dataloader/readers/associations.py

    r959eb01 r7a5d066  
    1414#copyright 2009, University of Tennessee 
    1515############################################################################# 
    16 import os 
    1716import sys 
    1817import logging 
    19 import json 
    2018 
    2119logger = logging.getLogger(__name__) 
    2220 
    23 FILE_NAME = 'defaults.json' 
     21FILE_ASSOCIATIONS = { 
     22    ".xml": "cansas_reader", 
     23    ".ses": "sesans_reader", 
     24    ".h5": "cansas_reader_HDF5", 
     25    ".txt": "ascii_reader", 
     26    ".asc": "IgorReader", 
     27    ".dat": "red2d_reader", 
     28    ".abs": "abs_reader", 
     29    ".d1d": "hfir1d_reader", 
     30    ".sans": "danse_reader", 
     31    ".nxs": "nexus_reader", 
     32    ".pdh": "anton_paar_saxs_reader" 
     33} 
    2434 
    25 def read_associations(loader, settings=FILE_NAME): 
     35 
     36def read_associations(loader, settings=FILE_ASSOCIATIONS): 
    2637    """ 
    2738    Read the specified settings file to associate 
     
    3142    :param settings: path to the json settings file [string] 
    3243    """ 
    33     reader_dir = os.path.dirname(__file__) 
    34     path = os.path.join(reader_dir, settings) 
    35      
    36     # If we can't find the file in the installation 
    37     # directory, look into the execution directory. 
    38     if not os.path.isfile(path): 
    39         path = os.path.join(os.getcwd(), settings) 
    40     if not os.path.isfile(path): 
    41         path = os.path.join(sys.path[0], settings) 
    42     if not os.path.isfile(path): 
    43         path = settings 
    44     if not os.path.isfile(path): 
    45         path = "./%s" % settings 
    46     if os.path.isfile(path): 
    47         with open(path) as fh: 
    48             json_tree = json.load(fh) 
    49          
    50         # Read in the file extension associations 
    51         entry_list = json_tree['SasLoader']['FileType'] 
    52  
    53         # For each FileType entry, get the associated reader and extension 
    54         for entry in entry_list: 
    55             reader = entry['-reader'] 
    56             ext = entry['-extension'] 
    57              
    58             if reader is not None and ext is not None: 
    59                 # Associate the extension with a particular reader 
    60                 # TODO: Modify the Register code to be case-insensitive 
    61                 # and remove the extra line below. 
    62                 try: 
    63                     exec "import %s" % reader 
    64                     exec "loader.associate_file_type('%s', %s)" % (ext.lower(), 
    65                                                                     reader) 
    66                     exec "loader.associate_file_type('%s', %s)" % (ext.upper(), 
    67                                                                     reader) 
    68                 except: 
    69                     msg = "read_associations: skipping association" 
    70                     msg += " for %s\n  %s" % (ext.lower(), sys.exc_value) 
    71                     logger.error(msg) 
    72     else: 
    73         print "Could not find reader association settings\n  %s [%s]" % (__file__, os.getcwd()) 
    74           
    75           
    76 def register_readers(registry_function): 
    77     """ 
    78     Function called by the registry/loader object to register 
    79     all default readers using a call back function. 
    80      
    81     :WARNING: this method is now obsolete 
    82  
    83     :param registry_function: function to be called to register each reader 
    84     """ 
    85     logger.info("register_readers is now obsolete: use read_associations()") 
    86     import abs_reader 
    87     import ascii_reader 
    88     import cansas_reader 
    89     import danse_reader 
    90     import hfir1d_reader 
    91     import IgorReader 
    92     import red2d_reader 
    93     #import tiff_reader 
    94     import nexus_reader 
    95     import sesans_reader 
    96     import cansas_reader_HDF5 
    97     import anton_paar_saxs_reader 
    98     registry_function(sesans_reader) 
    99     registry_function(abs_reader) 
    100     registry_function(ascii_reader) 
    101     registry_function(cansas_reader) 
    102     registry_function(danse_reader) 
    103     registry_function(hfir1d_reader) 
    104     registry_function(IgorReader) 
    105     registry_function(red2d_reader) 
    106     #registry_function(tiff_reader) 
    107     registry_function(nexus_reader) 
    108     registry_function(cansas_reader_HDF5) 
    109     registry_function(anton_paar_saxs_reader) 
    110     return True 
     44    # For each FileType entry, get the associated reader and extension 
     45    for ext, reader in settings.iteritems(): 
     46        if reader is not None and ext is not None: 
     47            # Associate the extension with a particular reader 
     48            # TODO: Modify the Register code to be case-insensitive 
     49            # FIXME: Remove exec statements 
     50            # and remove the extra line below. 
     51            try: 
     52                exec "import %s" % reader 
     53                exec "loader.associate_file_type('%s', %s)" % (ext.lower(), 
     54                                                                reader) 
     55                exec "loader.associate_file_type('%s', %s)" % (ext.upper(), 
     56                                                                reader) 
     57            except: 
     58                msg = "read_associations: skipping association" 
     59                msg += " for %s\n  %s" % (ext.lower(), sys.exc_value) 
     60                logger.error(msg) 
Note: See TracChangeset for help on using the changeset viewer.