Determines and stores information about the sorting configuration
found for entries of the module
517455
protected function processModuleSorting()
    {
        $this->model['is_listified'] = false;
        $this->model['ordered_by']   = [];

        // if there can be only 1 entry, it makes no sense to listify or order in any case
        if ($this->module['max_entries'] == 1) {
            return;
        }

        // if manually sorted, use listify and do not set sorting columns
        if ($this->module['sort_entries_manually']) {
            $this->model['is_listified'] = true;
            return;
        }

        // if automatically sorted, check and extract the sorting columns
        // listify is disabled by default, but may be overridden (might be useful some day)
        $this->model['is_listified'] = false;

        $sorting = trim(strtolower($this->module['sort_entries_by']));

        if (empty($sorting)) return;

        foreach (explode(',', $sorting) as $sortClauseString) {

            if ( ! preg_match("#^\s*[`'](.*)[`']\s+(asc|desc)\s*$#i", $sortClauseString, $matches)) {
                $this->context->log(
                    "Could not interpret sorting clause '{$sortClauseString}' for module #{$this->moduleId}",
                    Generator::LOG_LEVEL_ERROR
                );
                continue;
            }

            // store direction per column as key
            $this->model['ordered_by'][ $matches[1] ] = $matches[2];
        }
    }
452248
def sort(self, attr):
        """"""
        self.entries = Sorter(self.entries, self.category, attr).sort_entries()
        return self
509395
def _find_v1_settings(self, settings):
        

        if 'module_name' in settings:
            modname = settings['module_name']
        if 'modules' not in settings or len(settings['modules']) == 0:
            raise DataError("No modules defined in module_settings.json file")
        elif len(settings['modules']) > 1:
            raise DataError("Multiple modules defined in module_settings.json file",
                            modules=[x for x in settings['modules']])
        else:
            modname = list(settings['modules'])[0]

        if modname not in settings['modules']:
            raise DataError("Module name does not correspond with an entry in the modules directory",
                            name=modname, modules=[x for x in settings['modules']])

        release_info = self._load_release_info(settings)
        modsettings = settings['modules'][modname]
        architectures = settings.get('architectures', {})

        target_defs = settings.get('module_targets', {})
        targets = target_defs.get(modname, [])

        return TileInfo(modname, modsettings, architectures, targets, release_info)
296932
private function generatePhpDocSortDescription(): void
  {
    if ($this->routine['phpdoc']['sort_description']!=='')
    {
      $this->codeStore->append(' * '.$this->routine['phpdoc']['sort_description'], false);
    }
  }
206298
def _prepare_sort_options(self, has_pk):
        
        sort_options = {}
        if self._sort is not None and not has_pk:
            sort_options.update(self._sort)
        if self._sort_limits is not None:
            if 'start' in self._sort_limits and 'num' not in self._sort_limits:
                self._sort_limits['num'] = -1
            elif 'num' in self._sort_limits and 'start' not in self._sort_limits:
                self._sort_limits['start'] = 0
            sort_options.update(self._sort_limits)
        if not sort_options and self._sort is None:
            sort_options = None
        return sort_options
893818
def sort_versions(self):
        
        if self.sorted:
            return

        for orderer in (self.solver.package_orderers or []):
            entries = orderer.reorder(self.entries, key=lambda x: x.package)
            if entries is not None:
                self.entries = entries
                self.sorted = True

                if self.pr:
                    self.pr("sorted: %s packages: %s", self.package_name, repr(orderer))
                return

        # default ordering is version descending
        self.entries = sorted(self.entries, key=lambda x: x.version, reverse=True)
        self.sorted = True

        if self.pr:
            self.pr("sorted: %s packages: version descending", self.package_name)
746241
function sort() {
    var state = getInternalParamsState(this);
    var entries = state.entries;
    // Array#sort is not stable in some engines
    var slice = entries.slice();
    var entry, i, j;
    entries.length = 0;
    for (i = 0; i < slice.length; i++) {
      entry = slice[i];
      for (j = 0; j < i; j++) if (entries[j].key > entry.key) {
        entries.splice(j, 0, entry);
        break;
      }
      if (j === i) entries.push(entry);
    }
    if (state.updateURL) state.updateURL();
  }
