AddonManager: Added function to check for updates for a specific addon

This commit is contained in:
Yorik van Havre
2019-08-22 16:44:00 -03:00
parent 4d12917b5f
commit 0f714e00f1
2 changed files with 42 additions and 0 deletions

View File

@@ -587,4 +587,13 @@ class CommandAddonManager:
pref.SetBool("AutoCheck",self.config.checkUpdates.isChecked())
pref.SetString("CustomRepositories",self.config.customRepositories.toPlainText())
def check_updates(addon_name,callback):
"""Checks for updates for a given addon"""
oname = "update_checker_"+addon_name
setattr(FreeCAD,oname,CheckSingleWorker(addon_name))
getattr(FreeCAD,oname).updateAvailable.connect(callback)
getattr(FreeCAD,oname).start()
## @}

View File

@@ -713,3 +713,36 @@ class InstallWorker(QtCore.QThread):
if bakdir:
shutil.rmtree(bakdir)
return translate("AddonsInstaller", "Successfully installed") + " " + zipurl
class CheckSingleWorker(QtCore.QThread):
"""Worker to check for updates for a single addon"""
updateAvailable = QtCore.Signal(bool)
def __init__(self, name):
QtCore.QThread.__init__(self)
self.name = name
def run(self):
try:
import git
except:
return
FreeCAD.Console.PrintLog("Checking for available updates of the "+name+" addon\n")
addondir = os.path.join(FreeCAD.getUserAppDataDir(),"Mod",name)
if os.path.exists(addondir):
if os.path.exists(addondir + os.sep + '.git'):
gitrepo = git.Git(addondir)
try:
gitrepo.fetch()
if "git pull" in gitrepo.status():
self.updateAvailable.emit(True)
return
except:
# can fail for any number of reasons, ex. not being online
pass
self.updateAvailable.emit(False)