'Find a package. The package can be specified by name
or as a dictionary with name, version and flavor entries.
Only name is obligatory. If there are multiple matches the
best one (higher version number, flavors ordered according to
users\' preference) is returned.'

def find(self, ident):

    if (type(ident) == str):
        if ((ident[0] == '(') and (ident[(-1)] == ')')):
            ident = ident[1:(-1)]
        fields = ident.split('-')
        if ((len(fields) < 1) or (len(fields) > 3)):
            return None
        name = fields[0]
        if (len(fields) > 1):
            version = fields[1]
        else:
            version = None
        if (len(fields) > 2):
            flavor = fields[2]
        else:
            flavor = None
    else:
        name = ident['Name']
        version = ident.get('Version')
        flavor = ident.get('Flavor')
    found = None
    for p in self._packages:
        if ((name == p.name()) and ((not version) or (version == p.version())) and ((not flavor) or (flavor == p.flavor()))):
            if ((not found) or (found < p)):
                found = p
    return found