491946
def filter_entries(entries, config):
    """"""
    def in_genus_list(species, genus_list):
        for genus in genus_list:
            if species.startswith(genus.capitalize()):
                return True
        return False

    new_entries = []
    for entry in entries:
        if config.type_material and config.type_material != ['any']:
            requested_types = map(lambda x: config._RELATION_TO_TYPE_MATERIAL[x], config.type_material)
            if not entry['relation_to_type_material'] or entry['relation_to_type_material'] not in requested_types:
                 logging.debug("Skipping assembly with no reference to type material or reference to type material does not match requested")
                 continue 
            else:
                print(entry['relation_to_type_material'])
        if config.genus and not in_genus_list(entry['organism_name'], config.genus):
            logging.debug('Organism name %r does not start with any in %r, skipping',
                          entry['organism_name'], config.genus)
            continue
        if config.species_taxid and entry['species_taxid'] not in config.species_taxid:
            logging.debug('Species TaxID %r does not match with any in %r, skipping',
                          entry['species_taxid'], config.species_taxid)
            continue
        if config.taxid and entry['taxid'] not in config.taxid:
            logging.debug('Organism TaxID %r does not match with any in %r, skipping',
                          entry['taxid'], config.taxid)
            continue
        if not config.is_compatible_assembly_accession(entry['assembly_accession']):
            logging.debug('Skipping entry with incompatible assembly accession %r', entry['assembly_accession'])
            continue
        if not config.is_compatible_assembly_level(entry['assembly_level']):
            logging.debug('Skipping entry with assembly level %r', entry['assembly_level'])
            continue
        if config.refseq_category != 'all' \
                and entry['refseq_category'] != config.get_refseq_category_string(config.refseq_category):
            logging.debug('Skipping entry with refseq_category %r, not %r', entry['refseq_category'],
                          config.refseq_category)
            continue
        new_entries.append(entry)

    return new_entries
1246517
def resolve_sorting(self, query):
        
        sorting = {}

        # Sort on
        sort_on = query.get("sidx", None)
        sort_on = sort_on or query.get("sort_on", None)
        sort_on = sort_on == "Title" and "sortable_title" or sort_on
        if sort_on:
            sorting["sort_on"] = sort_on

            # Sort order
            sort_order = query.get("sord", None)
            sort_order = sort_order or query.get("sort_order", None)
            if sort_order in ["desc", "reverse", "rev", "descending"]:
                sorting["sort_order"] = "descending"
            else:
                sorting["sort_order"] = "ascending"

            # Sort limit
            sort_limit = api.to_int(query.get("limit", 30), default=30)
            if sort_limit:
                sorting["sort_limit"] = sort_limit

        return sorting
239835
protected function applySortForm(): SortConfig
    {
        $form = $this->getForm();
        $sortableForm = $form->get(self::SORTABLE_FORM_NAME);
        /** @var FormInterface $sortConfigForm */
        $sortConfigForm = $sortableForm->get(self::SORT_CONFIG_FORM_NAME);
        /** @var SortConfig $sortConfig */
        $sortConfig = $sortConfigForm->getData();

        foreach ($this->getConfiguration()->getSortable() as $sortable) {
            /** @var SubmitButton $button */
            $button = $sortableForm->get($sortable);
            if ($button->isClicked()) {
                if ($sortConfig->getColumn() === $sortable) {
                    $sortConfig->switchDirection();
                } else {
                    $sortConfig->setColumn($sortable);
                    $sortConfig->setDirection(false);
                }
            }
        }

        return $sortConfig;
    }
599058
def save(self, sortkey = True):
        
        return [k + '=' + repr(v) for k,v in self.config_items(sortkey)]
513161
def _collection(self):
        
        old_sort_limits_and_len_mode = None if self._sort_limits is None else self._sort_limits.copy(), self._len_mode
        old_sorts = None if self._sort is None else self._sort.copy(),\
                    None if self._sort_by_sortedset is None else self._sort_by_sortedset.copy()
        try:
            if self.stored_key and not self._stored_len:
                if self._len_mode:
                    self._len = 0
                    self._len_mode = False
                self._sort_limits = {}
                return []

            # Manage sort desc added by original `__getitem__` when we sort by score
            if self._sort_by_sortedset and self._sort and self._sort.get('desc'):
                self._sort = None
                self._sort_by_sortedset['desc'] = not self._sort_by_sortedset.get('desc', False)

            return super(ExtendedCollectionManager, self)._collection
        finally:
            self._sort_limits, self._len_mode = old_sort_limits_and_len_mode
            self._sort, self._sort_by_sortedset = old_sorts
