Factored out common code into find_binary function
svn: r13226
This commit is contained in:
parent
b414b25e2b
commit
05b6282363
@ -85,17 +85,10 @@ def run_file(file):
|
|||||||
Open a file or url with the default application. This should work
|
Open a file or url with the default application. This should work
|
||||||
on GNOME, KDE, XFCE, ... as we use a freedesktop application
|
on GNOME, KDE, XFCE, ... as we use a freedesktop application
|
||||||
"""
|
"""
|
||||||
import os
|
prog = find_binary('xdg-open')
|
||||||
|
if prog:
|
||||||
search = os.environ['PATH'].split(':')
|
os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ)
|
||||||
|
return True
|
||||||
xdgopen = 'xdg-open'
|
|
||||||
for path in search:
|
|
||||||
prog = os.path.join(path, xdgopen)
|
|
||||||
if os.path.isfile(prog):
|
|
||||||
os.spawnvpe(os.P_NOWAIT, prog, [prog, file], os.environ)
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def run_browser(url):
|
def run_browser(url):
|
||||||
@ -108,20 +101,29 @@ def run_browser(url):
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open_new_tab(url)
|
webbrowser.open_new_tab(url)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import os
|
|
||||||
|
|
||||||
search = os.environ['PATH'].split(':')
|
|
||||||
|
|
||||||
for browser in ['firefox', 'konqueror', 'epiphany',
|
for browser in ['firefox', 'konqueror', 'epiphany',
|
||||||
'galeon', 'mozilla']:
|
'galeon', 'mozilla']:
|
||||||
for path in search:
|
prog = find_binary(browser)
|
||||||
prog = os.path.join(path,browser)
|
if prog:
|
||||||
if os.path.isfile(prog):
|
os.spawnvpe(os.P_NOWAIT, prog, [prog, url], os.environ)
|
||||||
os.spawnvpe(os.P_NOWAIT, prog, [prog, url], os.environ)
|
return
|
||||||
return
|
|
||||||
|
|
||||||
# If we did not find a browser in the path, try this
|
# If we did not find a browser in the path, try this
|
||||||
try:
|
try:
|
||||||
os.startfile(url)
|
os.startfile(url)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def find_binary(file):
|
||||||
|
"""
|
||||||
|
Find the binary (executable) of a filename in the PATH, and return full
|
||||||
|
path if found, else return None.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
search = os.environ['PATH'].split(':')
|
||||||
|
for path in search:
|
||||||
|
prog = os.path.join(path, file)
|
||||||
|
if os.path.isfile(prog):
|
||||||
|
return prog
|
||||||
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user