def identifier_is_available(self, identifier):
        matches = []
        for codepath in self.available_package_names_list():
            pkg = self.get_available_package(codepath)
            try:
                pkg.load()
                if pkg.identifier == identifier:
                    matches.append(pkg)
                elif identifier in pkg.old_identifiers:
                    matches.append(pkg)
                if (hasattr(pkg._module, "can_handle_identifier") and
                        pkg._module.can_handle_identifier(identifier)):
                    matches.append(pkg)
            except (pkg.LoadFailed, pkg.InitializationFailed,
                    MissingRequirement):
                pass
            except Exception, e:
                debug.warning(
                    "Error loading package <codepath %s>" % pkg.codepath,
                    e)
        if len(matches) == 0:
            return None
        elif len(matches) == 1:
            return matches[0]
        # return package version that passes requirements
        valids = []
        for pkg in matches:
            try:
                pkg.check_requirements()
                valids.append(pkg)
            except (pkg.LoadFailed, pkg.InitializationFailed,
                    MissingRequirement):
                pass
            except Exception, e:
                debug.warning(
                    "Package <codepath %s> raised an exception while "
                    "querying requirements" % pkg.codepath,
                    e)
        if len(valids) == 1:
            return valids[0]
        elif len(valids) == 0:
            # return latest invalid package
            valids = matches
        # return latest version
        return sorted(valids, key=lambda x: LooseVersion(x.version))[-1]
Verifies a single sort key and direction.
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/core/packagemanager.py/PackageManager.identifier_is_available--crossover with--dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/tests/unit/api/openstack/test_common.py/SortParamUtilsTest.test_get_sort_params_single_value