2023-05-01 10:03:44 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
|
|
|
from ..update import update_inkstitch_document
|
|
|
|
from .base import InkstitchExtension
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateSvg(InkstitchExtension):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
InkstitchExtension.__init__(self, *args, **kwargs)
|
2025-03-02 19:54:56 +00:00
|
|
|
self.arg_parser.add_argument("--update-from", type=int, default=0, dest="update_from")
|
2024-05-07 18:48:05 +00:00
|
|
|
# inkstitch_svg_version history:
|
|
|
|
# 1 -> v3.0.0, May 2023
|
|
|
|
# 2 -> v.3.1.0 May 2024
|
2025-03-02 19:54:56 +00:00
|
|
|
# 3 -> v.3.2.0 May2025
|
2023-05-01 10:03:44 +00:00
|
|
|
|
|
|
|
def effect(self):
|
2025-03-15 18:27:24 +00:00
|
|
|
# set the file version to the update_from value, so that the updater knows where to start from
|
|
|
|
# the updater will then reset it to the current version after the update has finished
|
|
|
|
metadata = self.get_inkstitch_metadata()
|
|
|
|
metadata['inkstitch_svg_version'] = self.options.update_from
|
|
|
|
|
2023-05-01 10:03:44 +00:00
|
|
|
if not self.svg.selection:
|
2025-03-02 19:54:56 +00:00
|
|
|
update_inkstitch_document(self.document, warn_unversioned=False)
|
|
|
|
else:
|
2025-03-15 18:27:24 +00:00
|
|
|
update_inkstitch_document(self.document, self.get_selection(), warn_unversioned=False)
|
2023-05-01 10:03:44 +00:00
|
|
|
|
|
|
|
def get_selection(self):
|
|
|
|
selection = []
|
|
|
|
for element in self.svg.selection:
|
|
|
|
selection.append(element)
|
|
|
|
for descendant in element.iterdescendants():
|
|
|
|
selection.append(descendant)
|
|
|
|
return selection
|