Exemplo n.º 1
0
def parse_opts_unit_names(request):

    args = request.args
    config = request.config

    if not args:
        return []

    units = BaseUnit.objects.all()

    match = parse_opts_unit_names_broad(config, args, units)
    if match:
        args.clear()
        return match

    selected_units = []
    args_cpy = list(args)

    for arg in args_cpy:

        nick = basicstrip(arg)
        if nick in config['nicks']:
            nick = basicstrip(config['nicks'][nick])

        match = parse_opts_unit_names_broad(config, [nick], units)
        if match:
            args.remove(arg)
            for m in match:
                if m not in selected_units:
                    selected_units.append(m)

    return selected_units
Exemplo n.º 2
0
    def parse_unit_names(self, args):

        if not args:
            return []

        units = BaseUnit.objects.all()

        match = self.parse_unit_names_broad(args, units)
        if match:
            args.clear()
            return match

        selected_units = []
        args_cpy = list(args)

        for arg in args_cpy:

            nick = basicstrip(arg)
            if nick in self.config['nicks']:
                nick = basicstrip(self.config['nicks'][nick])

            match = self.parse_unit_names_broad([nick], units)
            if match:
                args.remove(arg)
                for m in match:
                    if m not in selected_units:
                        selected_units.append(m)

        return selected_units
Exemplo n.º 3
0
def parse_opts_unit_names_broad(config, args, units):

    full_match = []
    token_match = []
    wild_match = []
    loose_match = []

    if not args:
        return None

    arg = basicstrip(' '.join(args))

    faction = parse_opts_unit_names_by_faction(config, arg)
    if faction:
        return faction

    for unit in units:

        if arg in config['nicks']:
            arg = basicstrip(config['nicks'][arg])

        name = basicstrip(unit.name)

        if arg == name:
            full_match.append(unit)

        elif arg in name.split('-') or arg in name.split(' '):
            token_match.append(unit)

        elif arg in name or arg in name.replace('-', '').replace(' ', ''):
            wild_match.append(unit)

        elif arg.replace('-', '') == name.replace('-', ''):
            loose_match.append(unit)

    if full_match:
        return full_match

    if token_match:
        return token_match

    if wild_match:
        return wild_match

    if loose_match:
        return loose_match

    return None
Exemplo n.º 4
0
def parse_opts_unit_names_v1(request):

    selected_units = []
    args = request.args
    config = request.config
    new_args = list(args)

    for arg in new_args:

        if len(arg) < 2:
            continue

        larg = basicstrip(arg)
        if larg in config['nicks']:
            larg = basicstrip(config['nicks'][larg])

        found = False
        units = BaseUnit.objects.all()

        new_units = []
        for unit in units:

            name1 = basicstrip(unit.name)
            name2 = name1.replace('î', 'i').replace('Î', 'i')
            name3 = name1.replace('-', '')
            name4 = name1.replace('\'', '')

            if larg in name1 or larg in name2 or larg in name3 or larg in name4:
                found = True
                new_units.append(unit)
                if larg == name1:
                    new_units = [unit]
                    break

        if found:
            args.remove(arg)
            selected_units.extend(new_units)

    return selected_units
Exemplo n.º 5
0
def parse_opts_unit_names_by_faction(config, arg):

    faction = []

    larg = basicstrip(arg.lower())
    if larg in BaseUnitFaction.FACTION_NICKS:
        larg = BaseUnitFaction.FACTION_NICKS[larg]

    for fac_key, fac_name in BaseUnitFaction.FACTIONS:
        if larg in fac_key.split('_'):
            if fac_key not in faction:
                faction.append(fac_key)
            break

    return BaseUnit.get_units_by_faction(faction)