44
44
45
45
class Zipfile_bugfix (Zipfile ):
46
46
"""
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.
48
49
pr-1068: replace file() -> open()
49
50
"""
50
51
def extractall (self , path , members = None ):
@@ -113,7 +114,8 @@ def check_for(self, module_name, module_version):
113
114
module_name ,
114
115
'__init__.py' )
115
116
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 )
117
119
module = importlib .util .module_from_spec (spec )
118
120
sys .modules [spec .name ] = module
119
121
spec .loader .exec_module (module )
@@ -127,7 +129,8 @@ def check_for(self, module_name, module_version):
127
129
128
130
def request (self , module_name , module_version , source_link ):
129
131
"""
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.
131
134
132
135
Args:
133
136
module_name (str): module name
@@ -144,7 +147,8 @@ def request(self, module_name, module_version, source_link):
144
147
if module :
145
148
return module
146
149
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 ())
148
152
logging .warning (self .plugin_name + ': ' + message )
149
153
if self .uistate :
150
154
from gramps .gui .dialog import QuestionDialog3
@@ -157,26 +161,33 @@ def request(self, module_name, module_version, source_link):
157
161
prompt = ok_no_cancel .run ()
158
162
if prompt == True :
159
163
# 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" )
162
168
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.' ))
164
171
return None
165
172
elif prompt == - 1 :
166
173
#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.' ))
168
176
return None
169
177
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.' ))
171
180
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 )
173
183
module = self .check_for (module_name , module_version )
174
184
return module
175
185
return None
176
186
177
187
def load_addon_file (self , path , output_path , callback = None ):
178
188
"""
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.
180
191
"""
181
192
from urllib .request import urlopen
182
193
from gramps .gen .plug .utils import urlopen_maybe_no_check_cert
@@ -265,39 +276,49 @@ def cleanup_old_versions(self):
265
276
266
277
267
278
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
269
282
270
283
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' ):
272
286
_uistate = locals ().get ('uistate' )
273
287
else :
274
288
_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'
281
307
)
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
294
313
295
314
except Exception as e :
296
315
some_import_error = True
297
316
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
+
299
320
300
- if locals ().get ('uistate' ) is None or not some_import_error :
321
+ if locals ().get ('uistate' ) is None or locals (). get ( 'uistate' ) :
301
322
# Right after the download the plugin is loaded without uistate
302
323
# If the gui is available, then the error message is shown anyway
303
324
# so here we can import to avoid additional messages.
@@ -306,9 +327,9 @@ def cleanup_old_versions(self):
306
327
name = _ ("Life Line Ancestor Chart" ),
307
328
category = ("Ancestry" , _ ("Charts" )),
308
329
description = _ ("Persons and their relation in a time based chart" ),
309
- version = '1.3.11 ' ,
330
+ version = '1.3.12 ' ,
310
331
gramps_target_version = "5.1" ,
311
- status = STABLE ,
332
+ status = UNSTABLE ,
312
333
fname = 'lifelinechartview.py' ,
313
334
authors = ["Christian Schulze" ],
314
335
authors_email = [
"[email protected] " ],
@@ -320,17 +341,30 @@ def cleanup_old_versions(self):
320
341
name = _ ("Life Line Descendant Chart" ),
321
342
category = ("Ancestry" , _ ("Charts" )),
322
343
description = _ ("Persons and their relation in a time based chart" ),
323
- version = '1.3.11 ' ,
344
+ version = '1.3.12 ' ,
324
345
gramps_target_version = "5.1" ,
325
- status = STABLE ,
346
+ status = UNSTABLE ,
326
347
fname = 'lifelinechartview.py' ,
327
348
authors = ["Christian Schulze" ],
328
349
authors_email = [
"[email protected] " ],
329
350
viewclass = 'LifeLineChartDescendantView' ,
330
351
stock_icon = 'gramps-lifelinedescendantchart-bw' ,
331
352
)
332
353
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' ):
334
356
inifile .register ('lifelinechartview_warn.missingmodules' , "" )
335
357
inifile .set ('lifelinechartview_warn.missingmodules' , "True" )
336
358
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' )
0 commit comments