Skip to content

Commit 195f139

Browse files
committed
LifeLineCharts: 1) modify gpr file so that make runs without warnings.
2) Don't load or test for prerequisites in CLI mode 3) Always register addons, even when prerequisites broken, to avoid issue where plugin manager wants to install update every time. 4) Hide view when prerequisites broken to avoid error messages.
1 parent 6b3c35c commit 195f139

File tree

2 files changed

+92
-58
lines changed

2 files changed

+92
-58
lines changed

LifeLineChartView/lifelinechartview.gpr.py

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444

4545
class Zipfile_bugfix(Zipfile):
4646
"""
47-
Zipfile workaround. This class doesn't work with zip files in the recent release.
47+
Zipfile workaround. This class doesn't work with zip files in the
48+
recent release.
4849
pr-1068: replace file() -> open()
4950
"""
5051
def extractall(self, path, members=None):
@@ -113,7 +114,8 @@ def check_for(self, module_name, module_version):
113114
module_name,
114115
'__init__.py')
115116
if os.path.isfile(filename):
116-
spec = importlib.util.spec_from_file_location(module_name, filename)
117+
spec = importlib.util.spec_from_file_location(
118+
module_name, filename)
117119
module = importlib.util.module_from_spec(spec)
118120
sys.modules[spec.name] = module
119121
spec.loader.exec_module(module)
@@ -127,7 +129,8 @@ def check_for(self, module_name, module_version):
127129

