[Diff] Added option to copy instead of link

Closes #272
This commit is contained in:
Salvador E. Tropea 2022-09-02 07:16:16 -03:00
parent cabf14ec07
commit e9e4225b16
4 changed files with 14 additions and 2 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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