def _read_request_from(self, arguments): logger.debug("Command line parameters:" + ", ".join(map(str, arguments))) assert len(arguments) == 3, "Expected 3 arguments, but found %s" % arguments return Settings(file_system=self._file_system, ui=self._display, root_tex_file=arguments[1], output=arguments[2])
def _update_link(self, path, invocation, location, extensions, error): logger.debug("Updating '" + path + "(" + invocation.as_text + ")") self._show_invocation(invocation) resource = self._find(path, location, extensions, error) new_path = resource._path.relative_to(self.root_directory._path) new_file_name = str(new_path).replace("/", "_") self._file_system.copy(resource, self.output_directory / new_file_name) return str(new_path.without_extension()).replace("/", "_")
def _debug(self, category, action, tokens): text = "" position = "None" if not len(tokens) == 0: text = truncate(self._as_text(tokens), 30) position = tokens[-1].location, logger.debug("GL={} {} {} {}".format(self._level, action, category, text))
def rewrite2(self, parser, invocation): class_name = self.find_class_name(parser, invocation) if class_name == "subfiles": parser.read.until_text(r"\begin{document}", True) document = parser.read.until_text(r"\end{document}", True) logger.debug("Subfile extraction" + "".join(str(t) for t in document)) return parser.evaluate(document[:-11], dict()) return invocation.as_tokens
def execute2(self, parser, invocation): self._called = True logger.debug("Setting CALLED on %d", id(self)) link = parser.evaluate_as_text(invocation.argument("link")) content = self._flap.content_of(link, invocation) logger.debug("TEX INCLUSION %s: '%s'", link, content) if not link.endswith(".tex"): link += ".tex" tokens = parser._create.as_list(content) return parser._tokens.push(tokens)
def push(self, items): if isinstance(items, list): assert not any(i is None for i in items), \ "Cannot push None!" self._cache.extend(reversed(items)) else: assert items is not None, \ "Cannot push None" self._cache.append(items) logger.debug(f"Pushing! New cache size: {str(len(self._cache))}")
def rewrite2(self, parser, invocation): invocation.append_argument("options", parser.read.options()) logger.debug("OPTIONS: '%s'", invocation.argument_as_text("options")) invocation.append_argument("link", parser.read.one()) logger.debug("LINK: '%s'", invocation.argument_as_text("link")) link = parser.evaluate_as_text(invocation.argument("link")) new_link = self._flap.update_link_to_graphic(link, invocation) return invocation.substitute("link", parser._create.as_list( "{" + new_link + "}")).as_tokens
def shall_expand(self): logger.debug("Expanding") result = False for _, any_macro in self._definitions.items(): was_called = getattr(any_macro, "was_called", None) if was_called \ and any_macro.was_called \ and any_macro.requires_expansion: result = True for _, any_macro in self._definitions.items(): was_called = getattr(any_macro, "was_called", None) if was_called: any_macro._called = False return result
def relocate_dependency(self, dependency, invocation): if dependency not in self._analysed_dependencies: self._analysed_dependencies.append(dependency) try: file = self._find(dependency, [self.root_directory], ["sty", "cls"], TexFileNotFound(None)) self._file_system.copy(file, self.output_directory / file.fullname()) self._show_invocation(invocation) symbol_table = SymbolTable.default() symbol_table.CHARACTER += '@' self._rewrite(file.content(), file.fullname(), symbol_table) except TexFileNotFound: logger.debug("Could not find class or package '" + dependency + " locally")
def _execute(self, parser, invocation): logger.debug("Invocation: " + invocation.as_text) character = "".join( str(each_token) for each_token in invocation.argument("#1")) if character[0] == "`": if character[1] == "\\": character = character[2] else: character = character[1] new_category = "".join( str(each_token) for each_token in invocation.argument("#2")) self._flap.set_character_category(character, int(new_category)) return invocation.as_tokens
def _capture_arguments(self, parser, invocation): for index, any_token in enumerate(self._signature): if any_token.is_a_parameter: parameter = str(any_token) if index == len(self._signature) - 1: expression = parser.read.one() invocation.append_argument(parameter, expression) logger.debug("Arg '{}' is '{}'".format( any_token.as_text, "".join(t.as_text for t in expression))) else: next_token = self._signature[index + 1] value = parser.read.until_text(next_token.as_text) invocation.append_argument(parameter, value) logger.debug("Arg '{}' is '{}'".format( any_token.as_text, "".join(t.as_text for t in value))) else: invocation.append(parser.read.text(str(any_token)))
def _log(self, message): logger.debug(f"{self._name}: {message}")
def define(self, macro): logger.debug("Defining macro {}".format(macro.name)) self._definitions[macro.name] = macro
def debug(self): logger.debug("View of the stack ...") for index in range(len(self._cache)): item = self._cache[-(index+1)] text = str(item) if isinstance(item, str) else item.as_text logger.debug(f" - {index}: {item}")
def include_only(self, selection, invocation): logger.debug("Restrict inclusion to [" + ", ".join(selection) + "] (" + invocation.as_text + ")") self._show_invocation(invocation) self._selected_for_inclusion.extend(selection)
def log(invocation, message, **kwargs): data = (invocation.location.source, str(invocation.location.line), str(invocation.location.column), repr(truncate(invocation.as_text, length=40)), message.format(**kwargs)) logger.debug(" ".join(data))
def set_character_category(self, character, category): logger.debug("Set character {} in category '{}'".format( character, category)) self._character_table.assign(character, category)
def record_graphic_path(self, paths, invocation): logger.debug("Updating graphicpath (" + invocation.as_text + ")") self._show_invocation(invocation) self._graphic_directories = [self._file_system.open(self.root_directory._path / each) for each in paths]
def _log(self, message): logger.debug(self._name + ": " + message)
def content_of(self, location, invocation): logger.debug("Fetching '" + location + "(" + invocation.as_text + ")") self._show_invocation(invocation) file = self._find(location, [self.root_directory], ["tex"], TexFileNotFound(None)) return file.content()
def _capture_arguments(parser, invocation): invocation.append_argument("options", parser.read.options()) logger.debug("Options = '%s'", invocation.argument_as_text("options")) invocation.append_argument("link", parser.read.group())