Skip to content

Commit 6c9f7d7

Browse files
committed
[processing] helpfiles for scripts/models are now stored as json
1 parent ff24353 commit 6c9f7d7

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

python/plugins/processing/core/ProcessingLog.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
import os
2928
import re
3029
import codecs
3130
import datetime
32-
from PyQt4 import QtGui
3331
from processing.tools.system import *
3432
from processing.core.ProcessingConfig import ProcessingConfig
3533

python/plugins/processing/gui/Help2Html.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19-
import re
19+
2020

2121
__author__ = 'Victor Olaya'
2222
__date__ = 'August 2012'
@@ -26,10 +26,9 @@
2626

2727
__revision__ = '$Format:%H$'
2828

29-
import pickle
30-
from processing.tools.system import *
3129
import os
32-
import codecs
30+
import re
31+
import json
3332

3433
ALG_DESC = 'ALG_DESC'
3534
ALG_CREATOR = 'ALG_CREATOR'
@@ -58,8 +57,8 @@ def getHtmlFromHelpFile(alg, helpFile):
5857
if not os.path.exists(helpFile):
5958
return None
6059
alg = alg
61-
f = open(helpFile, 'rb')
62-
descriptions = pickle.load(f)
60+
with open(helpFile) as f:
61+
descriptions = json.load(f)
6362
s = '<html><body><h2>Algorithm description</h2>\n'
6463
s += '<p>' + getDescription(ALG_DESC, descriptions) + '</p>\n'
6564
s += '<h2>Input parameters</h2>\n'

python/plugins/processing/gui/HelpEditionDialog.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************
1818
"""
1919

20+
2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
2223
__copyright__ = '(C) 2012, Victor Olaya'
@@ -26,11 +27,12 @@
2627
__revision__ = '$Format:%H$'
2728

2829
import os
29-
import pickle
30+
import json
3031
from PyQt4.QtCore import *
3132
from PyQt4.QtGui import *
3233
from qgis.core import *
3334
from processing.ui.ui_DlgHelpEdition import Ui_DlgHelpEdition
35+
from processing.core.ProcessingLog import ProcessingLog
3436

3537

3638
class HelpEditionDialog(QDialog, Ui_DlgHelpEdition):
@@ -49,8 +51,13 @@ def __init__(self, alg):
4951
if self.alg.descriptionFile is not None:
5052
helpfile = alg.descriptionFile + '.help'
5153
if os.path.exists(helpfile):
52-
f = open(helpfile, 'rb')
53-
self.descriptions = pickle.load(f)
54+
try:
55+
with open(helpfile) as f:
56+
self.descriptions = json.load(f)
57+
except Exception, e:
58+
print e
59+
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, "Cannot open gelp file: " + helpfile)
60+
5461
self.currentName = self.ALG_DESC
5562
if self.ALG_DESC in self.descriptions:
5663
self.text.setText(self.descriptions[self.ALG_DESC])
@@ -67,17 +74,15 @@ def accept(self):
6774
self.descriptions[self.currentName] = unicode(self.text.toPlainText())
6875
if self.alg.descriptionFile is not None:
6976
try:
70-
f = open(self.alg.descriptionFile + '.help', 'wb')
71-
pickle.dump(self.descriptions, f)
72-
f.close()
77+
with open(self.alg.descriptionFile + '.help', 'w') as f:
78+
json.dump(self.descriptions, f)
7379
except Exception, e:
7480
QMessageBox.warning(self, 'Error saving help file',
75-
'Help file could not be saved. Check that \
76-
you have permission to modify the help \
77-
file. You might not have permission if \
78-
you are editing an example model or \
79-
script, since they are stored on the \
80-
installation folder')
81+
'Help file could not be saved.\n'
82+
'Check that you have permission to modify the help\n'
83+
'file. You might not have permission if you are \n'
84+
'editing an example model or script, since they \n'
85+
'are stored on the installation folder')
8186

8287
QDialog.accept(self)
8388

python/plugins/processing/gui/ScriptEditorDialog.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
import pickle
2928
import codecs
3029
import sys
30+
import json
3131

3232
from PyQt4.QtCore import *
3333
from PyQt4.QtGui import *
@@ -166,9 +166,8 @@ def saveScript(self, saveAs):
166166
# If help strings were defined before saving the script for
167167
# the first time, we do it here
168168
if self.help:
169-
f = open(self.filename + '.help', 'wb')
170-
pickle.dump(self.help, f)
171-
f.close()
169+
with open(self.filename + '.help', 'w') as f:
170+
json.dump(self.help, f)
172171
self.help = None
173172
self.setHasChanged(False)
174173
else:

python/plugins/processing/modeler/ModelerDialog.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
import json
1920

2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
@@ -26,7 +27,6 @@
2627
__revision__ = '$Format:%H$'
2728

2829
import codecs
29-
import pickle
3030
from PyQt4.QtCore import *
3131
from PyQt4.QtGui import *
3232

@@ -308,9 +308,8 @@ def saveModel(self, saveAs):
308308
# If help strings were defined before saving the model
309309
# for the first time, we do it here.
310310
if self.help:
311-
f = open(self.alg.descriptionFile + '.help', 'wb')
312-
pickle.dump(self.help, f)
313-
f.close()
311+
with open(self.descriptionFile + '.help', 'w') as f:
312+
json.dump(self.help, f)
314313
self.help = None
315314
QMessageBox.information(self, self.tr('Model saved'),
316315
self.tr('Model was correctly saved.'))

0 commit comments

Comments
 (0)