Example #1
0
File: ui.py Project: fchauvel/flap
 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])
Example #2
0
 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("/", "_")
Example #3
0
 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))
Example #4
0
 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
Example #5
0
 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)
Example #6
0
 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))}")
Example #7
0
 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
Example #8
0
 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
Example #9
0
    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")
Example #10
0
    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
Example #11
0
 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)))
Example #12
0
 def _log(self, message):
     logger.debug(f"{self._name}: {message}")
Example #13
0
 def define(self, macro):
     logger.debug("Defining macro {}".format(macro.name))
     self._definitions[macro.name] = macro
Example #14
0
 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}")
Example #15
0
 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)
Example #16
0
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))
Example #17
0
 def set_character_category(self, character, category):
     logger.debug("Set character {} in category '{}'".format(
         character, category))
     self._character_table.assign(character, category)
Example #18
0
 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]
Example #19
0
 def _log(self, message):
     logger.debug(self._name + ": " + message)
Example #20
0
 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()
Example #21
0
 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())