Esempio n. 1
0
def find_profile(dir, alternatives):
    """Tries to find a profile with a given number of alternatives
    """

    for file in os.scandir(dir):
        if file.path.endswith(".soc"):
            with open(file) as cur_file:
                num_alternatives = int(cur_file.readline())
                if num_alternatives == alternatives:
                    return Path(file.name).stem, Profile.from_soc(file.path)

    return None
Esempio n. 2
0
def read_profiles(dir, alternatives):
    profiles = {}

    for file in os.scandir(dir):
        if file.path.endswith(".soc"):
            in_range = False

            with open(file) as cur_file:
                num_alternatives = int(cur_file.readline())
                if num_alternatives == alternatives:
                    in_range = True

            if in_range:
                profile = Profile.from_soc(file.path)
                profiles[Path(file.name).stem] = profile

    return profiles