Пример #1
0
def setUserFileInBatchMode(new_user_file, current_user_file,
                           original_user_file, original_settings,
                           original_prop_man_settings):
    """
        Loads a specified user file. The file is loaded if
        new_user_file is different from  current_user_file. Else we just
        keep the user file loaded. If the new_user_file is empty then we default to
        original_user_file.
        @param new_user_file: The new user file. Note that this can be merely the filename (+ extension)
        @param current_user_file: The currently loaded user file
        @param original_user_file: The originally loaded user file. This is used as a default
        @param original_settings: The original reducer
        @param original_prop_man_settings: Original properties settings
    """
    user_file_to_set = ""

    if new_user_file == '':
        user_file_to_set = original_user_file
    else:
        # Try to find the user file in the default paths
        if not os.path.isfile(new_user_file):
            # Find the user file in the Mantid path. we make sure that the user file has a txt extension.
            user_file_names_with_extension = su.get_user_file_name_options_with_txt_extension(
                new_user_file)
            for user_file_name_with_extension in user_file_names_with_extension:
                user_file = FileFinder.getFullPath(
                    user_file_name_with_extension)
                if user_file:
                    break

            if not os.path.isfile(user_file):
                message = "Error could not find specified user file {0}"\
                    .format(new_user_file)
                raise RuntimeError(message)
            else:
                user_file_to_set = user_file
        else:
            user_file_to_set = new_user_file

    # Set the user file in the reducer and load the user file
    if os.path.normpath(user_file_to_set) != os.path.normpath(
            current_user_file):
        # Need to setup a clean reducer. If we are dealing with the original user file,
        # then we should take gui changes into account, ie reset to the original reducer
        if user_file_to_set == original_user_file:
            ReductionSingleton().replace(copy.deepcopy(original_settings))
            ReductionSingleton().settings = original_prop_man_settings.clone(
                REDUCTION_SETTINGS_OBJ_NAME)
        else:
            instrument = copy.deepcopy(ReductionSingleton().get_instrument())
            output_type = ReductionSingleton().to_Q.output_type
            ReductionSingleton().clean(isis_reducer.ISISReducer)
            ReductionSingleton().set_instrument(instrument)
            ReductionSingleton().user_settings = UserFile(user_file_to_set)
            ReductionSingleton().to_Q.output_type = output_type
            ReductionSingleton().user_settings.execute(ReductionSingleton())
        current_user_file = user_file_to_set
    return current_user_file
Пример #2
0
def setUserFileInBatchMode(new_user_file, current_user_file, original_user_file, original_settings, original_prop_man_settings):
    """
        Loads a specified user file. The file is loaded if
        new_user_file is different from  current_user_file. Else we just
        keep the user file loaded. If the new_user_file is empty then we default to
        original_user_file.
        @param new_user_file: The new user file. Note that this can be merely the filename (+ extension)
        @param current_user_file: The currently loaded user file
        @param original_user_file: The originally loaded user file. This is used as a default
        @param original_settings: The original reducer
        @param original_prop_man_settings: Original properties settings
    """
    user_file_to_set = ""

    if new_user_file == '':
        user_file_to_set = original_user_file
    else:
        # Try to find the user file in the default paths
        if not os.path.isfile(new_user_file):
            # Find the user file in the Mantid path. we make sure that the user file has a txt extension.
            user_file_names_with_extension = su.get_user_file_name_options_with_txt_extension(new_user_file)
            for user_file_name_with_extension in user_file_names_with_extension:
                user_file = FileFinder.getFullPath(user_file_name_with_extension)
                if user_file:
                    break

            if not os.path.isfile(user_file):
                message = "Error could not find specified user file {0}"\
                    .format(new_user_file)
                raise RuntimeError(message)
            else:
                user_file_to_set = user_file
        else:
            user_file_to_set = new_user_file

    # Set the user file in the reducer and load the user file
    if os.path.normpath(user_file_to_set) != os.path.normpath(current_user_file):
        # Need to setup a clean reducer. If we are dealing with the original user file,
        # then we should take gui changes into account, ie reset to the original reducer
        if user_file_to_set == original_user_file:
            ReductionSingleton().replace(copy.deepcopy(original_settings))
            ReductionSingleton().settings = original_prop_man_settings.clone(REDUCTION_SETTINGS_OBJ_NAME)
        else:
            instrument = copy.deepcopy(ReductionSingleton().get_instrument())
            output_type = ReductionSingleton().to_Q.output_type
            ReductionSingleton().clean(isis_reducer.ISISReducer)
            ReductionSingleton().set_instrument(instrument)
            ReductionSingleton().user_settings = UserFile(user_file_to_set)
            ReductionSingleton().to_Q.output_type = output_type
            ReductionSingleton().user_settings.execute(ReductionSingleton())
        current_user_file = user_file_to_set
    return current_user_file