def parse(self, resource):
        """ Parse a list of directories and reads it into a collection

        :param resource: List of folders
        :return: An inventory resource and a list of CtsTextMetadata metadata-objects
        """
        textgroups = []
        texts = []
        invalids = []

        for folder in resource:
            cts_files = glob("{base_folder}/data/*/__cts__.xml".format(base_folder=folder))
            for cts_file in cts_files:
                textgroup, cts_file = self._parse_textgroup(cts_file)
                textgroups.append((textgroup, cts_file))

        for textgroup, cts_textgroup_file in textgroups:
            cts_work_files = glob("{parent}/*/__cts__.xml".format(parent=os.path.dirname(cts_textgroup_file)))

            for cts_work_file in cts_work_files:
                _, parsed_texts, directory = self._parse_work(cts_work_file, textgroup)
                texts.extend([(text, directory) for text in parsed_texts])

        for text, directory in texts:
            # If text_id is not none, the text parsing errored
            if not self._parse_text(text, directory):
                invalids.append(text)

        # Dispatching routine
        for textgroup, textgroup_path in textgroups:
            self._dispatch_container(textgroup, textgroup_path)

        # Clean invalids if there was a need
        self._clean_invalids(invalids)

        self.inventory = self.dispatcher.collection
        return self.inventory
def parse ( self , resource ) : textgroups = [ ] texts = [ ] invalids = [ ] for folder in resource : cts_files = glob ( "{base_folder}/data/*/__cts__.xml" . format ( base_folder = folder ) ) for cts_file in cts_files : textgroup , cts_file = self . _parse_textgroup ( cts_file ) textgroups . append ( ( textgroup , cts_file ) ) for textgroup , cts_textgroup_file in textgroups : cts_work_files = glob ( "{parent}/*/__cts__.xml" . format ( parent = os . path . dirname ( cts_textgroup_file ) ) ) for cts_work_file in cts_work_files : _ , parsed_texts , directory = self . _parse_work ( cts_work_file , textgroup ) texts . extend ( [ ( text , directory ) for text in parsed_texts ] ) for text , directory in texts : if not self . _parse_text ( text , directory ) : invalids . append ( text ) for textgroup , textgroup_path in textgroups : self . _dispatch_container ( textgroup , textgroup_path ) self . _clean_invalids ( invalids ) self . inventory = self . dispatcher . collection return self . inventory
Parse a list of directories and reads it into a collection

        :param resource: List of folders
        :return: An inventory resource and a list of CtsTextMetadata metadata-objects