Changeset 58641


Ignore:
Timestamp:
Jan 8, 2014, 9:16:33 AM (11 years ago)
Author:
martinl
Message:

g.manual: add flag for display online manuals including addons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/scripts/g.manual/g.manual.py

    r56882 r58641  
    3535#% description: Display as MAN text page instead of HTML page in browser
    3636#%end
     37#%flag
     38#% key: o
     39#% label: Display online manuals instead of locally installed
     40#% description: Use online manuals available at http://grass.osgeo.org website. This flag has no effect when displaying MAN text pages.
     41#%end
    3742#%option
    3843#% key: entry
     
    4449import sys
    4550import os
     51import urllib
     52
    4653from grass.script import core as grass
    4754
     
    5057        grass.fatal(_("Browser '%s' not found") % browser)
    5158
    52     path = os.path.join(gisbase, 'docs', 'html', entry + '.html')
    53     if not os.path.exists(path) and os.getenv('GRASS_ADDON_BASE'):
    54         path = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'docs', 'html', entry + '.html')
     59    if flags['o']:
     60        major,minor,patch = grass.version()['version'].split('.')
     61        url_path = 'http://grass.osgeo.org/grass%s%s/manuals/%s.html' % (major,minor,entry)
     62        if urllib.urlopen(url_path).getcode() != 200:
     63            url_path = 'http://grass.osgeo.org/grass%s%s/manuals/addons/%s.html' % (major,minor,entry)
     64    else:
     65        path = os.path.join(gisbase, 'docs', 'html', entry + '.html')
     66        if not os.path.exists(path) and os.getenv('GRASS_ADDON_BASE'):
     67            path = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'docs', 'html', entry + '.html')
    5568   
    56     if not os.path.exists(path):
    57         grass.fatal(_("No HTML manual page entry for '%s'") % entry)
    58 
     69        if not os.path.exists(path):
     70            grass.fatal(_("No HTML manual page entry for '%s'") % entry)
     71   
     72        url_path = 'file://' + path
     73   
    5974    grass.verbose(_("Starting browser '%(browser)s' for manual"
    6075                    " entry '%(entry)s'...")
     
    6277
    6378    try:
    64         os.execlp(browser, browser_name, "file://%s" % (path))
     79        os.execlp(browser, browser_name, url_path)
    6580    except OSError:
    6681        grass.fatal(_("Error starting browser '%(browser)s' for HTML file"
Note: See TracChangeset for help on using the changeset viewer.