finalised get_image_from_config

This commit is contained in:
vicky 2022-05-18 21:31:31 +02:00
parent 7f12e46f5a
commit 337273a09e
1 changed files with 9 additions and 14 deletions

View File

@ -199,8 +199,9 @@ class PreParser:
temp_file.writelines(import_file.readlines()) temp_file.writelines(import_file.readlines())
temp_file.writelines(source_lines[source_line_count:]) temp_file.writelines(source_lines[source_line_count:])
temp_file.seek(0) temp_file.seek(0)
self.current_origin_for_read = temp_file
self.imports_done = True self.imports_done = True
return temp_file return self.current_origin_for_read
def parse_shortcuts_and_images(self): def parse_shortcuts_and_images(self):
""" """
@ -222,6 +223,7 @@ class PreParser:
self.file_with_all_replacements.write(temp_text) self.file_with_all_replacements.write(temp_text)
self.file_with_all_replacements.write("\n") self.file_with_all_replacements.write("\n")
self.file_with_all_replacements.seek(0) self.file_with_all_replacements.seek(0)
self.replacements_done = True
return self.file_with_all_replacements return self.file_with_all_replacements
def get_alias_from_config(self, shortcut, optional): def get_alias_from_config(self, shortcut, optional):
@ -241,12 +243,8 @@ class PreParser:
:param shortcut: the id of the picture to fetch :param shortcut: the id of the picture to fetch
:param optionals: optional parameters along with image :param optionals: optional parameters along with image
""" """
request = export.ExportRequest('inline_elements', 'image', export.format_optionals(optionals))
blind_run = export.ExportRequest('inline_elements', 'image', export.format_optionals(optionals)) output = self.__env.export_mngr(request)
# local_export_manager = self.__env.export_manager
local_export_manager = export.ExportManager("", "")
output = local_export_manager(blind_run)
return output.start + shortcut + output.end return output.start + shortcut + output.end
def __repr__(self): def __repr__(self):
@ -305,7 +303,7 @@ class PreParser:
self.tree_view = Tree(prefix+stripped_name+suffix) self.tree_view = Tree(prefix+stripped_name+suffix)
for p, l in self.parse_import_list(): for p, l in self.parse_import_list():
try: try:
self.tree_view.add(self.global_dict_of_imports[p].rich_tree(suffix=" (Line:{})".format(l), force=True, strip_prefix=strip_prefix)) self.tree_view.add(self.global_dict_of_imports[p].rich_tree(suffix=" (Line:{})".format(l), force=True, strip_prefix=strip_prefix)) # noqa
except KeyError: # The key isn't in the global dict yet except KeyError: # The key isn't in the global dict yet
self.tree_view.add(Tree(prefix+p+suffix+" !!")) self.tree_view.add(Tree(prefix+p+suffix+" !!"))
unparsed = True unparsed = True
@ -320,14 +318,11 @@ class PreParser:
if __name__ == "__main__": # pragma: no cover if __name__ == "__main__": # pragma: no cover
from bootstraparse.modules import config from bootstraparse.modules import config
from bootstraparse.modules import pathresolver from bootstraparse.modules import pathresolver
site_path = pathresolver.b_path("../../example_userfiles/index.bpr") site_path = pathresolver.b_path("../../example_userfiles/test.bpr")
config_path = pathresolver.b_path("../../example_userfiles/config/") config_path = pathresolver.b_path("../../example_userfiles/config/")
__env = environment.Environment() __env = environment.Environment()
__env.config = config.ConfigLoader(config_path) __env.config = config.ConfigLoader(config_path)
__env.export_manager = export.ExportManager('', '') __env.export_mngr = export.ExportManager('', '')
t_pp = PreParser(site_path, __env) t_pp = PreParser(site_path, __env)
out = t_pp.do_replacements() out = t_pp.do_replacements()
rich.print(t_pp.get_all_lines())
# rich.print(michel.rich_tree())
string_to_match = r'@[bite]{id=2}[saucisse=13] @[chaussette] @[bermuda]{tomate=tomate}[12] @[pasteque]'
rich.print(out.readlines())