Exemplo n.º 1
0
    def load_from_file(cls, file: Path) -> Dict[str, "Macro"]:
        """
        Loads the macros from a latex file.
        Will convert the value of the macros to int or float, if possible.

        :param file: the latex file.
        :return: the indexed dictionary of {macro.key, macro}.
        """
        macros_indexed: Dict[str, Macro] = dict()

        lines: List[str] = IOUtils.load(file, "txt").split("\n")
        for line in lines:
            match = cls.RE_DEF_MACRO.fullmatch(line.strip())
            if match is not None:
                key = match.group("key")
                value = match.group("value")

                # Try to convert to int, then (if failing) float.
                try:
                    value = int(value)
                except:
                    try:
                        value = float(value)
                    except:
                        pass
                # end try, try

                macros_indexed[key] = Macro(key, value)
            # end if
        # end for

        return macros_indexed
Exemplo n.º 2
0
 def load_sample_projects_database(cls) -> List[Dict]:
     return IOUtils.load(cls.SAMPLE_PROJECTS_PATH)
Exemplo n.º 3
0
 def load_revision_result(self,
                          revision: str,
                          file_name: str,
                          fmt: str = "json") -> Any:
     return IOUtils.load(self.get_revision_dir(revision) / file_name, fmt)
Exemplo n.º 4
0
 def load_meta_result(self, file_name: str, fmt: str = "json") -> Any:
     return IOUtils.load(self.meta_dir / file_name, fmt)