Beispiel #1
0
 def get_settings_dict_variable_names(self, subcategory):
     """ Returns a sorted list of variables in a specific category
         and subcategory, expanding variable names if they are arrays
         or derived types
     """
     varlist = []
     for cat_name in self._settings['_order']:
         for var_name in MARBL_tools.sort(self._settings[cat_name].keys()):
             if isinstance(self._settings[cat_name][var_name]['datatype'],
                           dict):
                 for subvar_name in MARBL_tools.sort(
                         self._settings[cat_name][var_name]
                     ['datatype'].keys()):
                     if subvar_name[0] != '_':
                         this_var = self._settings[cat_name][var_name][
                             'datatype'][subvar_name]
                         if this_var['subcategory'] == subcategory:
                             for settings_name in this_var[
                                     '_list_of_settings_names']:
                                 varlist.append(settings_name)
             else:
                 this_var = self._settings[cat_name][var_name]
                 if this_var['subcategory'] == subcategory:
                     for settings_name in this_var[
                             '_list_of_settings_names']:
                         varlist.append(settings_name)
     return MARBL_tools.sort(varlist, sort_key=MARBL_tools.natural_sort_key)
Beispiel #2
0
    def get_subcategory_names(self):
        """ Returns a sorted list of subcategories in a specific category.
            For now, the list is sorted naturally (so 10 appears after 9, not after 1).

            Optional: only return variables in a specific subcategory
        """
        subcat_list = []
        for cat_name in self._settings['_order']:
            for var_name in MARBL_tools.sort(self._settings[cat_name].keys()):
                if isinstance(self._settings[cat_name][var_name]['datatype'],
                              dict):
                    for subvar_name in MARBL_tools.sort(
                            self._settings[cat_name][var_name]
                        ['datatype'].keys()):
                        if subvar_name[0] != '_':
                            this_subcat = self._settings[cat_name][var_name][
                                'datatype'][subvar_name]['subcategory']
                            if this_subcat not in subcat_list:
                                subcat_list.append(this_subcat)
                else:
                    this_subcat = self._settings[cat_name][var_name][
                        'subcategory']
                    if this_subcat not in subcat_list:
                        subcat_list.append(this_subcat)
        return MARBL_tools.sort(subcat_list,
                                sort_key=MARBL_tools.natural_sort_key)
def _sort_with_specific_suffix_first(list_in, suffix=None, sort_key=lambda s: s.lower()):
    """ Sort, but make sure entries that end in a specified suffix are listed first
    """

    # 1. initialize empty list
    list_out = []

    # 2. Anything that ends in suffix gets appended to list_out first
    if suffix is not None:
        for list_entry in MARBL_tools.sort(list_in, sort_key):
            if list_entry.endswith(suffix):
                list_out.append(list_entry)

    # 3. Sort everything else
    for list_entry in MARBL_tools.sort(list_in, sort_key):
        if list_entry not in list_out:
            list_out.append(list_entry)
    return list_out
Beispiel #4
0
 def get_variable_names(self, category_name, sort_key=lambda s: s.lower()):
     """ Returns a sorted list of variables in a specific category.
         For now, the list is sorted alphabetically.
     """
     return MARBL_tools.sort(self._settings[category_name].keys(), sort_key)