AddonManager: update python source formatting
Update formatting in compliance with pep8 with the following exceptions: * truncate to 120 characters in line * prefer double quotes `"` to single quotes `'` in strings
This commit is contained in:
committed by
Yorik van Havre
parent
fc10827719
commit
dde64d4a0a
@@ -27,17 +27,40 @@ import shutil
|
||||
import stat
|
||||
import sys
|
||||
import tempfile
|
||||
import FreeCAD
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
import FreeCAD
|
||||
|
||||
import addonmanager_utilities as utils
|
||||
from addonmanager_utilities import translate # this needs to be as is for pylupdate
|
||||
from addonmanager_utilities import translate # this needs to be as is for pylupdate
|
||||
from addonmanager_macro import Macro
|
||||
|
||||
## @package AddonManager_workers
|
||||
have_git = False
|
||||
try:
|
||||
import git
|
||||
have_git = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
have_zip = False
|
||||
try:
|
||||
import zipfile
|
||||
have_zip = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
have_markdown = False
|
||||
try:
|
||||
import markdown
|
||||
have_markdown = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# @package AddonManager_workers
|
||||
# \ingroup ADDONMANAGER
|
||||
# \brief Multithread workers for the addon manager
|
||||
# @{
|
||||
|
||||
# Blacklisted addons
|
||||
macros_blacklist = []
|
||||
@@ -48,9 +71,9 @@ obsolete = []
|
||||
# These addons will print an additional message informing the user Python2 only
|
||||
py2only = []
|
||||
|
||||
NOGIT = False # for debugging purposes, set this to True to always use http downloads
|
||||
NOGIT = False # for debugging purposes, set this to True to always use http downloads
|
||||
|
||||
NOMARKDOWN = False # for debugging purposes, set this to True to disable Markdown lib
|
||||
NOMARKDOWN = False # for debugging purposes, set this to True to disable Markdown lib
|
||||
|
||||
"""Multithread workers for the Addon Manager"""
|
||||
|
||||
@@ -68,7 +91,6 @@ class UpdateWorker(QtCore.QThread):
|
||||
QtCore.QThread.__init__(self)
|
||||
|
||||
def run(self):
|
||||
|
||||
"populates the list of addons"
|
||||
|
||||
self.progressbar_show.emit(True)
|
||||
@@ -82,17 +104,17 @@ class UpdateWorker(QtCore.QThread):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
hit = re.findall(r'"obsolete"[^\{]*?{[^\{]*?"Mod":\[(?P<obsolete>[^\[\]]+?)\]}',
|
||||
p.replace('\n', '').replace(' ', ''))
|
||||
p.replace("\n", "").replace(" ", ""))
|
||||
if hit:
|
||||
obsolete = hit[0].replace('"', '').split(',')
|
||||
obsolete = hit[0].replace('"', "").split(",")
|
||||
hit = re.findall(r'"blacklisted"[^\{]*?{[^\{]*?"Macro":\[(?P<blacklisted>[^\[\]]+?)\]}',
|
||||
p.replace('\n', '').replace(' ', ''))
|
||||
p.replace("\n", "").replace(" ", ""))
|
||||
if hit:
|
||||
macros_blacklist = hit[0].replace('"', '').split(',')
|
||||
macros_blacklist = hit[0].replace('"', "").split(",")
|
||||
hit = re.findall(r'"py2only"[^\{]*?{[^\{]*?"Mod":\[(?P<py2only>[^\[\]]+?)\]}',
|
||||
p.replace('\n', '').replace(' ', ''))
|
||||
p.replace("\n", "").replace(" ", ""))
|
||||
if hit:
|
||||
py2only = hit[0].replace('"', '').split(',')
|
||||
py2only = hit[0].replace('"', "").split(",")
|
||||
else:
|
||||
print("Debug: addon_flags.json not found")
|
||||
|
||||
@@ -106,7 +128,7 @@ class UpdateWorker(QtCore.QThread):
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
p = re.findall((r"(?m)\[submodule\s*\"(?P<name>.*)\"\]\s*"
|
||||
p = re.findall((r'(?m)\[submodule\s*"(?P<name>.*)"\]\s*'
|
||||
r"path\s*=\s*(?P<path>.+)\s*"
|
||||
r"url\s*=\s*(?P<url>https?://.*)"), p)
|
||||
basedir = FreeCAD.getUserAppDataDir()
|
||||
@@ -124,7 +146,8 @@ class UpdateWorker(QtCore.QThread):
|
||||
state = 0
|
||||
repos.append([name, url, state])
|
||||
# querying custom addons
|
||||
customaddons = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons").GetString("CustomRepositories","").split("\n")
|
||||
customaddons = (FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Addons")
|
||||
.GetString("CustomRepositories", "").split("\n"))
|
||||
for url in customaddons:
|
||||
if url:
|
||||
name = url.split("/")[-1]
|
||||
@@ -135,7 +158,7 @@ class UpdateWorker(QtCore.QThread):
|
||||
state = 0
|
||||
else:
|
||||
state = 1
|
||||
repos.append([name,url,state])
|
||||
repos.append([name, url, state])
|
||||
if not repos:
|
||||
self.info_label.emit(translate("AddonsInstaller", "Unable to download addon list."))
|
||||
else:
|
||||
@@ -170,7 +193,7 @@ class InfoWorker(QtCore.QThread):
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
desc = re.findall("<meta property=\"og:description\" content=\"(.*?)\"",p)
|
||||
desc = re.findall('<meta property="og:description" content="(.*?)"', p)
|
||||
if desc:
|
||||
desc = desc[0]
|
||||
else:
|
||||
@@ -188,19 +211,14 @@ class CheckWBWorker(QtCore.QThread):
|
||||
mark = QtCore.Signal(str)
|
||||
addon_repos = QtCore.Signal(object)
|
||||
|
||||
def __init__(self,repos):
|
||||
def __init__(self, repos):
|
||||
|
||||
QtCore.QThread.__init__(self)
|
||||
self.repos = repos
|
||||
|
||||
def run(self):
|
||||
|
||||
if NOGIT:
|
||||
self.stop = True
|
||||
return
|
||||
try:
|
||||
import git
|
||||
except:
|
||||
if NOGIT or not have_git:
|
||||
self.stop = True
|
||||
return
|
||||
basedir = FreeCAD.getUserAppDataDir()
|
||||
@@ -208,36 +226,40 @@ class CheckWBWorker(QtCore.QThread):
|
||||
upds = []
|
||||
gitpython_warning = False
|
||||
for repo in self.repos:
|
||||
if repo[2] == 1: #installed
|
||||
#print("Checking for updates for",repo[0])
|
||||
if repo[2] == 1: # installed
|
||||
# print("Checking for updates for", repo[0])
|
||||
clonedir = moddir + os.sep + repo[0]
|
||||
if os.path.exists(clonedir):
|
||||
self.repos[self.repos.index(repo)][2] = 2 # mark as already installed AND already checked for updates
|
||||
if not os.path.exists(clonedir + os.sep + '.git'):
|
||||
# mark as already installed AND already checked for updates
|
||||
self.repos[self.repos.index(repo)][2] = 2
|
||||
if not os.path.exists(clonedir + os.sep + ".git"):
|
||||
# Repair addon installed with raw download
|
||||
bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + '.git', bare=True)
|
||||
bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + ".git", bare=True)
|
||||
try:
|
||||
with bare_repo.config_writer() as cw:
|
||||
cw.set('core', 'bare', False)
|
||||
cw.set("core", "bare", False)
|
||||
except AttributeError:
|
||||
if not gitpython_warning:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.")+"\n")
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"Outdated GitPython detected, "
|
||||
"consider upgrading with pip.") + "\n")
|
||||
gitpython_warning = True
|
||||
cw = bare_repo.config_writer()
|
||||
cw.set('core', 'bare', False)
|
||||
cw.set("core", "bare", False)
|
||||
del cw
|
||||
repo = git.Repo(clonedir)
|
||||
repo.head.reset('--hard')
|
||||
repo.head.reset("--hard")
|
||||
gitrepo = git.Git(clonedir)
|
||||
try:
|
||||
gitrepo.fetch()
|
||||
except:
|
||||
print("AddonManager: Unable to fetch git updates for repo",repo[0])
|
||||
except Exception:
|
||||
print("AddonManager: Unable to fetch git updates for repo", repo[0])
|
||||
else:
|
||||
if "git pull" in gitrepo.status():
|
||||
self.mark.emit(repo[0])
|
||||
upds.append(repo[0])
|
||||
self.repos[self.repos.index(repo)][2] = 3 # mark as already installed AND already checked for updates AND update available
|
||||
# mark as already installed AND already checked for updates AND update available
|
||||
self.repos[self.repos.index(repo)][2] = 3
|
||||
self.addon_repos.emit(self.repos)
|
||||
self.enable.emit(len(upds))
|
||||
self.stop = True
|
||||
@@ -257,49 +279,47 @@ class FillMacroListWorker(QtCore.QThread):
|
||||
self.macros = []
|
||||
|
||||
def run(self):
|
||||
|
||||
"""Populates the list of macros"""
|
||||
|
||||
self.retrieve_macros_from_git()
|
||||
self.retrieve_macros_from_wiki()
|
||||
[self.add_macro_signal.emit(m) for m in sorted(self.macros, key=lambda m: m.name.lower())]
|
||||
if self.macros:
|
||||
self.info_label_signal.emit(translate('AddonsInstaller', 'List of macros successfully retrieved.'))
|
||||
self.info_label_signal.emit(translate("AddonsInstaller", "List of macros successfully retrieved."))
|
||||
self.progressbar_show.emit(False)
|
||||
self.stop = True
|
||||
|
||||
def retrieve_macros_from_git(self):
|
||||
|
||||
"""Retrieve macros from FreeCAD-macros.git
|
||||
|
||||
Emits a signal for each macro in
|
||||
https://github.com/FreeCAD/FreeCAD-macros.git
|
||||
"""
|
||||
|
||||
try:
|
||||
import git
|
||||
except ImportError:
|
||||
if not have_git:
|
||||
self.info_label_signal.emit("GitPython not installed! Cannot retrieve macros from Git")
|
||||
FreeCAD.Console.PrintWarning(translate('AddonsInstaller', 'GitPython not installed! Cannot retrieve macros from git')+"\n")
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"GitPython not installed! Cannot retrieve macros from git")+"\n")
|
||||
return
|
||||
|
||||
self.info_label_signal.emit('Downloading list of macros from git...')
|
||||
self.info_label_signal.emit("Downloading list of macros from git...")
|
||||
try:
|
||||
git.Repo.clone_from('https://github.com/FreeCAD/FreeCAD-macros.git', self.repo_dir)
|
||||
except:
|
||||
FreeCAD.Console.PrintWarning(translate('AddonsInstaller', 'Something went wrong with the Git Macro Retrieval, possibly the Git executable is not in the path')+"\n")
|
||||
git.Repo.clone_from("https://github.com/FreeCAD/FreeCAD-macros.git", self.repo_dir)
|
||||
except Exception:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"Something went wrong with the Git Macro Retrieval, "
|
||||
"possibly the Git executable is not in the path") + "\n")
|
||||
for dirpath, _, filenames in os.walk(self.repo_dir):
|
||||
if '.git' in dirpath:
|
||||
continue
|
||||
for filename in filenames:
|
||||
if filename.lower().endswith('.fcmacro'):
|
||||
if ".git" in dirpath:
|
||||
continue
|
||||
for filename in filenames:
|
||||
if filename.lower().endswith(".fcmacro"):
|
||||
macro = Macro(filename[:-8]) # Remove ".FCMacro".
|
||||
macro.on_git = True
|
||||
macro.src_filename = os.path.join(dirpath, filename)
|
||||
self.macros.append(macro)
|
||||
|
||||
def retrieve_macros_from_wiki(self):
|
||||
|
||||
"""Retrieve macros from the wiki
|
||||
|
||||
Read the wiki and emit a signal for each found macro.
|
||||
@@ -310,18 +330,20 @@ class FillMacroListWorker(QtCore.QThread):
|
||||
self.progressbar_show.emit(True)
|
||||
u = utils.urlopen("https://www.freecadweb.org/wiki/Macros_recipes")
|
||||
if not u:
|
||||
FreeCAD.Console.PrintWarning(translate('AddonsInstaller', 'Appears to be an issue connecting to the Wiki, therefore cannot retrieve Wiki macro list at this time')+"\n")
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"Appears to be an issue connecting to the Wiki, "
|
||||
"therefore cannot retrieve Wiki macro list at this time") + "\n")
|
||||
return
|
||||
p = u.read()
|
||||
u.close()
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
macros = re.findall('title="(Macro.*?)"', p)
|
||||
macros = [mac for mac in macros if ('translated' not in mac)]
|
||||
macros = [mac for mac in macros if ("translated" not in mac)]
|
||||
for mac in macros:
|
||||
macname = mac[6:] # Remove "Macro ".
|
||||
macname = macname.replace("&","&")
|
||||
if (macname not in macros_blacklist) and ('recipes' not in macname.lower()):
|
||||
macname = macname.replace("&", "&")
|
||||
if (macname not in macros_blacklist) and ("recipes" not in macname.lower()):
|
||||
macro = Macro(macname)
|
||||
macro.on_wiki = True
|
||||
self.macros.append(macro)
|
||||
@@ -336,7 +358,7 @@ class ShowWorker(QtCore.QThread):
|
||||
|
||||
def __init__(self, repos, idx):
|
||||
|
||||
# repos is a list of [name,url,installbit,descr]
|
||||
# repos is a list of [name, url, installbit, descr]
|
||||
# name : Addon name
|
||||
# url : Addon repository location
|
||||
# installbit: 0 = Addon is not installed
|
||||
@@ -358,51 +380,54 @@ class ShowWorker(QtCore.QThread):
|
||||
else:
|
||||
u = None
|
||||
url = self.repos[self.idx][1]
|
||||
self.info_label.emit(translate("AddonsInstaller", "Retrieving info from") + ' ' + str(url))
|
||||
self.info_label.emit(translate("AddonsInstaller", "Retrieving info from") + " " + str(url))
|
||||
desc = ""
|
||||
regex = utils.getReadmeRegex(url)
|
||||
regex = utils.get_readme_regex(url)
|
||||
if regex:
|
||||
# extract readme from html via regex
|
||||
readmeurl = utils.getReadmeHTMLUrl(url)
|
||||
readmeurl = utils.get_readme_html_url(url)
|
||||
if not readmeurl:
|
||||
print("Debug: README not found for",url)
|
||||
print("Debug: README not found for", url)
|
||||
u = utils.urlopen(readmeurl)
|
||||
if not u:
|
||||
print("Debug: README not found at",readmeurl)
|
||||
print("Debug: README not found at", readmeurl)
|
||||
u = utils.urlopen(readmeurl)
|
||||
if u:
|
||||
p = u.read()
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
readme = re.findall(regex,p,flags=re.MULTILINE|re.DOTALL)
|
||||
readme = re.findall(regex, p, flags=re.MULTILINE | re.DOTALL)
|
||||
if readme:
|
||||
desc = readme[0]
|
||||
else:
|
||||
print("Debug: README not found at",readmeurl)
|
||||
print("Debug: README not found at", readmeurl)
|
||||
else:
|
||||
# convert raw markdown using lib
|
||||
readmeurl = utils.getReadmeUrl(url)
|
||||
readmeurl = utils.get_readme_url(url)
|
||||
if not readmeurl:
|
||||
print("Debug: README not found for",url)
|
||||
print("Debug: README not found for", url)
|
||||
u = utils.urlopen(readmeurl)
|
||||
if u:
|
||||
p = u.read()
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
desc = utils.fixRelativeLinks(p,readmeurl.rsplit("/README.md")[0])
|
||||
try:
|
||||
if NOMARKDOWN:
|
||||
raise ImportError
|
||||
import markdown # try to use system Markdown lib
|
||||
desc = markdown.markdown(desc,extensions=['md_in_html'])
|
||||
except ImportError:
|
||||
message = " <div style=\"width: 100%; text-align:center; background: #91bbe0;\"><strong style=\"color: #FFFFFF;\">"+translate("AddonsInstaller","Raw markdown displayed")+"</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller","Python Markdown library is missing.")+"<br/></div><hr/><pre>" + desc + "</pre>"
|
||||
desc = utils.fix_relative_links(p, readmeurl.rsplit("/README.md")[0])
|
||||
if NOMARKDOWN or not have_markdown:
|
||||
desc = markdown.markdown(desc, extensions=["md_in_html"])
|
||||
else:
|
||||
message = """
|
||||
<div style="width: 100%; text-align:center;background: #91bbe0;">
|
||||
<strong style="color: #FFFFFF;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "Raw markdown displayed")
|
||||
message += "</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller", "Python Markdown library is missing.")
|
||||
message += "<br/></div><hr/><pre>" + desc + "</pre>"
|
||||
desc = message
|
||||
else:
|
||||
print("Debug: README not found at",readmeurl)
|
||||
print("Debug: README not found at", readmeurl)
|
||||
if desc == "":
|
||||
# fall back to the description text
|
||||
u = utils.urlopen(url)
|
||||
@@ -414,9 +439,9 @@ class ShowWorker(QtCore.QThread):
|
||||
if sys.version_info.major >= 3 and isinstance(p, bytes):
|
||||
p = p.decode("utf-8")
|
||||
u.close()
|
||||
descregex = utils.getDescRegex(url)
|
||||
descregex = utils.get_desc_regex(url)
|
||||
if descregex:
|
||||
desc = re.findall(descregex,p)
|
||||
desc = re.findall(descregex, p)
|
||||
if desc:
|
||||
desc = desc[0]
|
||||
if not desc:
|
||||
@@ -427,92 +452,133 @@ class ShowWorker(QtCore.QThread):
|
||||
if self.repos[self.idx][2] == 1:
|
||||
upd = False
|
||||
# checking for updates
|
||||
if not NOGIT:
|
||||
try:
|
||||
import git
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
repo = self.repos[self.idx]
|
||||
clonedir = FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + repo[0]
|
||||
if os.path.exists(clonedir):
|
||||
if not os.path.exists(clonedir + os.sep + '.git'):
|
||||
# Repair addon installed with raw download
|
||||
bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + '.git', bare=True)
|
||||
try:
|
||||
with bare_repo.config_writer() as cw:
|
||||
cw.set('core', 'bare', False)
|
||||
except AttributeError:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.")+"\n")
|
||||
cw = bare_repo.config_writer()
|
||||
cw.set('core', 'bare', False)
|
||||
del cw
|
||||
repo = git.Repo(clonedir)
|
||||
repo.head.reset('--hard')
|
||||
gitrepo = git.Git(clonedir)
|
||||
gitrepo.fetch()
|
||||
if "git pull" in gitrepo.status():
|
||||
upd = True
|
||||
if not NOGIT and have_git:
|
||||
repo = self.repos[self.idx]
|
||||
clonedir = FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + repo[0]
|
||||
if os.path.exists(clonedir):
|
||||
if not os.path.exists(clonedir + os.sep + ".git"):
|
||||
# Repair addon installed with raw download
|
||||
bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + ".git", bare=True)
|
||||
try:
|
||||
with bare_repo.config_writer() as cw:
|
||||
cw.set("core", "bare", False)
|
||||
except AttributeError:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"Outdated GitPython detected, "
|
||||
"consider upgrading with pip.") + "\n")
|
||||
cw = bare_repo.config_writer()
|
||||
cw.set("core", "bare", False)
|
||||
del cw
|
||||
repo = git.Repo(clonedir)
|
||||
repo.head.reset("--hard")
|
||||
gitrepo = git.Git(clonedir)
|
||||
gitrepo.fetch()
|
||||
if "git pull" in gitrepo.status():
|
||||
upd = True
|
||||
# If there is an update pending, lets user know via the UI
|
||||
if upd:
|
||||
message = "<div style=\"width: 100%;text-align: center;background: #75AFFD;\"><br/><strong style=\"background: #397FF7;color: #FFFFFF;\">" + translate("AddonsInstaller", "An update is available for this addon.")
|
||||
message += "</strong><br/></div><hr/>" + desc + '<br/><br/>Addon repository: <a href="' + self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
self.repos[self.idx][2] = 3 # mark as already installed AND already checked for updates AND update is available
|
||||
message = """
|
||||
<div style="width: 100%;text-align: center;background: #75AFFD;">
|
||||
<br/>
|
||||
<strong style="background: #397FF7;color: #FFFFFF;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "An update is available for this addon.")
|
||||
message += "</strong><br/></div><hr/>" + desc + '<br/><br/>Addon repository: <a href="'
|
||||
message += self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + "</a>"
|
||||
# mark as already installed AND already checked for updates AND update is available
|
||||
self.repos[self.idx][2] = 3
|
||||
# If there isn't, indicate that this addon is already installed
|
||||
else:
|
||||
message = "<div style=\"width: 100%;text-align: center;background: #C1FEB2;\"><br/><strong style=\"background: #00B629;color: #FFFFFF;\">" + translate("AddonsInstaller", "This addon is already installed.") + "</strong><br/></div><hr/>"
|
||||
message += desc + '<br/><br/>Addon repository: <a href="' + self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
self.repos[self.idx][2] = 2 # mark as already installed AND already checked for updates
|
||||
message = """
|
||||
<div style="width: 100%;text-align: center;background: #C1FEB2;">
|
||||
<br/>
|
||||
<strong style="background: #00B629;color: #FFFFFF;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "This addon is already installed.")
|
||||
message += "</strong><br/></div><hr/>" + desc
|
||||
message += '<br/><br/>Addon repository: <a href="'
|
||||
message += self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + "</a>"
|
||||
self.repos[self.idx][2] = 2 # mark as already installed AND already checked for updates
|
||||
# Let the user know the install path for this addon
|
||||
message += '<br/>' + translate("AddonInstaller","Installed location")+": "+ FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
message += "<br/>" + translate("AddonInstaller", "Installed location") + ": "
|
||||
message += FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
self.addon_repos.emit(self.repos)
|
||||
elif self.repos[self.idx][2] == 2:
|
||||
message = "<div style=\"width: 100%;text-align: center;background: #C1FEB2;\"><br/><strong style=\"background: #00B629;color: #FFFFFF;\">" + translate("AddonsInstaller", "This addon is already installed.") + "</strong><br></div><hr/>"
|
||||
message += desc + '<br/><br/>Addon repository: <a href="' + self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
message += '<br/>' + translate("AddonInstaller","Installed location")+": "+ FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
message = """
|
||||
<div style="width: 100%;text-align: center;background: #C1FEB2;">
|
||||
<br/>
|
||||
<strong style="background: #00B629;color: #FFFFFF;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "This addon is already installed.")
|
||||
message += "</strong><br></div><hr/>" + desc
|
||||
message += '<br/><br/>Addon repository: <a href="'
|
||||
message += self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + "</a>"
|
||||
message += "<br/>" + translate("AddonInstaller", "Installed location") + ": "
|
||||
message += FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
elif self.repos[self.idx][2] == 3:
|
||||
message = "<div style=\"width: 100%;text-align: center;background: #75AFFD;\"><br/><strong style=\"background: #397FF7;color: #FFFFFF;\">" + translate("AddonsInstaller", "An update is available for this addon.")
|
||||
message += "</strong><br/></div><hr/>" + desc + '<br/><br/>Addon repository: <a href="' + self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
message += '<br/>' + translate("AddonInstaller","Installed location")+": "+ FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
message = """
|
||||
<div style="width: 100%;text-align: center;background: #75AFFD;">
|
||||
<br/>
|
||||
<strong style="background: #397FF7;color: #FFFFFF;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "An update is available for this addon.")
|
||||
message += "</strong><br/></div><hr/>" + desc + '<br/><br/>Addon repository: <a href="'
|
||||
message += self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + "</a>"
|
||||
message += "<br/>" + translate("AddonInstaller", "Installed location") + ": "
|
||||
message += FreeCAD.getUserAppDataDir() + os.sep + "Mod" + os.sep + self.repos[self.idx][0]
|
||||
else:
|
||||
message = desc + '<br/><br/>Addon repository: <a href="' + self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
message = desc + '<br/><br/>Addon repository: <a href="'
|
||||
message += self.repos[self.idx][1] + '">' + self.repos[self.idx][1] + '</a>'
|
||||
|
||||
# If the Addon is obsolete, let the user know through the Addon UI
|
||||
if self.repos[self.idx][0] in obsolete:
|
||||
message = " <div style=\"width: 100%; text-align:center; background: #FFB3B3;\"><strong style=\"color: #FFFFFF; background: #FF0000;\">"+translate("AddonsInstaller","This addon is marked as obsolete")+"</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller","This usually means it is no longer maintained, and some more advanced addon in this list provides the same functionality.")+"<br/></div><hr/>" + desc
|
||||
message = """
|
||||
<div style="width: 100%; text-align:center; background: #FFB3B3;">
|
||||
<strong style="color: #FFFFFF; background: #FF0000;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "This addon is marked as obsolete") + "</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller",
|
||||
"This usually means it is no longer maintained, "
|
||||
"and some more advanced addon in this list "
|
||||
"provides the same functionality.") + "<br/></div><hr/>" + desc
|
||||
|
||||
# If the Addon is Python 2 only, let the user know through the Addon UI
|
||||
if self.repos[self.idx][0] in py2only:
|
||||
message = " <div style=\"width: 100%; text-align:center; background: #ffe9b3;\"><strong style=\"color: #FFFFFF; background: #ff8000;\">"+translate("AddonsInstaller","This addon is marked as Python 2 Only")+"</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller","This workbench may no longer be maintained and installing it on a Python 3 system will more than likely result in errors at startup or while in use.")+"<br/></div><hr/>" + desc
|
||||
message = """
|
||||
<div style="width: 100%; text-align:center; background: #ffe9b3;">
|
||||
<strong style="color: #FFFFFF; background: #ff8000;">
|
||||
"""
|
||||
message += translate("AddonsInstaller", "This addon is marked as Python 2 Only") + "</strong><br/><br/>"
|
||||
message += translate("AddonsInstaller",
|
||||
"This workbench may no longer be maintained and "
|
||||
"installing it on a Python 3 system will more than "
|
||||
"likely result in errors at startup or while in use.")
|
||||
message += "<br/></div><hr/>" + desc
|
||||
|
||||
self.info_label.emit( message )
|
||||
self.info_label.emit(message)
|
||||
self.progressbar_show.emit(False)
|
||||
self.mustLoadImages = True
|
||||
l = self.loadImages( message, self.repos[self.idx][1], self.repos[self.idx][0])
|
||||
if l:
|
||||
self.info_label.emit( l )
|
||||
label = self.loadImages(message, self.repos[self.idx][1], self.repos[self.idx][0])
|
||||
if label:
|
||||
self.info_label.emit(label)
|
||||
self.stop = True
|
||||
|
||||
def stopImageLoading(self):
|
||||
|
||||
"this stops the image loading process and allow the thread to terminate earlier"
|
||||
|
||||
self.mustLoadImages = False
|
||||
|
||||
def loadImages(self,message,url,wbName):
|
||||
|
||||
def loadImages(self, message, url, wbName):
|
||||
"checks if the given page contains images and downloads them"
|
||||
|
||||
# QTextBrowser cannot display online images. So we download them
|
||||
# here, and replace the image link in the html code with the
|
||||
# downloaded version
|
||||
|
||||
imagepaths = re.findall("<img.*?src=\"(.*?)\"",message)
|
||||
imagepaths = re.findall("<img.*?src=\"(.*?)\"", message)
|
||||
if imagepaths:
|
||||
storedimages = []
|
||||
store = os.path.join(FreeCAD.getUserAppDataDir(),"AddonManager","Images")
|
||||
store = os.path.join(FreeCAD.getUserAppDataDir(), "AddonManager", "Images")
|
||||
if not os.path.exists(store):
|
||||
os.makedirs(store)
|
||||
for path in imagepaths:
|
||||
@@ -526,38 +592,37 @@ class ShowWorker(QtCore.QThread):
|
||||
path = utils.getserver(url) + path
|
||||
name = path.split("/")[-1]
|
||||
if name and path.startswith("http"):
|
||||
storename = os.path.join(store,name)
|
||||
storename = os.path.join(store, name)
|
||||
if len(storename) >= 260:
|
||||
remainChars = 259 - (len(store) + len(wbName) + 1)
|
||||
storename = os.path.join(store,wbName+name[-remainChars:])
|
||||
storename = os.path.join(store, wbName+name[-remainChars:])
|
||||
if not os.path.exists(storename):
|
||||
try:
|
||||
u = utils.urlopen(path)
|
||||
imagedata = u.read()
|
||||
u.close()
|
||||
except:
|
||||
print("AddonManager: Debug: Error retrieving image from",path)
|
||||
except Exception:
|
||||
print("AddonManager: Debug: Error retrieving image from", path)
|
||||
else:
|
||||
f = open(storename,"wb")
|
||||
f = open(storename, "wb")
|
||||
f.write(imagedata)
|
||||
f.close()
|
||||
|
||||
# resize the image to 300x300px if needed
|
||||
from PySide import QtCore,QtGui
|
||||
img = QtGui.QImage(storename)
|
||||
if (img.width() > 300) or (img.height() > 300):
|
||||
pix = QtGui.QPixmap()
|
||||
pix = pix.fromImage(img.scaled(300,300,QtCore.Qt.KeepAspectRatio,QtCore.Qt.FastTransformation))
|
||||
pix.save(storename, "jpeg",100)
|
||||
message = message.replace("src=\""+origpath,"src=\"file:///"+storename.replace("\\","/"))
|
||||
#print(message)
|
||||
pix = pix.fromImage(img.scaled(300, 300,
|
||||
QtCore.Qt.KeepAspectRatio,
|
||||
QtCore.Qt.FastTransformation))
|
||||
pix.save(storename, "jpeg", 100)
|
||||
message = message.replace("src=\""+origpath, "src=\"file:///"+storename.replace("\\", "/"))
|
||||
# print(message)
|
||||
return message
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class GetMacroDetailsWorker(QtCore.QThread):
|
||||
|
||||
"""Retrieve the macro details for a macro"""
|
||||
|
||||
info_label = QtCore.Signal(str)
|
||||
@@ -573,36 +638,35 @@ class GetMacroDetailsWorker(QtCore.QThread):
|
||||
self.progressbar_show.emit(True)
|
||||
self.info_label.emit(translate("AddonsInstaller", "Retrieving description..."))
|
||||
if not self.macro.parsed and self.macro.on_git:
|
||||
self.info_label.emit(translate('AddonsInstaller', 'Retrieving info from git'))
|
||||
self.info_label.emit(translate("AddonsInstaller", "Retrieving info from git"))
|
||||
self.macro.fill_details_from_file(self.macro.src_filename)
|
||||
if not self.macro.parsed and self.macro.on_wiki:
|
||||
self.info_label.emit(translate('AddonsInstaller', 'Retrieving info from wiki'))
|
||||
mac = self.macro.name.replace(' ', '_')
|
||||
mac = mac.replace('&', '%26')
|
||||
mac = mac.replace('+', '%2B')
|
||||
url = 'https://www.freecadweb.org/wiki/Macro_' + mac
|
||||
self.info_label.emit(translate("AddonsInstaller", "Retrieving info from wiki"))
|
||||
mac = self.macro.name.replace(" ", "_")
|
||||
mac = mac.replace("&", "%26")
|
||||
mac = mac.replace("+", "%2B")
|
||||
url = "https://www.freecadweb.org/wiki/Macro_" + mac
|
||||
self.macro.fill_details_from_wiki(url)
|
||||
if self.macro.is_installed():
|
||||
already_installed_msg = ('<strong style=\"background: #00B629;\">'
|
||||
+ translate("AddonsInstaller", "This macro is already installed.")
|
||||
+ '</strong><br>')
|
||||
+ translate("AddonsInstaller", "This macro is already installed.")
|
||||
+ '</strong><br>')
|
||||
else:
|
||||
already_installed_msg = ''
|
||||
already_installed_msg = ""
|
||||
message = (already_installed_msg
|
||||
+ "<h1>"+self.macro.name+"</h1>"
|
||||
+ self.macro.desc
|
||||
+ '<br/><br/>Macro location: <a href="'
|
||||
+ self.macro.url
|
||||
+ '">'
|
||||
+ self.macro.url
|
||||
+ '</a>')
|
||||
+ "<h1>"+self.macro.name+"</h1>"
|
||||
+ self.macro.desc
|
||||
+ "<br/><br/>Macro location: <a href=\""
|
||||
+ self.macro.url
|
||||
+ "\">"
|
||||
+ self.macro.url
|
||||
+ "</a>")
|
||||
self.info_label.emit(message)
|
||||
self.progressbar_show.emit(False)
|
||||
self.stop = True
|
||||
|
||||
|
||||
class InstallWorker(QtCore.QThread):
|
||||
|
||||
"This worker installs a workbench"
|
||||
|
||||
info_label = QtCore.Signal(str)
|
||||
@@ -616,35 +680,26 @@ class InstallWorker(QtCore.QThread):
|
||||
self.repos = repos
|
||||
|
||||
def run(self):
|
||||
|
||||
"installs or updates the selected addon"
|
||||
|
||||
git = None
|
||||
try:
|
||||
import git
|
||||
except Exception as e:
|
||||
if not have_git:
|
||||
self.info_label.emit("GitPython not found.")
|
||||
print(e)
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller","GitPython not found. Using standard download instead.")+"\n")
|
||||
try:
|
||||
import zipfile
|
||||
except:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"GitPython not found. Using standard download instead.") + "\n")
|
||||
if not have_zip:
|
||||
self.info_label.emit("no zip support.")
|
||||
FreeCAD.Console.PrintError(translate("AddonsInstaller","Your version of python doesn't appear to support ZIP files. Unable to proceed.")+"\n")
|
||||
FreeCAD.Console.PrintError(translate("AddonsInstaller",
|
||||
"Your version of python doesn't appear to support ZIP "
|
||||
"files. Unable to proceed.") + "\n")
|
||||
return
|
||||
try:
|
||||
import StringIO as io
|
||||
except ImportError: # StringIO is not available with python3
|
||||
import io
|
||||
if not isinstance(self.idx,list):
|
||||
|
||||
if not isinstance(self.idx, list):
|
||||
self.idx = [self.idx]
|
||||
for idx in self.idx:
|
||||
if idx < 0:
|
||||
return
|
||||
if not self.repos:
|
||||
return
|
||||
if NOGIT:
|
||||
git = None
|
||||
basedir = FreeCAD.getUserAppDataDir()
|
||||
moddir = basedir + os.sep + "Mod"
|
||||
if not os.path.exists(moddir):
|
||||
@@ -654,26 +709,33 @@ class InstallWorker(QtCore.QThread):
|
||||
if os.path.exists(clonedir):
|
||||
self.info_label.emit("Updating module...")
|
||||
if sys.version_info.major > 2 and str(self.repos[idx][0]) in py2only:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "User requested updating a Python 2 workbench on a system running Python 3 - ")+str(self.repos[idx][0])+"\n")
|
||||
if git:
|
||||
if not os.path.exists(clonedir + os.sep + '.git'):
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"User requested updating a Python 2 workbench on "
|
||||
"a system running Python 3 - ") +
|
||||
str(self.repos[idx][0])+"\n")
|
||||
if have_git:
|
||||
if not os.path.exists(clonedir + os.sep + ".git"):
|
||||
# Repair addon installed with raw download
|
||||
bare_repo = git.Repo.clone_from(self.repos[idx][1], clonedir + os.sep + '.git', bare=True)
|
||||
bare_repo = git.Repo.clone_from(self.repos[idx][1], clonedir + os.sep + ".git", bare=True)
|
||||
try:
|
||||
with bare_repo.config_writer() as cw:
|
||||
cw.set('core', 'bare', False)
|
||||
cw.set("core", "bare", False)
|
||||
except AttributeError:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.")+"\n")
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"Outdated GitPython detected, consider "
|
||||
"upgrading with pip.") + "\n")
|
||||
cw = bare_repo.config_writer()
|
||||
cw.set('core', 'bare', False)
|
||||
cw.set("core", "bare", False)
|
||||
del cw
|
||||
repo = git.Repo(clonedir)
|
||||
repo.head.reset('--hard')
|
||||
repo.head.reset("--hard")
|
||||
repo = git.Git(clonedir)
|
||||
try:
|
||||
answer = repo.pull() + "\n\n" + translate("AddonsInstaller", "Workbench successfully updated. Please restart FreeCAD to apply the changes.")
|
||||
except:
|
||||
print("Error updating module",self.repos[idx][1]," - Please fix manually")
|
||||
answer = repo.pull() + "\n\n" + translate("AddonsInstaller",
|
||||
"Workbench successfully updated. "
|
||||
"Please restart FreeCAD to apply the changes.")
|
||||
except Exception:
|
||||
print("Error updating module", self.repos[idx][1], " - Please fix manually")
|
||||
answer = repo.status()
|
||||
print(answer)
|
||||
else:
|
||||
@@ -682,24 +744,32 @@ class InstallWorker(QtCore.QThread):
|
||||
for submodule in repo_sms.submodules:
|
||||
submodule.update(init=True, recursive=True)
|
||||
else:
|
||||
answer = self.download(self.repos[idx][1],clonedir) + "\n\n" + translate("AddonsInstaller", "Workbench successfully updated. Please restart FreeCAD to apply the changes.")
|
||||
answer = self.download(self.repos[idx][1], clonedir) + "\n\n"
|
||||
answer += translate("AddonsInstaller",
|
||||
"Workbench successfully updated. Please "
|
||||
"restart FreeCAD to apply the changes.")
|
||||
else:
|
||||
self.info_label.emit("Checking module dependencies...")
|
||||
depsok,answer = self.checkDependencies(self.repos[idx][1])
|
||||
depsok, answer = self.check_dependencies(self.repos[idx][1])
|
||||
if depsok:
|
||||
if sys.version_info.major > 2 and str(self.repos[idx][0]) in py2only:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "User requested installing a Python 2 workbench on a system running Python 3 - ")+str(self.repos[idx][0])+"\n")
|
||||
if git:
|
||||
FreeCAD.Console.PrintWarning(translate("AddonsInstaller",
|
||||
"User requested installing a Python 2 "
|
||||
"workbench on a system running Python 3 - ") +
|
||||
str(self.repos[idx][0]) + "\n")
|
||||
if have_git:
|
||||
self.info_label.emit("Cloning module...")
|
||||
repo = git.Repo.clone_from(self.repos[idx][1], clonedir, branch='master')
|
||||
repo = git.Repo.clone_from(self.repos[idx][1], clonedir, branch="master")
|
||||
|
||||
# Make sure to clone all the submodules as well
|
||||
if repo.submodules:
|
||||
repo.submodule_update(recursive=True)
|
||||
else:
|
||||
self.info_label.emit("Downloading module...")
|
||||
self.download(self.repos[idx][1],clonedir)
|
||||
answer = translate("AddonsInstaller", "Workbench successfully installed. Please restart FreeCAD to apply the changes.")
|
||||
self.download(self.repos[idx][1], clonedir)
|
||||
answer = translate("AddonsInstaller",
|
||||
"Workbench successfully installed. Please restart "
|
||||
"FreeCAD to apply the changes.")
|
||||
# symlink any macro contained in the module to the macros folder
|
||||
macro_dir = FreeCAD.getUserMacroDir(True)
|
||||
if not os.path.exists(macro_dir):
|
||||
@@ -707,24 +777,25 @@ class InstallWorker(QtCore.QThread):
|
||||
if os.path.exists(clonedir):
|
||||
for f in os.listdir(clonedir):
|
||||
if f.lower().endswith(".fcmacro"):
|
||||
print("copying macro:",f)
|
||||
print("copying macro:", f)
|
||||
utils.symlink(os.path.join(clonedir, f), os.path.join(macro_dir, f))
|
||||
FreeCAD.ParamGet('User parameter:Plugins/'+self.repos[idx][0]).SetString("destination",clonedir)
|
||||
answer += "\n\n"+translate("AddonsInstaller", "A macro has been installed and is available under Macro -> Macros menu")+":"
|
||||
answer += "\n<b>" + f + "</b>"
|
||||
FreeCAD.ParamGet('User parameter:Plugins/' +
|
||||
self.repos[idx][0]).SetString("destination", clonedir)
|
||||
answer += "\n\n" + translate("AddonsInstaller",
|
||||
"A macro has been installed and is available "
|
||||
"under Macro -> Macros menu")
|
||||
answer += ":\n<b>" + f + "</b>"
|
||||
self.progressbar_show.emit(False)
|
||||
self.info_label.emit(answer)
|
||||
self.mark_recompute.emit(self.repos[idx][0])
|
||||
self.stop = True
|
||||
|
||||
def checkDependencies(self,baseurl):
|
||||
|
||||
def check_dependencies(self, baseurl):
|
||||
"checks if the repo contains a metadata.txt and check its contents"
|
||||
|
||||
import FreeCADGui
|
||||
ok = True
|
||||
message = ""
|
||||
depsurl = baseurl.replace("github.com","raw.githubusercontent.com")
|
||||
depsurl = baseurl.replace("github.com", "raw.githubusercontent.com")
|
||||
if not depsurl.endswith("/"):
|
||||
depsurl += "/"
|
||||
depsurl += "master/metadata.txt"
|
||||
@@ -736,74 +807,69 @@ class InstallWorker(QtCore.QThread):
|
||||
|
||||
# urllib2 gives us a bytelike object instead of a string. Have to consider that
|
||||
try:
|
||||
depsfile = depsfile.decode('utf-8')
|
||||
depsfile = depsfile.decode("utf-8")
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
deps = depsfile.split("\n")
|
||||
for l in deps:
|
||||
if l.startswith("workbenches="):
|
||||
depswb = l.split("=")[1].split(",")
|
||||
for line in deps:
|
||||
if line.startswith("workbenches="):
|
||||
depswb = line.split("=")[1].split(",")
|
||||
for wb in depswb:
|
||||
if wb.strip():
|
||||
if not wb.strip() in FreeCADGui.listWorkbenches().keys():
|
||||
if not wb.strip()+"Workbench" in FreeCADGui.listWorkbenches().keys():
|
||||
ok = False
|
||||
message += translate("AddonsInstaller","Missing workbench") + ": " + wb + ", "
|
||||
elif l.startswith("pylibs="):
|
||||
depspy = l.split("=")[1].split(",")
|
||||
message += translate("AddonsInstaller", "Missing workbench") + ": " + wb + ", "
|
||||
elif line.startswith("pylibs="):
|
||||
depspy = line.split("=")[1].split(",")
|
||||
for pl in depspy:
|
||||
if pl.strip():
|
||||
try:
|
||||
__import__(pl.strip())
|
||||
except:
|
||||
except ImportError:
|
||||
ok = False
|
||||
message += translate("AddonsInstaller","Missing python module") +": " + pl + ", "
|
||||
elif l.startswith("optionalpylibs="):
|
||||
opspy = l.split("=")[1].split(",")
|
||||
message += translate("AddonsInstaller", "Missing python module") + ": " + pl + ", "
|
||||
elif line.startswith("optionalpylibs="):
|
||||
opspy = line.split("=")[1].split(",")
|
||||
for pl in opspy:
|
||||
if pl.strip():
|
||||
try:
|
||||
__import__(pl.strip())
|
||||
except:
|
||||
message += translate("AddonsInstaller","Missing optional python module (doesn't prevent installing)") +": " + pl + ", "
|
||||
except ImportError:
|
||||
message += translate("AddonsInstaller",
|
||||
"Missing optional python module (doesn't prevent installing)")
|
||||
message += ": " + pl + ", "
|
||||
if message and (not ok):
|
||||
message = translate("AddonsInstaller", "Some errors were found that prevent to install this workbench") + ": <b>" + message + "</b>. "
|
||||
message += translate("AddonsInstaller","Please install the missing components first.")
|
||||
message = translate("AddonsInstaller", "Some errors were found that prevent to install this workbench")
|
||||
message += ": <b>" + message + "</b>. "
|
||||
message += translate("AddonsInstaller", "Please install the missing components first.")
|
||||
return ok, message
|
||||
|
||||
def download(self,baseurl,clonedir):
|
||||
|
||||
def download(self, baseurl, clonedir):
|
||||
"downloads and unzip a zip version from a git repo"
|
||||
|
||||
import zipfile
|
||||
bakdir = None
|
||||
if os.path.exists(clonedir):
|
||||
bakdir = clonedir+".bak"
|
||||
if os.path.exists(bakdir):
|
||||
shutil.rmtree(bakdir)
|
||||
os.rename(clonedir,bakdir)
|
||||
os.rename(clonedir, bakdir)
|
||||
os.makedirs(clonedir)
|
||||
zipurl = utils.getZipUrl(baseurl)
|
||||
zipurl = utils.get_zip_url(baseurl)
|
||||
if not zipurl:
|
||||
return translate("AddonsInstaller", "Error: Unable to locate zip from") + " " + baseurl
|
||||
try:
|
||||
print("Downloading "+zipurl)
|
||||
u = utils.urlopen(zipurl)
|
||||
except:
|
||||
except Exception:
|
||||
return translate("AddonsInstaller", "Error: Unable to download") + " " + zipurl
|
||||
if not u:
|
||||
return translate("AddonsInstaller", "Error: Unable to download") + " " + zipurl
|
||||
if sys.version_info.major < 3:
|
||||
import StringIO as io
|
||||
_stringio = io.StringIO
|
||||
else:
|
||||
import io
|
||||
_stringio = io.BytesIO
|
||||
zfile = _stringio()
|
||||
zfile.write(u.read())
|
||||
zfile = zipfile.ZipFile(zfile)
|
||||
master = zfile.namelist()[0] # github will put everything in a subfolder
|
||||
master = zfile.namelist()[0] # github will put everything in a subfolder
|
||||
zfile.extractall(clonedir)
|
||||
u.close()
|
||||
zfile.close()
|
||||
@@ -816,7 +882,6 @@ class InstallWorker(QtCore.QThread):
|
||||
|
||||
|
||||
class CheckSingleWorker(QtCore.QThread):
|
||||
|
||||
"""Worker to check for updates for a single addon"""
|
||||
|
||||
updateAvailable = QtCore.Signal(bool)
|
||||
@@ -828,21 +893,21 @@ class CheckSingleWorker(QtCore.QThread):
|
||||
|
||||
def run(self):
|
||||
|
||||
try:
|
||||
import git
|
||||
except:
|
||||
if not have_git:
|
||||
return
|
||||
FreeCAD.Console.PrintLog("Checking for available updates of the "+self.name+" addon\n")
|
||||
addondir = os.path.join(FreeCAD.getUserAppDataDir(),"Mod",self.name)
|
||||
addondir = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", self.name)
|
||||
if os.path.exists(addondir):
|
||||
if os.path.exists(addondir + os.sep + '.git'):
|
||||
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:
|
||||
except Exception:
|
||||
# can fail for any number of reasons, ex. not being online
|
||||
pass
|
||||
self.updateAvailable.emit(False)
|
||||
|
||||
# @}
|
||||
|
||||
Reference in New Issue
Block a user