Skip to content
Snippets Groups Projects
Commit 3cc49d72 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Some more convenience functions added to utils.webpage.

parent e63781ee
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,9 @@ The following functions are provided: ...@@ -12,7 +12,9 @@ The following functions are provided:
.. autosummary:: .. autosummary::
:nosignatures: :nosignatures:
fileToUrl
openPage openPage
openFile
localHelpUrl localHelpUrl
openLocalHelp openLocalHelp
""" """
...@@ -22,11 +24,26 @@ import os.path as op ...@@ -22,11 +24,26 @@ import os.path as op
import webbrowser import webbrowser
def fileToUrl(fileName):
"""Converts a file path to a URL. """
import urlparse
import urllib
return urlparse.urljoin(
'file:', urllib.pathname2url(fileName))
def openPage(url): def openPage(url):
"""Opens the given URL in the system-default web browser.""" """Opens the given URL in the system-default web browser."""
webbrowser.open(url) webbrowser.open(url)
def openFile(fileName):
"""Opens the given file in the system-default web browser."""
openPage(fileToUrl(fileName))
def localHelpUrl(toolName): def localHelpUrl(toolName):
"""Checks the ``$FSLDIR`` to see if a local help page exists for the """Checks the ``$FSLDIR`` to see if a local help page exists for the
FSL tool with the specified name. FSL tool with the specified name.
...@@ -40,10 +57,7 @@ def localHelpUrl(toolName): ...@@ -40,10 +57,7 @@ def localHelpUrl(toolName):
localUrl = op.join(fsldir, 'doc', 'redirects', '{}.html'.format(toolName)) localUrl = op.join(fsldir, 'doc', 'redirects', '{}.html'.format(toolName))
if op.exists(localUrl): if op.exists(localUrl):
import urlparse return fileToUrl(localUrl)
import urllib
return urlparse.urljoin(
'file:', urllib.pathname2url(localUrl))
return None return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment