From 171803ff64c0045a7983aa74b61b6f8cd8637f52 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 28 Oct 2022 08:29:54 -0300 Subject: [PATCH] [Populate] Added support to compress and Makefile generation --- kibot/out_compress.py | 14 ++++++++++++-- kibot/out_populate.py | 15 +++++++-------- tests/yaml_samples/populate.kibot.yaml | 7 +++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/kibot/out_compress.py b/kibot/out_compress.py index 416caa9d..24c3a0e6 100644 --- a/kibot/out_compress.py +++ b/kibot/out_compress.py @@ -160,16 +160,26 @@ class CompressOptions(BaseOptions): logger.error('Unknown output `{}` selected in {}'.format(f.from_output, self._parent)) exit(WRONG_ARGUMENTS) if not no_out_run: + extra_files = [] for file in files_list: - if not os.path.isfile(file): + if not os.path.exists(file): # The target doesn't exist if not out._done: # The output wasn't created in this run, try running it run_output(out) - if not os.path.isfile(file): + if not os.path.exists(file): # Still missing, something is wrong logger.error('Unable to generate `{}` from {}'.format(file, out)) exit(INTERNAL_ERROR) + if os.path.isdir(file): + # Popultate output adds the image dirs + # Computing its content is complex: + # - We must parse the input markdown + # - We must coinfigure and use the renderer output to do the file name expansion + # This is almost as complex as generating the whole output, so it adds the dir + extra_files = glob.iglob(os.path.join(file, '**')) + if extra_files: + files_list += extra_files else: out_dir = out_dir_cwd if f.from_cwd else out_dir_default source = f.expand_filename_both(f.source, make_safe=False) diff --git a/kibot/out_populate.py b/kibot/out_populate.py index 97e075c9..26dcfbf5 100644 --- a/kibot/out_populate.py +++ b/kibot/out_populate.py @@ -75,8 +75,12 @@ class PopulateOptions(VariantOptions): if '%d' not in self.imgname: raise KiPlotConfigurationError('The image pattern must contain `%d` `{}`'.format(self.imgname)) -# def get_targets(self, out_dir): -# return [self._parent.expand_filename(out_dir, self.output)] + def get_out_file_name(self): + return 'index.html' if self.format == 'html' else 'index.md' + + def get_targets(self, out_dir): + img_dir = os.path.dirname(self._parent.expand_filename(out_dir, self.imgname)) + return [self._parent.expand_filename(out_dir, self.get_out_file_name()), img_dir] def generate_image(self, side, components, active_components, name): options = self._renderer.options @@ -167,7 +171,7 @@ class PopulateOptions(VariantOptions): raise KiPlotConfigurationError('Failed to load file `{}`'.format(template_file)) # Initialize the output file renderer renderer = create_renderer(self.format, self.initial_components) - outputfile = 'index.html' if is_html else 'index.md' + outputfile = self.get_out_file_name() # Parse the input markdown parsed_content = parse_content(renderer, content) logger.debugl(3, parsed_content) @@ -197,8 +201,3 @@ class Populate(BaseOutput): # noqa: F821 self.options = PopulateOptions """ *[dict] Options for the `populate` output """ self._category = 'PCB/docs' - -# def get_dependencies(self): - -# @staticmethod -# def get_conf_examples(name, layers, templates): diff --git a/tests/yaml_samples/populate.kibot.yaml b/tests/yaml_samples/populate.kibot.yaml index c02259dd..b888cc02 100644 --- a/tests/yaml_samples/populate.kibot.yaml +++ b/tests/yaml_samples/populate.kibot.yaml @@ -76,3 +76,10 @@ outputs: options: renderer: PcbDraw input: tests/data/source_html.md + + - name: Compressed + comment: "Compress the result" + type: compress + options: + files: + - from_output: Populate