568685
def config_value_items(self, sortkey = False):
        
        return ((k, getattr(self, k)) for k in self.config_value_keys(sortkey))
1012692
def _ProcessEntries(self, fd):
    """"""
    p = config_file.KeyValueParser(kv_sep="{", term="}", sep=None)
    data = utils.ReadFileBytesAsUnicode(fd)
    entries = p.ParseEntries(data)
    for entry in entries:
      for section, cfg in iteritems(entry):
        # The parser returns a list of configs. There will only be one.
        if cfg:
          cfg = cfg[0].strip()
        else:
          cfg = ""
        self._ParseSection(section, cfg)
796682
def _sorted_keys(self):
        

        try:
            keys = self._cache['sorted_keys']
        except KeyError:
            keys = self._cache['sorted_keys'] = sorted(self.keys(), key=parse_version)

        return keys
452557
protected function getCmsOrderedConfigReplace()
    {
        $orderColumns = $this->data['ordered_by'] ?: [];


        // for now, ignore the ordering if the column to order on is translated
        $translatedOrderColumns = array_intersect(array_keys($orderColumns
        ), $this->data['translated_attributes']);

        if (count($translatedOrderColumns)) {
            foreach ($translatedOrderColumns as $column) {
                unset($orderColumns[ $column ]);
            }
        }

        if ( ! count($orderColumns)) return '';
        

        // we only need to set a config if the scope method is global
        if (config('pxlcms.generator.models.scopes.position_order') !== CmsModelWriter::SCOPE_GLOBAL) return '';


        // align assignment signs by longest attribute
        $longestLength = 0;

        foreach ($orderColumns as $attribute => $direction) {

            if (strlen($attribute) > $longestLength) {
                $longestLength = strlen($attribute);
            }
        }

        $replace = $this->tab() . "protected \$cmsOrderBy = [\n";

        foreach ($orderColumns as $attribute => $direction) {

            $replace .= $this->tab(2)
                . "'" . str_pad($attribute . "'", $longestLength + 1)
                . " => '" . $direction . "',\n";
        }

        $replace .= $this->tab() . "];\n\n";

        return $replace;
    }
1032686
def sort_items(self,items,args=False):
    
    if self.settings['sort'].lower() == 'src': return
    def alpha(i):
        return i.name
    def permission(i):
        if args:
            if i.intent == 'in': return 'b'
            if i.intent == 'inout': return 'c'
            if i.intent == 'out': return 'd'
            if i.intent == '': return 'e'
        perm = getattr(i, 'permission', '')
        if perm == 'public': return 'b'
        if perm == 'protected': return 'c'
        if perm == 'private': return 'd'
        return 'a'
    def permission_alpha(i):
        return permission(i) + '-' + i.name
    def itype(i):
        if i.obj == 'variable':
            retstr = i.vartype
            if retstr == 'class': retstr = 'type'
            if i.kind: retstr = retstr + '-' + str(i.kind)
            if i.strlen: retstr = retstr + '-' + str(i.strlen)
            if i.proto:
                retstr = retstr + '-' + i.proto[0]
            return retstr
        elif i.obj == 'proc':
            if i.proctype != 'Function':
                return i.proctype.lower()
            else:
                return i.proctype.lower() + '-' + itype(i.retvar)
        else:
            return i.obj
    def itype_alpha(i):
        return itype(i) + '-' + i.name

    if self.settings['sort'].lower() == 'alpha':
        items.sort(key=alpha)
    elif self.settings['sort'].lower() == 'permission':
        items.sort(key=permission)
    elif self.settings['sort'].lower() == 'permission-alpha':
        items.sort(key=permission_alpha)
    elif self.settings['sort'].lower() == 'type':
        items.sort(key=itype)
    elif self.settings['sort'].lower() == 'type-alpha':
        items.sort(key=itype_alpha)