Bugs 6099 & 6472: Don't leave zombies and report errors
Update spawnve() to subprocess.check_output() Pop an ErrorDialog if the system's open command fails in open_file_with_default_application() svn: r22417
This commit is contained in:
@@ -24,7 +24,9 @@ from gramps.gen.const import URL_MANUAL_PAGE, URL_WIKISTRING
|
|||||||
from gramps.gen.constfunc import is_quartz
|
from gramps.gen.constfunc import is_quartz
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
from gramps.gui.utils import open_file_with_default_application as run_file
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
#list of manuals on wiki, map locale code to wiki extension, add language codes
|
#list of manuals on wiki, map locale code to wiki extension, add language codes
|
||||||
#completely, or first part, so pt_BR if Brazilian portugeze wiki manual, and
|
#completely, or first part, so pt_BR if Brazilian portugeze wiki manual, and
|
||||||
@@ -58,6 +60,23 @@ def display_help(webpage='', section=''):
|
|||||||
link = link + '#' + section
|
link = link + '#' + section
|
||||||
display_url(link)
|
display_url(link)
|
||||||
|
|
||||||
|
def run_file(file_name):
|
||||||
|
"""
|
||||||
|
Open a file or url with the default application. This should work
|
||||||
|
on GNOME, KDE, XFCE, ... as we use a freedesktop application
|
||||||
|
"""
|
||||||
|
if is_quartz():
|
||||||
|
prog = find_binary('open')
|
||||||
|
else:
|
||||||
|
prog = find_binary('xdg-open')
|
||||||
|
if prog:
|
||||||
|
try:
|
||||||
|
subprocess.check_call([prog, file_name])
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def display_url(link, uistate=None):
|
def display_url(link, uistate=None):
|
||||||
"""
|
"""
|
||||||
Open the specified URL in a browser.
|
Open the specified URL in a browser.
|
||||||
@@ -71,20 +90,6 @@ def display_url(link, uistate=None):
|
|||||||
if not run_file(link):
|
if not run_file(link):
|
||||||
run_browser(link)
|
run_browser(link)
|
||||||
|
|
||||||
def run_file(file):
|
|
||||||
"""
|
|
||||||
Open a file or url with the default application. This should work
|
|
||||||
on GNOME, KDE, XFCE, ... as we use a freedesktop application
|
|
||||||
"""
|
|
||||||
if is_quartz():
|
|
||||||
prog = find_binary('open')
|
|
||||||
else:
|
|
||||||
prog = find_binary('xdg-open')
|
|
||||||
if prog:
|
|
||||||
os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def run_browser(url):
|
def run_browser(url):
|
||||||
"""
|
"""
|
||||||
Attempt of find a browswer, and launch with the browser with the
|
Attempt of find a browswer, and launch with the browser with the
|
||||||
|
@@ -33,6 +33,7 @@ from __future__ import print_function, division
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.gettext
|
_ = glocale.translation.gettext
|
||||||
# gtk is not included here, because this file is currently imported
|
# gtk is not included here, because this file is currently imported
|
||||||
@@ -367,7 +368,6 @@ def open_file_with_default_application( file_path ):
|
|||||||
"""
|
"""
|
||||||
from .dialog import ErrorDialog
|
from .dialog import ErrorDialog
|
||||||
norm_path = os.path.normpath( file_path )
|
norm_path = os.path.normpath( file_path )
|
||||||
|
|
||||||
if not os.path.exists(norm_path):
|
if not os.path.exists(norm_path):
|
||||||
ErrorDialog(_("Error Opening File"), _("File does not exist"))
|
ErrorDialog(_("Error Opening File"), _("File does not exist"))
|
||||||
return
|
return
|
||||||
@@ -377,16 +377,16 @@ def open_file_with_default_application( file_path ):
|
|||||||
os.startfile(norm_path)
|
os.startfile(norm_path)
|
||||||
except WindowsError as msg:
|
except WindowsError as msg:
|
||||||
ErrorDialog(_("Error Opening File"), str(msg))
|
ErrorDialog(_("Error Opening File"), str(msg))
|
||||||
else:
|
return
|
||||||
|
|
||||||
if mac():
|
if mac():
|
||||||
utility = '/usr/bin/open'
|
utility = '/usr/bin/open'
|
||||||
else:
|
else:
|
||||||
utility = 'xdg-open'
|
utility = 'xdg-open'
|
||||||
search = os.environ['PATH'].split(':')
|
try:
|
||||||
for lpath in search:
|
subprocess.check_output([utility, norm_path], stderr=subprocess.STDOUT)
|
||||||
prog = os.path.join(lpath, utility)
|
except subprocess.CalledProcessError as err:
|
||||||
if os.path.isfile(prog):
|
ErrorDialog(_("Error Opening File"), err.output)
|
||||||
os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_pending_events(max_count=10):
|
def process_pending_events(max_count=10):
|
||||||
|
Reference in New Issue
Block a user