[GRASS-SVN] r44775 - grass/trunk/scripts/g.manual

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 29 14:52:12 EST 2010


Author: martinl
Date: 2010-12-29 11:52:12 -0800 (Wed, 29 Dec 2010)
New Revision: 44775

Modified:
   grass/trunk/scripts/g.manual/g.manual.py
Log:
g.manual: -i -> suppress required
	  don't check xdg-open
	  various clean up


Modified: grass/trunk/scripts/g.manual/g.manual.py
===================================================================
--- grass/trunk/scripts/g.manual/g.manual.py	2010-12-29 18:54:42 UTC (rev 44774)
+++ grass/trunk/scripts/g.manual/g.manual.py	2010-12-29 19:52:12 UTC (rev 44775)
@@ -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 by the GRASS Development Team
+# COPYRIGHT:	(C) 2003, 2008, 2010 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
@@ -14,92 +14,87 @@
 #
 #############################################################################
 
-#%Module
-#%  description: Display the HTML man pages of GRASS GIS
-#%  keywords: general
-#%  keywords: manual
-#%  keywords: help
-#%End
+#%module
+#% description: Display the HTML man pages of GRASS GIS
+#% keywords: general
+#% keywords: manual
+#% keywords: help
+#%end
 #%flag
-#%  key: i
-#%  description: Display index
-#%End
+#% key: i
+#% description: Display index
+#% suppress_required: yes
+#%end
 #%flag
-#%  key: m
-#%  description: Display as MAN text page instead of HTML page in browser
-#%End
+#% key: m
+#% description: Display as MAN text page instead of HTML page in browser
+#%end
 #%option
 #% key: entry
 #% type: string
 #% description: Manual entry to be displayed
-#% required : no
-#%End
+#% required : yes
+#%end
 
 import sys
 import os
 from grass.script import core as grass
 
 def start_browser(entry):
-    if not grass.find_program(browser):
+    if browser != 'xdg-open' and not grass.find_program(browser):
         grass.fatal(_("Browser <%s> not found") % browser)
     
     path = os.path.join(gisbase, 'docs', 'html', entry + '.html')
     if not os.path.exists(path):
-	grass.fatal(_("No HTML manual page entry for <%s>.") % entry)
-    verbose = os.getenv("GRASS_VERBOSE")
-    if not verbose or int(verbose) > 1:
-	grass.message(_("Starting browser <%s> for module %s...") % (browser_name, entry))
+	grass.fatal(_("No HTML manual page entry for <%s>") % entry)
+    grass.verbose(_("Starting browser <%s> for module %s...") % (browser_name, entry))
     
     os.execlp(browser, browser_name, "file://%s/docs/html/%s.html" % (gisbase, entry))
     grass.fatal(_("Error starting browser <%s> for HTML file <%s>") % (browser, entry))
-
+    
 def start_man(entry):
     path = os.path.join(gisbase, 'man', 'man1', entry + '.1')
     for ext in ['', '.gz', '.bz2']:
 	if os.path.exists(path + ext):
 	    os.execlp('man', 'man', path + ext)
 	    grass.fatal(_("Error starting 'man' for <%s>") % path)
-    grass.fatal(_("No manual page entry for <%s>.") % entry)
+    grass.fatal(_("No manual page entry for <%s>") % entry)
 
 def main():
     global gisbase, browser, browser_name
-
-    index = flags['i']
+    
+    index  = flags['i']
     manual = flags['m']
-    entry = options['entry']
-
+    entry  = options['entry']
+    
     gisbase = os.environ['GISBASE']
     
     browser = os.getenv('GRASS_HTML_BROWSER')
-
-    if "html_browser_mac.sh" in browser:
-        #hack for MacOSX:
-	browser_name = os.getenv('GRASS_HTML_BROWSER_MACOSX','..').split('.')[2]
-    elif os.getenv('OSTYPE') == "cygwin":
-        #hack for Cygwin:
+    
+    if sys.platform == 'darwin':
+        # hack for MacOSX
+	browser_name = os.getenv('GRASS_HTML_BROWSER_MACOSX', '..').split('.')[2]
+    elif sys.platform == 'cygwin':
+        # hack for Cygwin
 	browser_name = grass.basename(browser, 'exe')
     else:
 	browser_name = grass.basename(browser)
-
-    #keep order!
-    #first test for index...
+    
+    # keep order!
+    # first test for index...
     if index:
 	if manual:
 	    start_man('index')
 	else:
 	    start_browser('index')
-	sys.exit(0)
-
-    #... then for help parameter:
-    if not entry:
-	grass.run_command('g.manual', '--help')
-	sys.exit(0)
-
+        return 0
+    
     if manual:
 	start_man(entry)
     else:
 	start_browser(entry)
+    return 0
 
 if __name__ == "__main__":
     options, flags = grass.parser()
-    main()
+    sys.exit(main())



More information about the grass-commit mailing list