Beispiel #1
0
    def find_matching_compartment(self, compartment, interact=True):
        """

        :param compartment: should be an iterable, as-stored in an archive
        :param interact: if true, interactively prompt user to merge and save missing compartments
        :return: the Compartment. Also adds it to self._c_dict
        """
        cs = compartment_string(compartment)
        if cs in self._c_dict.keys():
            return self._c_dict[cs]

        match = traverse_compartments(self.compartments, compartment)
        if match is None:
            if interact:
                c = merge_compartment(self.compartments, compartment)
                match = traverse_compartments(self.compartments, compartment)
                if c is match and c is not None:
                    print('match: %s' % match.to_list())
                    print('Updating compartments...')
                    save_compartments(self.compartments, file=self._compartments_file)
                    return c
            else:
                raise MissingCompartment('%s' % cs)
        else:
            self._c_dict[cs] = match
            return match
Beispiel #2
0
 def save_compartments(self, file):
     save_compartments(self.compartments, file)
     self._compartments_file = file