Merge branch 'master' of https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X
This commit is contained in:
commit
dc6779e55b
@ -15,60 +15,23 @@ import inkex
|
|||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class AboutUpgradeMightyScape(inkex.EffectExtension):
|
|
||||||
|
|
||||||
def add_arguments(self, pars):
|
|
||||||
pars.add_argument("--tab")
|
|
||||||
pars.add_argument("--stash_untracked", type=inkex.Boolean, default=False, help="Stash untracked files and continue to upgrade")
|
|
||||||
|
|
||||||
def effect(self):
|
|
||||||
warnings.simplefilter('ignore', ResourceWarning) #suppress "enable tracemalloc to get the object allocation traceback"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import git
|
import git
|
||||||
from git import Repo #requires GitPython lib
|
from git import Repo #requires GitPython lib
|
||||||
except:
|
except:
|
||||||
inkex.utils.debug("Error. GitPython was not installed but is required to run the upgrade process!")
|
inkex.utils.debug("Error. GitPython was not installed but is required to run the upgrade process!")
|
||||||
return
|
exit(1)
|
||||||
|
|
||||||
#get the directory of mightyscape
|
class AboutUpgradeMightyScape(inkex.EffectExtension):
|
||||||
extension_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) #go up to main dir /home/<user>/.config/inkscape/extensions/mightyscape-1.X/
|
|
||||||
main_dir = os.path.abspath(os.path.join(extension_dir, '../../')) #go up to main dir /home/<user>/.config/inkscape/extensions/mightyscape-1.X/
|
|
||||||
|
|
||||||
#create some statistics
|
def update(self, local_repo, remote):
|
||||||
totalFolders = 0
|
|
||||||
for root, folders, files in os.walk(extension_dir):
|
|
||||||
totalFolders += len(folders)
|
|
||||||
break #prevent descending into subfolders
|
|
||||||
|
|
||||||
totalInx = 0
|
|
||||||
for root, folders, files in os.walk(extension_dir):
|
|
||||||
for file in files:
|
|
||||||
if file.endswith('.inx'):
|
|
||||||
totalInx += 1
|
|
||||||
|
|
||||||
inkex.utils.debug("Locally there are {} extension folders with {} .inx files!".format(totalFolders, totalInx))
|
|
||||||
|
|
||||||
repo = Repo(os.path.join(main_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
|
|
||||||
try:
|
try:
|
||||||
latestRemoteCommit = git.cmd.Git().ls_remote("https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X.git", heads=True).replace('refs/heads/master','').strip()
|
latestRemoteCommit = git.cmd.Git().ls_remote(remote, heads=True).replace('refs/heads/master','').strip()
|
||||||
localCommit = str(repo.head.commit)
|
localCommit = str(local_repo.head.commit)
|
||||||
#ref_logs = repo.head.reference.log()
|
#ref_logs = repo.head.reference.log()
|
||||||
|
|
||||||
#commits = list(repo.iter_commits("master", max_count=5))
|
#commits = list(local_repo.iter_commits("master", max_count=5))
|
||||||
commits = list(repo.iter_commits("master"))
|
commits = list(local_repo.iter_commits("master"))
|
||||||
self.msg("Local commit id is: " + localCommit[:7])
|
self.msg("Local commit id is: " + localCommit[:7])
|
||||||
self.msg("Latest remote commit is: " + latestRemoteCommit[:7])
|
self.msg("Latest remote commit is: " + latestRemoteCommit[:7])
|
||||||
self.msg("There are {} remote commits at the moment.".format(len(commits)))
|
self.msg("There are {} remote commits at the moment.".format(len(commits)))
|
||||||
@ -102,11 +65,61 @@ class AboutUpgradeMightyScape(inkex.EffectExtension):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
inkex.utils.debug("Nothing to do! MightyScape is already up to date!")
|
inkex.utils.debug("Nothing to do! MightyScape is already up to date!")
|
||||||
exit(0)
|
|
||||||
|
|
||||||
except git.exc.GitCommandError:
|
except git.exc.GitCommandError:
|
||||||
self.msg("Error receiving latest remote commit from git. Are you offline? Cannot continue!")
|
return False
|
||||||
return
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def add_arguments(self, pars):
|
||||||
|
pars.add_argument("--tab")
|
||||||
|
pars.add_argument("--stash_untracked", type=inkex.Boolean, default=False, help="Stash untracked files and continue to upgrade")
|
||||||
|
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
warnings.simplefilter('ignore', ResourceWarning) #suppress "enable tracemalloc to get the object allocation traceback"
|
||||||
|
|
||||||
|
#get the directory of mightyscape
|
||||||
|
extension_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '../')) #go up to main dir /home/<user>/.config/inkscape/extensions/mightyscape-1.X/
|
||||||
|
main_dir = os.path.abspath(os.path.join(extension_dir, '../../')) #go up to main dir /home/<user>/.config/inkscape/extensions/mightyscape-1.X/
|
||||||
|
|
||||||
|
#create some statistics
|
||||||
|
totalFolders = 0
|
||||||
|
for root, folders, files in os.walk(extension_dir):
|
||||||
|
totalFolders += len(folders)
|
||||||
|
break #prevent descending into subfolders
|
||||||
|
|
||||||
|
totalInx = 0
|
||||||
|
for root, folders, files in os.walk(extension_dir):
|
||||||
|
for file in files:
|
||||||
|
if file.endswith('.inx'):
|
||||||
|
totalInx += 1
|
||||||
|
|
||||||
|
inkex.utils.debug("Locally there are {} extension folders with {} .inx files!\n".format(totalFolders, totalInx))
|
||||||
|
|
||||||
|
local_repo = Repo(os.path.join(main_dir, ".git"))
|
||||||
|
#check if it is a non-empty git repository
|
||||||
|
if local_repo.bare is False:
|
||||||
|
if local_repo.is_dirty(untracked_files=True) is False:
|
||||||
|
if len(local_repo.untracked_files) > 0:
|
||||||
|
if self.options.stash_untracked is True:
|
||||||
|
local_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 = local_repo.remotes.origin
|
||||||
|
remotes = []
|
||||||
|
remotes.append("https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X.git") #main
|
||||||
|
remotes.append("https://github.com/vmario89/mightyscape-1.X.git") #copy/second remote
|
||||||
|
|
||||||
|
#finally run the update
|
||||||
|
success = self.update(local_repo, remotes[0])
|
||||||
|
if success is False: #try the second remote if first failed
|
||||||
|
self.msg("Error receiving latest remote commit from main git remote {}. Trying second remote ...".format(remotes[0]))
|
||||||
|
success = self.update(local_repo, remotes[1])
|
||||||
|
if success is False: #if still false:
|
||||||
|
self.msg("Error receiving latest remote commit from second git remote {}.\nAre you offline? Cannot continue!".format(remotes[0]))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
else:
|
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.")
|
inkex.utils.debug("No \".git\" directory found. Seems your MightyScape was not installed with git clone. Please see documentation on how to do that.")
|
||||||
|
@ -199,7 +199,7 @@ class vpypetools (inkex.EffectExtension):
|
|||||||
#input_bbox = inkex.elements._selected.ElementList.bounding_box(self.svg.selected) # get BoundingBox for selection
|
#input_bbox = inkex.elements._selected.ElementList.bounding_box(self.svg.selected) # get BoundingBox for selection
|
||||||
input_bbox = self.svg.selection.bounding_box() # get BoundingBox for selection
|
input_bbox = self.svg.selection.bounding_box() # get BoundingBox for selection
|
||||||
if len(lc) == 0:
|
if len(lc) == 0:
|
||||||
inkex.errormsg('Selection appears to be empty or does not contain any valid svg:path nodes. Try to cast your objects to paths using CTRL + SHIFT + C or strokes to paths using CTRL + ALT+ C')
|
self.msg('Selection appears to be empty or does not contain any valid svg:path nodes. Try to cast your objects to paths using CTRL + SHIFT + C or strokes to paths using CTRL + ALT+ C')
|
||||||
return
|
return
|
||||||
# find the first object in selection which has a style attribute (skips groups and other things which have no style)
|
# find the first object in selection which has a style attribute (skips groups and other things which have no style)
|
||||||
firstElementStyle = None
|
firstElementStyle = None
|
||||||
@ -261,7 +261,7 @@ class vpypetools (inkex.EffectExtension):
|
|||||||
self.options.filter_not_closed is False and \
|
self.options.filter_not_closed is False and \
|
||||||
self.options.filter_min_length_enabled is False and \
|
self.options.filter_min_length_enabled is False and \
|
||||||
self.options.filter_max_length_enabled is False:
|
self.options.filter_max_length_enabled is False:
|
||||||
inkex.errormsg('No filters to apply. Please select at least one filter.')
|
self.msg('No filters to apply. Please select at least one filter.')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Plugin Occult
|
# Plugin Occult
|
||||||
@ -292,17 +292,17 @@ class vpypetools (inkex.EffectExtension):
|
|||||||
self.options.freemode_cmd3_enabled is False and \
|
self.options.freemode_cmd3_enabled is False and \
|
||||||
self.options.freemode_cmd4_enabled is False and \
|
self.options.freemode_cmd4_enabled is False and \
|
||||||
self.options.freemode_cmd5_enabled is False:
|
self.options.freemode_cmd5_enabled is False:
|
||||||
inkex.utils.debug("Warning: empty vpype pipeline. With this you are just getting read-write layerset/lineset.")
|
self.msg("Warning: empty vpype pipeline. With this you are just getting read-write layerset/lineset.")
|
||||||
else:
|
else:
|
||||||
if self.options.freemode_show_cmd is True:
|
if self.options.freemode_show_cmd is True:
|
||||||
inkex.utils.debug("Your command pipe will be the following:")
|
self.msg("Your command pipe will be the following:")
|
||||||
inkex.utils.debug(command)
|
self.msg(command)
|
||||||
|
|
||||||
# inkex.utils.debug(command)
|
# self.msg(command)
|
||||||
try:
|
try:
|
||||||
doc = execute(command, doc)
|
doc = execute(command, doc)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
inkex.utils.debug("Error in vpype:" + str(e))
|
self.msg("Error in vpype:" + str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
##########################################
|
##########################################
|
||||||
@ -318,15 +318,16 @@ class vpypetools (inkex.EffectExtension):
|
|||||||
else:
|
else:
|
||||||
traveling_length_saving = 0.0
|
traveling_length_saving = 0.0
|
||||||
if self.options.output_stats is True:
|
if self.options.output_stats is True:
|
||||||
inkex.utils.debug('Total tooling length before vpype conversion: ' + str('{:0.2f}'.format(tooling_length_before)) + ' mm')
|
self.msg('Total tooling length before vpype conversion: ' + str('{:0.2f}'.format(tooling_length_before)) + ' mm')
|
||||||
inkex.utils.debug('Total traveling length before vpype conversion: ' + str('{:0.2f}'.format(traveling_length_before)) + ' mm')
|
self.msg('Total traveling length before vpype conversion: ' + str('{:0.2f}'.format(traveling_length_before)) + ' mm')
|
||||||
inkex.utils.debug('Total tooling length after vpype conversion: ' + str('{:0.2f}'.format(tooling_length_after)) + ' mm')
|
self.msg('Total tooling length after vpype conversion: ' + str('{:0.2f}'.format(tooling_length_after)) + ' mm')
|
||||||
inkex.utils.debug('Total traveling length after vpype conversion: ' + str('{:0.2f}'.format(traveling_length_after)) + ' mm')
|
self.msg('Total traveling length after vpype conversion: ' + str('{:0.2f}'.format(traveling_length_after)) + ' mm')
|
||||||
inkex.utils.debug('Total tooling length optimized: ' + str('{:0.2f}'.format(tooling_length_saving)) + ' %')
|
self.msg('Total tooling length optimized: ' + str('{:0.2f}'.format(tooling_length_saving)) + ' %')
|
||||||
inkex.utils.debug('Total traveling length optimized: ' + str('{:0.2f}'.format(traveling_length_saving)) + ' %')
|
self.msg('Total traveling length optimized: ' + str('{:0.2f}'.format(traveling_length_saving)) + ' %')
|
||||||
|
|
||||||
if tooling_length_after == 0:
|
if tooling_length_after == 0:
|
||||||
inkex.errormsg('No lines left after vpype conversion. Conversion result is empty. Cannot continue. Check your document about containing any svg:path elements. You will need to convert objects and strokes to paths first!')
|
self.msg('No lines left after vpype conversion. Conversion result is empty. Cannot continue. Check your document about containing any svg:path elements. You will need to convert objects and strokes to paths first! Vpype command chain was:')
|
||||||
|
self.msg(command)
|
||||||
return
|
return
|
||||||
|
|
||||||
# show the vpype document visually
|
# show the vpype document visually
|
||||||
@ -349,7 +350,7 @@ class vpypetools (inkex.EffectExtension):
|
|||||||
try:
|
try:
|
||||||
stream = open(output_file, 'r')
|
stream = open(output_file, 'r')
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
inkex.utils.debug("There was no SVG output generated by vpype. Cannot continue")
|
self.msg("There was no SVG output generated by vpype. Cannot continue")
|
||||||
exit(1)
|
exit(1)
|
||||||
p = etree.XMLParser(huge_tree=True)
|
p = etree.XMLParser(huge_tree=True)
|
||||||
import_doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True))
|
import_doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True))
|
||||||
|
Reference in New Issue
Block a user