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:
John Ralls 2013-05-24 23:36:18 +00:00
parent 6a4a4a3a9c
commit 25c5e6fbc8
2 changed files with 31 additions and 26 deletions

View File

@ -24,7 +24,9 @@ from gramps.gen.const import URL_MANUAL_PAGE, URL_WIKISTRING
from gramps.gen.constfunc import is_quartz
from gramps.gen.config import config
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 subprocess
#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
@ -57,7 +59,24 @@ def display_help(webpage='', section=''):
if section:
link = link + '#' + section
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):
"""
Open the specified URL in a browser.
@ -71,20 +90,6 @@ def display_url(link, uistate=None):
if not run_file(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):
"""
Attempt of find a browswer, and launch with the browser with the

View File

@ -33,6 +33,7 @@ from __future__ import print_function, division
#-------------------------------------------------------------------------
import os
import sys
import subprocess
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
# 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
norm_path = os.path.normpath( file_path )
if not os.path.exists(norm_path):
ErrorDialog(_("Error Opening File"), _("File does not exist"))
return
@ -377,17 +377,17 @@ def open_file_with_default_application( file_path ):
os.startfile(norm_path)
except WindowsError as msg:
ErrorDialog(_("Error Opening File"), str(msg))
return
if mac():
utility = '/usr/bin/open'
else:
if mac():
utility = '/usr/bin/open'
else:
utility = 'xdg-open'
search = os.environ['PATH'].split(':')
for lpath in search:
prog = os.path.join(lpath, utility)
if os.path.isfile(prog):
os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ)
return
utility = 'xdg-open'
try:
subprocess.check_output([utility, norm_path], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
ErrorDialog(_("Error Opening File"), err.output)
return
def process_pending_events(max_count=10):
"""