Browse Source

g.manual: use webbrowser package (attempt to fix g.manual on Windows)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65179 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 years ago
parent
commit
b85afbca12
1 changed files with 14 additions and 10 deletions
  1. 14 10
      scripts/g.manual/g.manual.py

+ 14 - 10
scripts/g.manual/g.manual.py

@@ -6,7 +6,7 @@
 # AUTHOR(S):    Markus Neteler
 #               Converted to Python by Glynn Clements
 # PURPOSE:      Display the HTML/MAN pages
-# COPYRIGHT:    (C) 2003, 2008, 2010-2012 by the GRASS Development Team
+# COPYRIGHT:    (C) 2003-2015 by the GRASS Development Team
 #
 #               This program is free software under the GNU General Public
 #               License (>=v2). Read the file COPYING that comes with GRASS
@@ -49,12 +49,15 @@
 import sys
 import os
 import urllib
+import webbrowser
 
 from grass.script.utils import basename
 from grass.script import core as grass
 
 def start_browser(entry):
-    if browser != 'xdg-open' and not grass.find_program(browser):
+    if browser and \
+       browser not in ('xdg-open', 'explorer') and \
+       not grass.find_program(browser):
         grass.fatal(_("Browser '%s' not found") % browser)
 
     if flags['o']:
@@ -72,16 +75,19 @@ def start_browser(entry):
     
         url_path = 'file://' + path
     
+    if browser:
+        webbrowser.register(browser_name, None)
+    
     grass.verbose(_("Starting browser '%(browser)s' for manual"
-                    " entry '%(entry)s'...")
-                  % dict(browser=browser_name, entry=entry))
-
+                    " entry '%(entry)s'...") % \
+                  dict(browser=browser_name, entry=entry))
+    
     try:
-        os.execlp(browser, browser_name, url_path)
-    except OSError:
+        webbrowser.open(url_path)
+    except:
         grass.fatal(_("Error starting browser '%(browser)s' for HTML file"
                       " '%(path)s'") % dict(browser=browser, path=path))
-
+    
 def start_man(entry):
     path = os.path.join(gisbase, 'docs', 'man', 'man1', entry + '.1')
     if not os.path.exists(path) and os.getenv('GRASS_ADDON_BASE'):
@@ -111,9 +117,7 @@ def main():
         start = start_browser
     
     entry  = options['entry']
-    
     gisbase = os.environ['GISBASE']
-    
     browser = os.getenv('GRASS_HTML_BROWSER', '')
     
     if sys.platform == 'darwin':