diff --git a/fsl/utils/webpage.py b/fsl/utils/webpage.py index c532ec23d9104ed042111311783e4a3373086196..962c6444fb39beab8168f5716fe10da3a8ab7ae6 100644 --- a/fsl/utils/webpage.py +++ b/fsl/utils/webpage.py @@ -12,7 +12,9 @@ The following functions are provided: .. autosummary:: :nosignatures: + fileToUrl openPage + openFile localHelpUrl openLocalHelp """ @@ -22,11 +24,26 @@ import os.path as op 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): """Opens the given URL in the system-default web browser.""" webbrowser.open(url) +def openFile(fileName): + """Opens the given file in the system-default web browser.""" + openPage(fileToUrl(fileName)) + + def localHelpUrl(toolName): """Checks the ``$FSLDIR`` to see if a local help page exists for the FSL tool with the specified name. @@ -40,10 +57,7 @@ def localHelpUrl(toolName): localUrl = op.join(fsldir, 'doc', 'redirects', '{}.html'.format(toolName)) if op.exists(localUrl): - import urlparse - import urllib - return urlparse.urljoin( - 'file:', urllib.pathname2url(localUrl)) + return fileToUrl(localUrl) return None