From 8b92f964ae5849639b864683a87454b14da64629 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Fri, 14 May 2021 01:09:15 +0200 Subject: [PATCH] working on some update script --- .../fablabchemnitz/upgrade_mightyscape.inx | 15 +++++ .../fablabchemnitz/upgrade_mightyscape.py | 56 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 extensions/fablabchemnitz/upgrade_mightyscape.inx create mode 100644 extensions/fablabchemnitz/upgrade_mightyscape.py diff --git a/extensions/fablabchemnitz/upgrade_mightyscape.inx b/extensions/fablabchemnitz/upgrade_mightyscape.inx new file mode 100644 index 00000000..c7629594 --- /dev/null +++ b/extensions/fablabchemnitz/upgrade_mightyscape.inx @@ -0,0 +1,15 @@ + + + Upgrade MightyScape + fablabchemnitz.de.upgrade_mightyscape + false + + all + + + + + + \ No newline at end of file diff --git a/extensions/fablabchemnitz/upgrade_mightyscape.py b/extensions/fablabchemnitz/upgrade_mightyscape.py new file mode 100644 index 00000000..541c98cd --- /dev/null +++ b/extensions/fablabchemnitz/upgrade_mightyscape.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +""" +Upgrade MightyScape from Inkscape Extension Dialog. Made for end users + +Extension for InkScape 1.X +Author: Mario Voigt / FabLab Chemnitz +Mail: mario.voigt@stadtfabrikanten.org +Date: 14.05.2021 +Last patch: 14.05.2021 +License: GNU GPL v3 +""" + +import inkex +import os +from git import Repo + +class Upgrade(inkex.EffectExtension): + + def add_arguments(self, pars): + pars.add_argument("--stash_untracked", type=inkex.Boolean, default=False, help="Stash untracked files and continue to upgrade") + + def effect(self): + #get the directory of mightyscape + extension_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../', '../') #go up to dir /home//.config/inkscape/extensions/mightyscape-1.X/ + + repo = Repo(os.path.join(extension_dir, ".git")) + + #check if it is a non-empty git repository + if repo.bare is False: + + if repo.is_dirty(untracked_files=True) is False: + if len(repo.untracked_files) > 0: + if self.options.stash_untracked is True: + repo.git.stash('save') + else: + inkex.utils.debug("There are some untracked files in your MightyScape directory. Still trying to pull recent files from git...") + + origin = repo.remotes.origin + fetch_info = origin.fetch() + + for info in fetch_info: + inkex.utils.debug("Updated %s to %s" % (info.ref, info.commit)) + + #finally pull new data + origin.pull() + else: + inkex.utils.debug("MightyScape is up to date!") + exit(0) + + else: + inkex.utils.debug("No \".git\" directory found. Seems your MightyScape was not installed with git clone. Please see documentation on how to do that.") + exit(1) + +if __name__ == '__main__': + Upgrade().run() \ No newline at end of file