Skip to content

Commit

Permalink
[processing]download and store help files when downloading from scrip…
Browse files Browse the repository at this point in the history
…t/models repo

Fixes #11979
  • Loading branch information
volaya committed Jan 15, 2015
1 parent c54cd92 commit 908d6b3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Expand Up @@ -101,7 +101,7 @@ class GetScriptsAndModelsDialog(QDialog, Ui_DlgGetScriptsAndModels):
'<p>Algorithms are divided in 3 groups:</p>'
'<ul><li><b>Installed:</b> Algorithms already in your system, with '
'the latest version available</li>'
'<li><b>Upgradable:</b> Algorithms already in your system, but with '
'<li><b>Updatable:</b> Algorithms already in your system, but with '
'a newer version available in the server</li>'
'<li><b>Not installed:</b> Algorithms not installed in your '
'system</li></ul>')
Expand Down Expand Up @@ -139,6 +139,7 @@ def populateTree(self):
self.notinstalledItem.setIcon(0, self.icon)
resources = readUrl(self.urlBase + 'list.txt').splitlines()
resources = [r.split(',') for r in resources]
self.resources = {f:(v,n) for f,v,n in resources}
for filename, version, name in resources:
treeBranch = self.getTreeBranchForState(filename, float(version))
item = TreeItem(filename, name, self.icon)
Expand Down Expand Up @@ -177,8 +178,8 @@ def getTreeBranchForState(self, filename, version):
with open(helpFile) as f:
helpContent = json.load(f)
currentVersion = float(helpContent[Help2Html.ALG_VERSION])
except:
currentVersion = 1
except Exception:
currentVersion = 0
if version > currentVersion:
return self.toupdateItem
else:
Expand Down Expand Up @@ -209,12 +210,21 @@ def okPressed(self):
path = os.path.join(self.folder, filename)
with open(path, 'w') as f:
f.write(code)
self.progressBar.setValue(i + 1)
except HTTPError:
QMessageBox.critical(iface.mainWindow(),
self.tr('Connection problem'),
self.tr('Could not download file: %s') % filename)
return
url += '.help'
try:
html = readUrl(url)
except HTTPError:
html = '{"ALG_VERSION" : %s}' % self.resources[filename][0]

path = os.path.join(self.folder, filename + '.help')
with open(path, 'w') as f:
f.write(html)
self.progressBar.setValue(i + 1)


toDelete = []
Expand Down

0 comments on commit 908d6b3

Please sign in to comment.