From fa7a526883bdd35aca780b653af96169fd843aa8 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 18 Jun 2022 23:50:43 +0200 Subject: Add CachedLazyCamFile --- gerbonara/cam.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gerbonara') diff --git a/gerbonara/cam.py b/gerbonara/cam.py index 2cc57ba..fb69e5c 100644 --- a/gerbonara/cam.py +++ b/gerbonara/cam.py @@ -416,3 +416,23 @@ class LazyCamFile: """ Copy this Gerber file to the new path. """ shutil.copy(self.original_path, filename) +class CachedLazyCamFile: + def __init__(self, klass, data, original_path, *args, **kwargs): + self._class = klass + self._data = data + self.original_path = original_path + self._args = args + self._kwargs = kwargs + + @cached_property + def instance(self): + return self._class.from_string(self._data, filename=self.original_path, *self._args, **self._kwargs) + + @property + def is_lazy(self): + return True + + def save(self, filename, *args, **kwargs): + """ Copy this Gerber file to the new path. """ + Path(filename).write_text(self._data) + -- cgit