From e9e4225b1658f1f0a68bc329fad6ac8f26bd7542 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 2 Sep 2022 07:16:16 -0300 Subject: [PATCH] [Diff] Added option to copy instead of link Closes #272 --- kibot/out_diff.py | 11 +++++++++-- tests/test_plot/test_misc.py | 1 + tests/yaml_samples/diff_file_sch_k5.kibot.yaml | 2 ++ tests/yaml_samples/diff_file_sch_k6.kibot.yaml | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kibot/out_diff.py b/kibot/out_diff.py index 373995de..bc0d63a1 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -21,7 +21,7 @@ Dependencies: """ from hashlib import sha1 import os -from shutil import rmtree +from shutil import rmtree, copy2 from subprocess import run, CalledProcessError, STDOUT, PIPE from tempfile import mkdtemp, NamedTemporaryFile from .error import KiPlotConfigurationError @@ -91,6 +91,9 @@ class DiffOptions(BaseOptions): """ When enabled we create a symlink to the output file with a name that contains the git hashes involved in the comparison. If you plan to compress the output don't forget to disable the `follow_links` option """ + self.copy_instead_of_link = False + """ When `add_link_id` is enabled creates a copy of the file instead of a symlink. + Useful for some Windows setups """ super().__init__() self._expand_id = 'diff' self._expand_ext = 'pdf' @@ -286,7 +289,11 @@ class DiffOptions(BaseOptions): run_command(cmd) if self.add_link_id: name_comps = os.path.splitext(name) - os.symlink(os.path.basename(name), name_comps[0]+'_'+gh1+'-'+gh2+name_comps[1]) + target = name_comps[0]+'_'+gh1+'-'+gh2+name_comps[1] + if self.copy_instead_of_link: + copy2(name, target) + else: + os.symlink(os.path.basename(name), target) finally: # Clean-up if remove_cache: diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index 8770b087..8c48d807 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -1382,5 +1382,6 @@ def test_diff_file_sch_1(test_dir): yaml = 'diff_file_sch_'+('k5' if context.ki5() else 'k6') ctx = context.TestContext(test_dir, prj, yaml) ctx.run() + ctx.expect_out_file(prj+'-diff_sch_None-None.pdf') ctx.compare_pdf(prj+'-diff_sch.pdf') ctx.clean_up(keep_project=True) diff --git a/tests/yaml_samples/diff_file_sch_k5.kibot.yaml b/tests/yaml_samples/diff_file_sch_k5.kibot.yaml index 6d98d1b1..ceea6a8a 100644 --- a/tests/yaml_samples/diff_file_sch_k5.kibot.yaml +++ b/tests/yaml_samples/diff_file_sch_k5.kibot.yaml @@ -9,4 +9,6 @@ outputs: old: tests/board_samples/kicad_5/light_control.sch pcb: false old_type: file + add_link_id: true + copy_instead_of_link: true cache_dir: .cache diff --git a/tests/yaml_samples/diff_file_sch_k6.kibot.yaml b/tests/yaml_samples/diff_file_sch_k6.kibot.yaml index 6aa77be5..1dd8676f 100644 --- a/tests/yaml_samples/diff_file_sch_k6.kibot.yaml +++ b/tests/yaml_samples/diff_file_sch_k6.kibot.yaml @@ -9,4 +9,6 @@ outputs: old: tests/board_samples/kicad_6/light_control.kicad_sch pcb: false old_type: file + add_link_id: true + copy_instead_of_link: true cache_dir: .cache