1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
class OpenBrowser(object):
def _search_browser_from_nix(self):
browsers = ["xdg-open", "firefox", "chromium-browser",
"mozilla", "konqueror", "opera", "epiphany", "netscape"]
browser = None
try:
for browser_iter in browsers:
try:
val = check_output(["which", browser_iter], timeout=1)
if val != '':
browser = browser_iter
break
except CalledProcessError:
pass
if browser is None:
raise RunException("Web browser unknown!")
return browser
except Exception:
print_exc()
raise RunException("Web browser not found!")
def open_url(self, url):
os_name = sys.platform
if 'darwin' in os_name:
args = ["open", url]
elif 'win' in os_name:
args = ["rundll32", "url.dll", "FileProtocolHandler", url]
else:
args = [self._search_browser_from_nix(), url]
Popen(args) |
Partager