128130
def request(self, module_name, module_version, source_link):
129131
"""
130-
Request a module. Either it is available, or it will be downloaded and loaded.
132+
Request a module. Either it is available, or it will be downloaded
133+
and loaded.
131134
132135
Args:
133136
module_name (str): module name
@@ -144,7 +147,8 @@ def request(self, module_name, module_version, source_link):
144147
if module:
145148
return module
146149

147-
message = _("Failed to load the required module {module_name} version {module_version}.").format(**locals())
150+
message = _("Failed to load the required module {module_name} "
151+
"version {module_version}.").format(**locals())
148152
logging.warning(self.plugin_name + ': ' + message)
149153
if self.uistate:
150154
from gramps.gui.dialog import QuestionDialog3
@@ -157,26 +161,33 @@ def request(self, module_name, module_version, source_link):
157161
prompt = ok_no_cancel.run()
158162
if prompt == True:
159163
# dont ask me again
160-
inifile.register(self.plugin_name.lower()+'_warn.missingmodules', "")
161-
inifile.set(self.plugin_name.lower()+'_warn.missingmodules', "False")
164+
inifile.register(self.plugin_name.lower() +
165+
'_warn.missingmodules', "")
166+
inifile.set(self.plugin_name.lower() +
167+
'_warn.missingmodules', "False")
162168
inifile.save()
163-
logging.warning(self.plugin_name + ': ' + _('The user chose to deactivate further warnings.'))
169+
logging.warning(self.plugin_name + ': ' + _(
170+
'The user chose to deactivate further warnings.'))
164171
return None
165172
elif prompt == -1:
166173
#cancel
167-
logging.info(self.plugin_name + ': ' + _('The user chose to ignore the warning once.'))
174+
logging.info(self.plugin_name + ': ' +
175+
_('The user chose to ignore the warning once.'))
168176
return None
169177
elif prompt == False:
170-
logging.info(self.plugin_name + ': ' + _('The user chose to install the module.'))
178+
logging.info(self.plugin_name + ': ' +
179+
_('The user chose to install the module.'))
171180
output_path = os.path.join(USER_PLUGINS, self.plugin_name)
172-
self.load_addon_file(source_link, output_path=output_path, callback=print)
181+
self.load_addon_file(source_link, output_path=output_path,
182+
callback=print)
173183
module = self.check_for(module_name, module_version)
174184
return module
175185
return None
176186

177187
def load_addon_file(self, path, output_path, callback=None):
178188
"""
179-
Load an module from a particular path (from URL or file system) and extract to output_path.
189+
Load an module from a particular path (from URL or file system) and
190+
extract to output_path.
180191
"""
181192
from urllib.request import urlopen
182193
from gramps.gen.plug.utils import urlopen_maybe_no_check_cert
@@ -265,39 +276,49 @@ def cleanup_old_versions(self):
265276

266277

267278
life_line_chart_version_required = (1, 7, 2)
268-
life_line_chart_version_required_str = '.'.join([str(i) for i in life_line_chart_version_required])
279+
life_line_chart_version_required_str = '.'.join(
280+
[str(i) for i in life_line_chart_version_required])
281+
some_import_error = False
269282

270283
try:
271-
if 'lifelinechartview_warn' not in sects or inifile.get('lifelinechartview_warn.missingmodules') != 'False':
284+
if('lifelinechartview_warn' not in sects or
285+
inifile.get('lifelinechartview_warn.missingmodules') != 'False'):
272286
_uistate = locals().get('uistate')
273287
else:
274288
_uistate = None
275-
mp=ModuleProvider('LifeLineChartView', _uistate)
276-
if sys.version_info.major==3 and sys.version_info.minor>5:
277-
svgwrite = mp.request(
278-
'svgwrite',
279-
'1.4',
280-
'https://pypi.python.org/packages/source/s/svgwrite/svgwrite-1.4.zip'
289+
290+
if _uistate: # don't bother with any of this unless GUI
291+
mp=ModuleProvider('LifeLineChartView', _uistate)
292+
if sys.version_info.major==3 and sys.version_info.minor>5:
293+
svgwrite = mp.request(
294+
'svgwrite',
295+
'1.4',
296+
'https://pypi.python.org/packages/source/s/'
297+
'svgwrite/svgwrite-1.4.zip'
298+
)
299+
else:
300+
svgwrite = True
301+
life_line_chart = mp.request(
302+
'life_line_chart',
303+
life_line_chart_version_required_str,
304+
'https://pypi.python.org/packages/source/l/'
305+
'life_line_chart/life_line_chart-' +
306+
life_line_chart_version_required_str + '.tar.gz'
281307
)
282-
else:
283-
svgwrite = True
284-
life_line_chart = mp.request(
285-
'life_line_chart',
286-
life_line_chart_version_required_str,
287-
'https://pypi.python.org/packages/source/l/life_line_chart/life_line_chart-'+life_line_chart_version_required_str+'.tar.gz'
288-
)
289-
290-
fname = os.path.join(USER_PLUGINS, 'LifeLineChartView')
291-
icons = Gtk.IconTheme().get_default()
292-
icons.append_search_path(fname)
293-
some_import_error = life_line_chart is None or svgwrite is None
308+
309+
fname = os.path.join(USER_PLUGINS, 'LifeLineChartView')
310+
icons = Gtk.IconTheme().get_default()
311+
icons.append_search_path(fname)
312+
some_import_error = life_line_chart is None or svgwrite is None
294313

295314
except Exception as e:
296315
some_import_error = True
297316
import_error_message = traceback.format_exc()
298-
logging.log(logging.ERROR, 'Failed to load LifeLineChartView plugin.\n' + import_error_message)
317+
logging.log(logging.ERROR, 'Failed to load LifeLineChartView plugin.\n' +
318+
import_error_message)
319+
299320

300-
if locals().get('uistate') is None or not some_import_error:
321+
if locals().get('uistate') is None or locals().get('uistate'):
301322
# Right after the download the plugin is loaded without uistate
302323
# If the gui is available, then the error message is shown anyway
303324
# so here we can import to avoid additional messages.
@@ -306,9 +327,9 @@ def cleanup_old_versions(self):
306327
name=_("Life Line Ancestor Chart"),
307328
category=("Ancestry", _("Charts")),
308329
description=_("Persons and their relation in a time based chart"),
309-
version = '1.3.11',
330+
version = '1.3.12',
310331
gramps_target_version="5.1",
311-
status=STABLE,
332+
status=UNSTABLE,
312333
fname='lifelinechartview.py',
313334
authors=["Christian Schulze"],
314335
authors_email=["[email protected]"],
@@ -320,17 +341,30 @@ def cleanup_old_versions(self):
320341
name=_("Life Line Descendant Chart"),
321342
category=("Ancestry", _("Charts")),
322343
description=_("Persons and their relation in a time based chart"),
323-
version = '1.3.11',
344+
version = '1.3.12',
324345
gramps_target_version="5.1",
325-
status=STABLE,
346+
status=UNSTABLE,
326347
fname='lifelinechartview.py',
327348
authors=["Christian Schulze"],
328349
authors_email=["[email protected]"],
329350
viewclass='LifeLineChartDescendantView',
330351
stock_icon='gramps-lifelinedescendantchart-bw',
331352
)
332353

333-
if not some_import_error:
354+
# reset the warning 'on' setting if updated or new plugin or it loaded ok.
355+
if _uistate and not some_import_error or locals().get('new_plugin'):
334356
inifile.register('lifelinechartview_warn.missingmodules', "")
335357
inifile.set('lifelinechartview_warn.missingmodules', "True")
336358
inifile.save()
359+
360+
# prevent the view from starting if there is a problem; we still need to
361+
# register to support plugin manager 'installed' and addon updates correctly
362+
if locals().get('uistate'):
363+
from gramps.gui.pluginmanager import GuiPluginManager
364+
pmgr = GuiPluginManager.get_instance()
365+
if some_import_error:
366+
pmgr.hide_plugin('lifelinechartancestorview')
367+
pmgr.hide_plugin('lifelinechartdescendantview')
368+
elif 'lifelinechartancestorview' in pmgr.get_hidden_plugin_ids():
369+
pmgr.unhide_plugin('lifelinechartancestorview')
370+
pmgr.unhide_plugin('lifelinechartdescendantview')

LifeLineChartView/po/template.pot

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-08-26 10:49-0500\n"
11+
"POT-Creation-Date: 2020-09-03 16:07-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -117,77 +117,77 @@ msgstr ""
117117
msgid "Add Child to Family"
118118
msgstr ""
119119

120-
#: LifeLineChartView/lifelinechartview.gpr.py:147
120+
#: LifeLineChartView/lifelinechartview.gpr.py:150
121121
#, python-brace-format
122122
msgid ""
123123
"Failed to load the required module {module_name} version {module_version}."
124124
msgstr ""
125125

126-
#: LifeLineChartView/lifelinechartview.gpr.py:152
126+
#: LifeLineChartView/lifelinechartview.gpr.py:156
127127
msgid " Plugin"
128128
msgstr ""
129129

130-
#: LifeLineChartView/lifelinechartview.gpr.py:154
130+
#: LifeLineChartView/lifelinechartview.gpr.py:158
131131
msgid "Don't ask me again"
132132
msgstr ""
133133

134-
#: LifeLineChartView/lifelinechartview.gpr.py:155
134+
#: LifeLineChartView/lifelinechartview.gpr.py:159
135135
msgid "Download module"
136136
msgstr ""
137137

138-
#: LifeLineChartView/lifelinechartview.gpr.py:163
138+
#: LifeLineChartView/lifelinechartview.gpr.py:170
139139
msgid "The user chose to deactivate further warnings."
140140
msgstr ""
141141

142-
#: LifeLineChartView/lifelinechartview.gpr.py:167
142+
#: LifeLineChartView/lifelinechartview.gpr.py:175
143143
msgid "The user chose to ignore the warning once."
144144
msgstr ""
145145

146-
#: LifeLineChartView/lifelinechartview.gpr.py:170
146+
#: LifeLineChartView/lifelinechartview.gpr.py:179
147147
msgid "The user chose to install the module."
148148
msgstr ""
149149

150-
#: LifeLineChartView/lifelinechartview.gpr.py:200
150+
#: LifeLineChartView/lifelinechartview.gpr.py:211
151151
#, python-format
152152
msgid "Unable to open '%s' with curl"
153153
msgstr ""
154154

155-
#: LifeLineChartView/lifelinechartview.gpr.py:211
156-
#: LifeLineChartView/lifelinechartview.gpr.py:218
155+
#: LifeLineChartView/lifelinechartview.gpr.py:222
156+
#: LifeLineChartView/lifelinechartview.gpr.py:229
157157
#, python-format
158158
msgid "Unable to open '%s'"
159159
msgstr ""
160160

161-
#: LifeLineChartView/lifelinechartview.gpr.py:227
161+
#: LifeLineChartView/lifelinechartview.gpr.py:238
162162
#, python-format
163163
msgid "Error in reading '%s'"
164164
msgstr ""
165165

166-
#: LifeLineChartView/lifelinechartview.gpr.py:242
166+
#: LifeLineChartView/lifelinechartview.gpr.py:253
167167
#, python-format
168168
msgid "Error: cannot open '%s'"
169169
msgstr ""
170170

171-
#: LifeLineChartView/lifelinechartview.gpr.py:246
171+
#: LifeLineChartView/lifelinechartview.gpr.py:257
172172
#, python-format
173173
msgid "Error: unknown file type: '%s'"
174174
msgstr ""
175175

176-
#: LifeLineChartView/lifelinechartview.gpr.py:306
176+
#: LifeLineChartView/lifelinechartview.gpr.py:327
177177
msgid "Life Line Ancestor Chart"
178178
msgstr ""
179179

180-
#: LifeLineChartView/lifelinechartview.gpr.py:307
181-
#: LifeLineChartView/lifelinechartview.gpr.py:321
180+
#: LifeLineChartView/lifelinechartview.gpr.py:328
181+
#: LifeLineChartView/lifelinechartview.gpr.py:342
182182
msgid "Charts"
183183
msgstr ""
184184

185-
#: LifeLineChartView/lifelinechartview.gpr.py:308
186-
#: LifeLineChartView/lifelinechartview.gpr.py:322
185+
#: LifeLineChartView/lifelinechartview.gpr.py:329
186+
#: LifeLineChartView/lifelinechartview.gpr.py:343
187187
msgid "Persons and their relation in a time based chart"
188188
msgstr ""
189189

190-
#: LifeLineChartView/lifelinechartview.gpr.py:320
190+
#: LifeLineChartView/lifelinechartview.gpr.py:341
191191
msgid "Life Line Descendant Chart"
192192
msgstr ""
193193

0 commit comments

Comments
 (0)