[GRASS-SVN] r66263 - in grass/trunk: man tools

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 18 21:17:08 PDT 2015


Author: lucadelu
Date: 2015-09-18 21:17:08 -0700 (Fri, 18 Sep 2015)
New Revision: 66263

Added:
   grass/trunk/man/jquery.fixedheadertable.min.js
   grass/trunk/man/parser_standard_options.css
   grass/trunk/man/parser_standard_options.js
   grass/trunk/man/parser_standard_options.py
Removed:
   grass/trunk/tools/parser_standard_options.py
Modified:
   grass/trunk/man/Makefile
   grass/trunk/man/build_html.py
Log:
improved parser standard option to have a better output table, added it to Makefile; TODO add link to a GRASS manual

Modified: grass/trunk/man/Makefile
===================================================================
--- grass/trunk/man/Makefile	2015-09-19 00:49:05 UTC (rev 66262)
+++ grass/trunk/man/Makefile	2015-09-19 04:17:08 UTC (rev 66263)
@@ -7,7 +7,10 @@
 DSTFILES := \
 	$(HTMLDIR)/grassdocs.css \
 	$(HTMLDIR)/grass_logo.png \
-	$(HTMLDIR)/grass_icon.png
+	$(HTMLDIR)/grass_icon.png \
+	$(HTMLDIR)/jquery.fixedheadertable.min.js \
+	$(HTMLDIR)/parser_standard_options.css \
+	$(HTMLDIR)/parser_standard_options.js
 
 categories = \
 	d:display \
@@ -23,7 +26,7 @@
 
 IDXCATS := $(foreach cat,$(categories),$(lastword $(subst :, ,$(cat))))
 
-IDXSRC = full_index index topics keywords graphical_index manual_gallery class_graphical $(IDXCATS)
+IDXSRC = full_index index topics keywords graphical_index manual_gallery class_graphical parser_standard_options $(IDXCATS)
 
 INDICES := $(patsubst %,$(HTMLDIR)/%.html,$(IDXSRC))
 
@@ -79,6 +82,15 @@
 	$(PYTHON) ./build_manual_gallery.py $(HTMLDIR)
 endef
 
+define build_pso
+GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" \
+	VERSION_NUMBER=$(GRASS_VERSION_NUMBER) VERSION_DATE=$(GRASS_VERSION_DATE) \
+	$(PYTHON) ./parser_standard_options.py -t $(MODULE_TOPDIR)/lib/gis/parser_standard_options.c \
+	-f grass -o $(HTMLDIR)/parser_standard_options.html -p 'id="opts_table" class="scroolTable"'
+endef
+
+$(HTMLDIR)/topics.html: $(ALL_HTML)
+
 define build_class_graphical
 GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" \
 	VERSION_NUMBER=$(GRASS_VERSION_NUMBER) VERSION_DATE=$(GRASS_VERSION_DATE) \
@@ -101,12 +113,16 @@
 	$(call build_keywords)
 	touch $@
 
+
 $(HTMLDIR)/graphical_index.html: $(ALL_HTML)
 	$(call build_graphical_index)
 	touch $@
 
 $(HTMLDIR)/manual_gallery.html: $(ALL_HTML)
-	$(call build_manual_gallery)
+       $(call build_manual_gallery)
+
+$(HTMLDIR)/parser_standard_options.html: $(ALL_HTML)
+	$(call build_pso)
 	touch $@
 
 # TODO: this should be done in the same way as category_rule
@@ -131,3 +147,11 @@
 $(HTMLDIR)/grass_icon.png: grass_icon.png
 	$(INSTALL_DATA) $< $@
 
+$(HTMLDIR)/jquery.fixedheadertable.min.js: jquery.fixedheadertable.min.js
+	$(INSTALL_DATA) $< $@
+
+$(HTMLDIR)/parser_standard_options.js: parser_standard_options.js
+	$(INSTALL_DATA) $< $@
+
+$(HTMLDIR)/parser_standard_options.css: parser_standard_options.css
+	$(INSTALL_DATA) $< $@

Modified: grass/trunk/man/build_html.py
===================================================================
--- grass/trunk/man/build_html.py	2015-09-19 00:49:05 UTC (rev 66262)
+++ grass/trunk/man/build_html.py	2015-09-19 04:17:08 UTC (rev 66263)
@@ -322,6 +322,24 @@
 """)
 #"
 
+headerpso_tmpl = \
+r"""
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+<link rel="stylesheet" href="parser_standard_options.css" type="text/css">
+<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
+<script type="text/javascript" src="jquery.fixedheadertable.min.js"></script>
+<script type="text/javascript" src="parser_standard_options.js"></script>
+</head>
+<body style="width: 99%">
+<div id="container">
+
+<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
+<hr class="header">
+<h2>Parser standard options</h2>
+<ul>
+"""
+#"
+
 ############################################################################
 
 def check_for_desc_override(basename):

Added: grass/trunk/man/jquery.fixedheadertable.min.js
===================================================================
--- grass/trunk/man/jquery.fixedheadertable.min.js	                        (rev 0)
+++ grass/trunk/man/jquery.fixedheadertable.min.js	2015-09-19 04:17:08 UTC (rev 66263)
@@ -0,0 +1,19 @@
+/*!
+ * jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
+ *
+ * Copyright (c) 2013 Mark Malek
+ * http://fixedheadertable.com
+ *
+ * Licensed under MIT
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * http://docs.jquery.com/Plugins/Authoring
+ * jQuery authoring guidelines
+ *
+ * Launch  : October 2009
+ * Version : 1.3
+ * Released: May 9th, 2011
+ *
+ *
+ * all CSS sizing (width,height) is done in pixels (px)
+ */(function(c){c.fn.fixedHeaderTable=function(m){var u={width:"100%",height:"100%",themeClass:"fht-default",borderCollapse:!0,fixedColumns:0,fixedColumn:!1,sortable:!1,autoShow:!0,footer:!1,cloneHeadToFoot:!1,autoResize:!1,create:null},b={},n={init:function(a){b=c.extend({},u,a);return this.each(function(){var a=c(this);h._isTable(a)?(n.setup.apply(this,Array.prototype.slice.call(arguments,1)),c.isFunction(b.create)&&b.create.call(this)):c.error("Invalid table mark-up")})},setup:function(){var a=c(this), d=a.find("thead"),e=a.find("tfoot"),g=0,f,k,p;b.originalTable=c(this).clone();b.includePadding=h._isPaddingIncludedWithWidth();b.scrollbarOffset=h._getScrollbarWidth();b.themeClassName=b.themeClass;f=-1<b.width.search("%")?a.parent().width()-b.scrollbarOffset:b.width-b.scrollbarOffset;a.css({width:f});a.closest(".fht-table-wrapper").length||(a.addClass("fht-table"),a.wrap('<div class="fht-table-wrapper"></div>'));f=a.closest(".fht-table-wrapper");!0==b.fixedColumn&&0>=b.fixedColumn
 s&&(b.fixedColumns= 1);0<b.fixedColumns&&0==f.find(".fht-fixed-column").length&&(a.wrap('<div class="fht-fixed-body"></div>'),c('<div class="fht-fixed-column"></div>').prependTo(f),k=f.find(".fht-fixed-body"));f.css({width:b.width,height:b.height}).addClass(b.themeClassName);a.hasClass("fht-table-init")||a.wrap('<div class="fht-tbody"></div>');p=a.closest(".fht-tbody");var l=h._getTableProps(a);h._setupClone(p,l.tbody);a.hasClass("fht-table-init")?k=f.find("div.fht-thead"):(k=0<b.fixedColumns?c('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(k): c('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(f),k.find("table.fht-table").addClass(b.originalTable.attr("class")).attr("style",b.originalTable.attr("style")),d.clone().appendTo(k.find("table")));h._setupClone(k,l.thead);a.css({"margin-top":-k.outerHeight(!0)});!0==b.footer&&(h._setupTableFooter(a,this,l),e.length||(e=f.find("div.fht-tfoot table")),g=e.outerHeight(!0));d=f.height()-
 d.outerHeight(!0)-g-l.border;p.css({height:d});a.addClass("fht-table-init");"undefined"!== typeof b.altClass&&n.altRows.apply(this);0<b.fixedColumns&&h._setupFixedColumn(a,this,l);b.autoShow||f.hide();h._bindScroll(p,l);return this},resize:function(){return this},altRows:function(a){var d=c(this);a="undefined"!==typeof a?a:b.altClass;d.closest(".fht-table-wrapper").find("tbody tr:odd:not(:hidden)").addClass(a)},show:function(a,d,b){var g=c(this),f=g.closest(".fht-table-wrapper");if("undefined"!==typeof a&&"number"===typeof a)return f.show(a,function(){c.isFunction(d)&&d.call(this)}),this; if("undefined"!==typeof a&&"string"===typeof a&&"undefined"!==typeof d&&"number"===typeof d)return f.show(a,d,function(){c.isFunction(b)&&b.call(this)}),this;g.closest(".fht-table-wrapper").show();c.isFunction(a)&&a.call(this);return this},hide:function(a,d,b){var g=c(this),f=g.closest(".fht-table-wrapper");if("undefined"!==typeof a&&"number"===typeof a)return f.hide(a,function(){c.isFunction(b)&&b
 .call(this)}),this;if("undefined"!==typeof a&&"string"===typeof a&&"undefined"!==typeof d&&"number"=== typeof d)return f.hide(a,d,function(){c.isFunction(b)&&b.call(this)}),this;g.closest(".fht-table-wrapper").hide();c.isFunction(b)&&b.call(this);return this},destroy:function(){var a=c(this),d=a.closest(".fht-table-wrapper");a.insertBefore(d).removeAttr("style").append(d.find("tfoot")).removeClass("fht-table fht-table-init").find(".fht-cell").remove();d.remove();return this}},h={_isTable:function(a){var d=a.is("table"),b=0<a.find("thead").length;a=0<a.find("tbody").length;return d&&b&&a?!0:!1},_bindScroll:function(a){var d= a.closest(".fht-table-wrapper"),c=a.siblings(".fht-thead"),g=a.siblings(".fht-tfoot");a.bind("scroll",function(){0<b.fixedColumns&&d.find(".fht-fixed-column").find(".fht-tbody table").css({"margin-top":-a.scrollTop()});c.find("table").css({"margin-left":-this.scrollLeft});(b.footer||b.cloneHeadToFoot)&&g.find("table").css({"margin-left":-this.scrollLeft})})},_fix
 HeightWithCss:function(a,d){b.includePadding?a.css({height:a.height()+d.border}):a.css({height:a.parent().height()+d.border})},_fixWidthWithCss:function(a, d,e){b.includePadding?a.each(function(){c(this).css({width:void 0==e?c(this).width():e})}):a.each(function(){c(this).css({width:void 0==e?c(this).parent().width():e})})},_setupFixedColumn:function(a,d,e){var g=a.closest(".fht-table-wrapper"),f=g.find(".fht-fixed-body");d=g.find(".fht-fixed-column");var k=c('<div class="fht-thead"><table class="fht-table"><thead><tr></tr></thead></table></div>'),p=c('<div class="fht-tbody"><table class="fht-table"><tbody></tbody></table></div>');a=c('<div class="fht-tfoot"><table class="fht-table"><tfoot><tr></tr></tfoot></table></div>'); var g=g.width(),l=f.find(".fht-tbody").height()-b.scrollbarOffset,q,t,r,s;k.find("table.fht-table").addClass(b.originalTable.attr("class"));p.find("table.fht-table").addClass(b.originalTable.attr("class"));a.find("table.fht-table").addClass(b.originalTable.attr("
 class"));q=f.find(".fht-thead thead tr > *:lt("+b.fixedColumns+")");r=b.fixedColumns*e.border;q.each(function(){r+=c(this).outerWidth(!0)});h._fixHeightWithCss(q,e);h._fixWidthWithCss(q,e);var m=[];q.each(function(){m.push(c(this).width())}); t=f.find("tbody tr > *:not(:nth-child(n+"+(b.fixedColumns+1)+"))").each(function(a){h._fixHeightWithCss(c(this),e);h._fixWidthWithCss(c(this),e,m[a%b.fixedColumns])});k.appendTo(d).find("tr").append(q.clone());p.appendTo(d).css({"margin-top":-1,height:l+e.border});t.each(function(a){0==a%b.fixedColumns&&(s=c("<tr></tr>").appendTo(p.find("tbody")),b.altClass&&c(this).parent().hasClass(b.altClass)&&s.addClass(b.altClass));c(this).clone().appendTo(s)});d.css({height:0,width:r});var n=d.find(".fht-tbody .fht-table").height()- d.find(".fht-tbody").height();d.find(".fht-tbody .fht-table").bind("mousewheel",function(a,d,b,e){if(0!=e)return a=parseInt(c(this).css("marginTop"),10)+(0<e?120:-120),0<a&&(a=0),a<-n&&(a=-n),c(this).css("marginTop",a),f.find(
 ".fht-tbody").scrollTop(-a).scroll(),!1});f.css({width:g});if(!0==b.footer||!0==b.cloneHeadToFoot)k=f.find(".fht-tfoot tr > *:lt("+b.fixedColumns+")"),h._fixHeightWithCss(k,e),a.appendTo(d).find("tr").append(k.clone()),d=a.find("table").innerWidth(),a.css({top:b.scrollbarOffset, width:d})},_setupTableFooter:function(a,d,e){d=a.closest(".fht-table-wrapper");var g=a.find("tfoot");a=d.find("div.fht-tfoot");a.length||(a=0<b.fixedColumns?c('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo(d.find(".fht-fixed-body")):c('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo(d));a.find("table.fht-table").addClass(b.originalTable.attr("class"));switch(!0){case !g.length&&!0==b.cloneHeadToFoot&&!0==b.footer:e=d.find("div.fht-thead");a.empty(); e.find("table").clone().appendTo(a);break;case g.length&&!1==b.cloneHeadToFoot&&!0==b.footer:a.find("table").append(g).css({"margin-top":-e.border}),h._setupClone(a,e.tfoot)}},_getTableProps:function(a){var d=
 {thead:{},tbody:{},tfoot:{},border:0},c=1;!0==b.borderCollapse&&(c=2);d.border=(a.find("th:first-child").outerWidth()-a.find("th:first-child").innerWidth())/c;d.thead=h._getColumnsWidth(a.find("thead tr"));d.tfoot=h._getColumnsWidth(a.find("tfoot tr"));d.tbody=h._getColumnsWidth(a.find("tbody tr")); return d},_getColumnsWidth:function(a){var d={},b={},g=0,f,k;f=h._getColumnsCount(a);for(k=0;k<f;k++)b[k]={rowspan:1,colspan:1};a.each(function(a){var l=0,k=0;c(this).children().each(function(a){for(var f=parseInt(c(this).attr("colspan"))||1,h=parseInt(c(this).attr("rowspan"))||1;1<b[a+k].rowspan;)b[a+k].rowspan--,k+=b[a].colspan;a+=l+k;l+=f-1;1<h&&(b[a]={rowspan:h,colspan:f});if("undefined"===typeof d[a]||1!=d[a].colspan)d[a]={width:c(this).width()+parseInt(c(this).css("border-left-width"))+parseInt(c(this).css("border-right-width")), colspan:f},1==f&&g++});if(g==f)return!1});return d},_getColumnsCount:function(a){var b=0;a.each(function(a){var g;c(this).children().each(function(a){a=pa
 rseInt(c(this).attr("colspan"))||1;g=parseInt(c(this).attr("rowspan"))||1;b+=a});if(1<b||1==g)return!1});return b},_setupClone:function(a,d){var e=a.find("thead").length?"thead tr":a.find("tfoot").length?"tfoot tr":"tbody tr",g={},e=a.find(e);columnsCount=h._getColumnsCount(e);for(i=0;i<columnsCount;i++)g[i]={rowspan:1,colspan:1};e.each(function(a){var e= 0,h=0;c(this).children().each(function(a){for(var f=parseInt(c(this).attr("colspan"))||1,m=parseInt(c(this).attr("rowspan"))||1;1<g[a+h].rowspan;)g[a+h].rowspan--,h+=g[a].colspan;a+=e+h;e+=f-1;1<m&&(g[a]={rowspan:m,colspan:f});"undefined"!==typeof d[a]&&d[a].colspan==f&&((c(this).find("div.fht-cell").length?c(this).find("div.fht-cell"):c('<div class="fht-cell"></div>').appendTo(c(this))).css({width:parseInt(d[a].width,10)}),c(this).closest(".fht-tbody").length||!c(this).is(":last-child")||c(this).closest(".fht-fixed-column").length|| (a=Math.max((c(this).innerWidth()-c(this).width())/2,b.scrollbarOffset),c(this).css({"padding-right
 ":parseInt(c(this).css("padding-right"))+a+"px"})))})})},_isPaddingIncludedWithWidth:function(){var a=c('<table class="fht-table"><tr><td style="padding: 10px; font-size: 10px;">test</td></tr></table>'),d,e;a.addClass(b.originalTable.attr("class"));a.appendTo("body");d=a.find("td").height();a.find("td").css("height",a.find("tr").height());e=a.find("td").height();a.remove();return d!=e?!0:!1},_getScrollbarWidth:function(){var a= 0;if(!a)if(/msie/.test(navigator.userAgent.toLowerCase())){var b=c('<textarea cols="10" rows="2"></textarea>').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),e=c('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),a=b.width()-e.width()+2;b.add(e).remove()}else b=c("<div />").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1E3,left:-1E3}).prependTo("body").append("<div />").find("div").css({width:"100%", height:200}),a=100-b.width(),b.parent().re
 move();return a}};if(n[m])return n[m].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof m&&m)c.error('Method "'+m+'" does not exist in fixedHeaderTable plugin!');else return n.init.apply(this,arguments)}})(jQuery);

Added: grass/trunk/man/parser_standard_options.css
===================================================================
--- grass/trunk/man/parser_standard_options.css	                        (rev 0)
+++ grass/trunk/man/parser_standard_options.css	2015-09-19 04:17:08 UTC (rev 66263)
@@ -0,0 +1,172 @@
+/*!
+* jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
+*
+* Copyright (c) 2011 Mark Malek
+* http://fixedheadertable.com
+*
+* Licensed under MIT
+* http://www.opensource.org/licenses/mit-license.php
+*
+* http://docs.jquery.com/Plugins/Authoring
+* jQuery authoring guidelines
+*
+* Launch  : October 2009
+* Version : 1.3
+* Released: May 9th, 2011
+*
+*
+* all CSS sizing (width,height) is done in pixels (px)
+*/
+
+/* @group Reset */
+
+.fht-table,
+.fht-table thead,
+.fht-table tfoot,
+.fht-table tbody,
+.fht-table tr,
+.fht-table th,
+.fht-table td {
+        /* position */
+    margin: 0;
+
+    /* size */
+        padding: 0;
+
+        /* text */
+        font-size: 100%;
+        font: inherit;
+        vertical-align: top;
+        }
+
+.fht-table {
+        /* appearance */
+    border-collapse: collapse;
+    border-spacing: 0;
+        }
+
+/* @end */
+
+/* @group Content */
+
+.fht-table-wrapper,
+.fht-table-wrapper .fht-thead,
+.fht-table-wrapper .fht-tfoot,
+.fht-table-wrapper .fht-fixed-column .fht-tbody,
+.fht-table-wrapper .fht-fixed-body .fht-tbody,
+.fht-table-wrapper .fht-tbody {
+        /* appearance */
+        overflow: hidden;
+
+        /* position */
+        position: relative;
+        }
+
+        .fht-table-wrapper .fht-fixed-body .fht-tbody,
+        .fht-table-wrapper .fht-tbody {
+                /* appearance */
+            overflow: auto;
+                }
+
+                .fht-table-wrapper .fht-table .fht-cell {
+                        /* appearance */
+                        overflow: hidden;
+
+                        /* size */
+                    height: 1px;
+                        }
+
+        .fht-table-wrapper .fht-fixed-column,
+        .fht-table-wrapper .fht-fixed-body {
+            /* position */
+            top: 0;
+            left: 0;
+            position: absolute;
+            }
+
+        .fht-table-wrapper .fht-fixed-column {
+            /* position */
+            z-index: 1;
+            }
+
+/* @end */
+
+.scroolTable td, .scroolTable th {
+        /* appearance */
+        border: 1px solid #778899;
+
+        /* size */
+        padding: 5px;
+        }
+
+.scroolTable {
+        /* text */
+        font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+        }
+
+.scroolTable tbody tr td {
+        /* appearance */
+        background-color: rgb(100%, 100%, 100%);
+        background-image: -moz-linear-gradient(
+                top,
+                rgba(255,255,255,0.4) 0%,
+                rgba(255,255,255,0.2) 50%,
+                rgba(255,255,255,0.1) 51%,
+                rgba(255,255,255,0.0) 100%);
+
+        background-image: -webkit-gradient(
+                linear, left top, left bottom,
+                color-stop(0%,rgba(255,255,255,0.4)),
+                color-stop(50%,rgba(255,255,255,0.2)),
+                color-stop(51%,rgba(255,255,255,0.1)),
+                color-stop(100%,rgba(255,255,255,0.0)));
+
+        /* text */
+        color: #262c31;
+        font-size: 11px;
+        }
+
+.scroolTable tbody tr.odd td {
+        /* appearance */
+        background-color: #d6e0ef;
+        background-image: -moz-linear-gradient(
+                top,
+                rgba(255,255,255,0.4) 0%,
+                rgba(255,255,255,0.2) 50%,
+                rgba(255,255,255,0.1) 51%,
+                rgba(255,255,255,0.0) 100%);
+
+        background-image: -webkit-gradient(
+                linear, left top, left bottom,
+                color-stop(0%,rgba(255,255,255,0.4)),
+                color-stop(50%,rgba(255,255,255,0.2)),
+                color-stop(51%,rgba(255,255,255,0.1)),
+                color-stop(100%,rgba(255,255,255,0.0)));
+        }
+
+.scroolTable thead tr th,
+.scroolTable thead tr td,
+.scroolTable tfoot tr th,
+.scroolTable tfoot tr td {
+        /* appearance */
+        background-color: rgb(25%, 60%, 25%);
+        background-image: -moz-linear-gradient(
+                top,
+                rgba(255,255,255,0.4) 0%,
+                rgba(255,255,255,0.2) 50%,
+                rgba(255,255,255,0.1) 51%,
+                rgba(255,255,255,0.0) 100%);
+
+        background-image: -webkit-gradient(
+                linear, left top, left bottom,
+                color-stop(0%,rgba(255,255,255,0.4)),
+                color-stop(50%,rgba(255,255,255,0.2)),
+                color-stop(51%,rgba(255,255,255,0.1)),
+                color-stop(100%,rgba(255,255,255,0.0)));
+
+        /* text */
+        color: #121517;
+        font-size: 12px;
+        font-weight: bold;
+        text-shadow: 0 1px 1px #e8ebee;
+        }

Added: grass/trunk/man/parser_standard_options.js
===================================================================
--- grass/trunk/man/parser_standard_options.js	                        (rev 0)
+++ grass/trunk/man/parser_standard_options.js	2015-09-19 04:17:08 UTC (rev 66263)
@@ -0,0 +1,4 @@
+$(document).ready(function() {
+  $('#opts_table').fixedHeaderTable({footer: false, cloneHeadToFoot: true,
+                                     fixedColumn: true});
+});

Copied: grass/trunk/man/parser_standard_options.py (from rev 66260, grass/trunk/tools/parser_standard_options.py)
===================================================================
--- grass/trunk/man/parser_standard_options.py	                        (rev 0)
+++ grass/trunk/man/parser_standard_options.py	2015-09-19 04:17:08 UTC (rev 66263)
@@ -0,0 +1,177 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Jun 26 19:10:58 2015
+
+ at author: pietro
+"""
+from __future__ import print_function
+import argparse
+import sys
+from urllib import urlopen
+from build_html import *
+
+def parse_options(lines, startswith='Opt'):
+    def split_in_groups(lines):
+        def count_par_diff(line):
+            open_par = line.count('(')
+            close_par = line.count(')')
+            return open_par - close_par
+        res = None
+        diff = 0
+        for line in lines:
+            if line.startswith('case'):
+                optname = line.split()[1][:-1]
+                res = []
+#                if optname == 'G_OPT_R_BASENAME_INPUT':
+#                    import ipdb; ipdb.set_trace()
+            elif line == 'break;':
+                diff = 0
+                yield optname, res
+            elif line.startswith('G_'):
+                diff = count_par_diff(line)
+            elif diff > 0:
+                diff -= count_par_diff(line)
+            else:
+                res.append(line) if res is not None else None
+
+    def split_opt_line(line):
+        index = line.index('=')
+        key = line[:index].strip()
+        default = line[index + 1:].strip()
+        if default.startswith('_('):
+            default = default[2:]
+        return key, default
+
+    def parse_glines(glines):
+        res = {}
+        key = None
+        for line in glines:
+            if line.startswith('/*'):
+                continue
+            if line.startswith(startswith) and line.endswith(';'):
+                key, default = [w.strip() for w in split_opt_line(line[5:])]
+                res[key] = default
+            elif line.startswith(startswith):
+                key, default = split_opt_line(line[5:])
+                res[key] = [default, ]
+            else:
+                if key is not None:
+                    if key not in res:
+                        res[key] = []
+                    start, end = 0, -1
+                    if line.startswith('_('):
+                        start = 2
+                    if line.endswith(');'):
+                        end = -3
+                    elif line.endswith(';'):
+                        end = -2
+                    res[key].append(line[start:end])
+        # pprint(glines)
+        # pprint(res)
+        return res
+
+    def clean_value(val):
+        if isinstance(val, list):
+            val = ' '.join(val)
+        return (val.replace('"', '').replace("\'", "'").strip().strip(';')
+                ).strip().strip('_(').strip().strip(')').strip()
+
+    # with open(optionfile, mode='r') as optfile:
+    lines = [line.strip() for line in lines]
+    result = []
+    for optname, glines in split_in_groups(lines):
+        if glines:
+            res = parse_glines(glines)
+            if res:
+                for key, val in res.items():
+                    res[key] = clean_value(val)
+                result.append((optname, res))
+    return result
+
+
+class OptTable(object):
+    """"""
+    def __init__(self, list_of_dict):
+        self.options = list_of_dict
+        self.columns = sorted(set([key for _, d in self.options
+                                   for key in d.keys()]))
+
+    def csv(self, delimiter=';', endline='\n'):
+        """Return a CSV string with the options"""
+        csv = []
+        csv.append(delimiter.join(self.columns))
+        for optname, options in self.options:
+            opts = [options.get(col, '') for col in self.columns]
+            csv.append(delimiter.join([optname, ] + opts))
+        return endline.join(csv)
+
+    def html(self, endline='\n', indent='  ', toptions='border=1'):
+        """Return a HTML table with the options"""
+        html = ['<table{}>'.format(' ' + toptions if toptions else '')]
+        # write headers
+        html.append(indent + "<thead>")
+        html.append(indent + "<tr>")
+        html.append(indent * 2 + "<th>{0}</th>".format('option'))
+        for col in self.columns:
+            html.append(indent * 2 + "<th>{0}</th>".format(col))
+        html.append(indent + "</tr>")
+        html.append(indent + "</thead>")
+        html.append(indent + "<tbody>")
+        for optname, options in self.options:
+            html.append(indent + "<tr>")
+            html.append(indent * 2 + "<td>{0}</td>".format(optname))
+            for col in self.columns:
+                html.append(indent * 2 +
+                            "<td>{0}</td>".format(options.get(col, '')))
+            html.append(indent + "</tr>")
+        html.append(indent + "</tbody>")
+        html.append("</table>")
+        return endline.join(html)
+
+    def _repr_html_(self):
+        """Method used by IPython notebook"""
+        return self.html()
+
+
+if __name__ == "__main__":
+    URL = ('https://trac.osgeo.org/grass/browser/grass/'
+           'trunk/lib/gis/parser_standard_options.c?format=txt')
+    parser = argparse.ArgumentParser(description='Extract GRASS default '
+                                                 'options from link.')
+    parser.add_argument('-f', '--format', default='html', dest='format',
+                        choices=['html', 'csv', 'grass'],
+                        help='Define the output format')
+    parser.add_argument('-l', '--link', default=URL, dest='url', type=str,
+                        help='Provide the url with the file to parse')
+    parser.add_argument('-t', '--text', default='', dest='text',
+                        type=argparse.FileType('r'),
+                        help='Provide the file to parse')
+    parser.add_argument('-o', '--output', default=sys.stdout, dest='output',
+                        type=argparse.FileType('w'),
+                        help='Provide the url with the file to parse')
+    parser.add_argument('-s', '--starts-with', default='Opt',
+                        dest='startswith', type=str,
+                        help='Extract only the options that starts with this')
+    parser.add_argument('-p', '--html_params', default='border=1', type=str,
+                        dest='htmlparmas', help="Options for the HTML table")
+    args = parser.parse_args()
+
+    cfile = args.text if args.text else urlopen(args.url, proxies=None)
+
+    options = OptTable(parse_options(cfile.readlines(),
+                                     startswith=args.startswith))
+    outform = args.format
+    if outform in ['csv', 'html']:
+        print(getattr(options, outform)(), file=args.output)
+        args.output.close()
+    else:
+        year = os.getenv("VERSION_DATE")
+        name = args.output.name
+        args.output.close()
+        topicsfile = open(name, 'w')
+        topicsfile.write(header1_tmpl.substitute(title="GRASS GIS " \
+                        "%s Reference Manual: Parser standard options index" % grass_version))
+        topicsfile.write(headerpso_tmpl)
+        topicsfile.write(options.html(toptions=args.htmlparmas))
+        write_html_footer(topicsfile, "index.html", year)
+        topicsfile.close()

Deleted: grass/trunk/tools/parser_standard_options.py
===================================================================
--- grass/trunk/tools/parser_standard_options.py	2015-09-19 00:49:05 UTC (rev 66262)
+++ grass/trunk/tools/parser_standard_options.py	2015-09-19 04:17:08 UTC (rev 66263)
@@ -1,159 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Fri Jun 26 19:10:58 2015
-
- at author: pietro
-"""
-from __future__ import print_function
-import argparse
-from pprint import pprint
-import sys
-from urllib import urlopen
-
-
-def parse_options(lines, startswith='Opt'):
-    def split_in_groups(lines):
-        def count_par_diff(line):
-            open_par = line.count('(')
-            close_par = line.count(')')
-            return open_par - close_par
-        res = None
-        diff = 0
-        for line in lines:
-            if line.startswith('case'):
-                optname = line.split()[1][:-1]
-                res = []
-#                if optname == 'G_OPT_R_BASENAME_INPUT':
-#                    import ipdb; ipdb.set_trace()
-            elif line == 'break;':
-                diff = 0
-                yield optname, res
-            elif line.startswith('G_'):
-                diff = count_par_diff(line)
-            elif diff > 0:
-                diff -= count_par_diff(line)
-            else:
-                res.append(line) if res is not None else None
-
-    def split_opt_line(line):
-        index = line.index('=')
-        key = line[:index].strip()
-        default = line[index + 1:].strip()
-        if default.startswith('_('):
-            default = default[2:]
-        return key, default
-
-    def parse_glines(glines):
-        res = {}
-        key = None
-        for line in glines:
-            if line.startswith('/*'):
-                continue
-            if line.startswith(startswith) and line.endswith(';'):
-                key, default = [w.strip() for w in split_opt_line(line[5:])]
-                res[key] = default
-            elif line.startswith(startswith):
-                key, default = split_opt_line(line[5:])
-                res[key] = [default, ]
-            else:
-                if key is not None:
-                    if key not in res:
-                        res[key] = []
-                    start, end = 0, -1
-                    if line.startswith('_('):
-                        start = 2
-                    if line.endswith(');'):
-                        end = -3
-                    elif line.endswith(';'):
-                        end = -2
-                    res[key].append(line[start:end])
-        # pprint(glines)
-        # pprint(res)
-        return res
-
-    def clean_value(val):
-        if isinstance(val, list):
-            val = ' '.join(val)
-        return (val.replace('"', '').replace("\'", "'").strip().strip(';')
-                ).strip().strip('_(').strip().strip(')').strip()
-
-    # with open(optionfile, mode='r') as optfile:
-    lines = [line.strip() for line in lines]
-    result = []
-    for optname, glines in split_in_groups(lines):
-        if glines:
-            res = parse_glines(glines)
-            if res:
-                for key, val in res.items():
-                    res[key] = clean_value(val)
-                result.append((optname, res))
-    return result
-
-
-class OptTable(object):
-    """"""
-    def __init__(self, list_of_dict):
-        self.options = list_of_dict
-        self.columns = sorted(set([key for _, d in self.options
-                                   for key in d.keys()]))
-
-    def csv(self, delimiter=';', endline='\n'):
-        """Return a CSV string with the options"""
-        csv = []
-        csv.append(delimiter.join(self.columns))
-        for optname, options in self.options:
-            opts = [options.get(col, '') for col in self.columns]
-            csv.append(delimiter.join([optname, ] + opts))
-        return endline.join(csv)
-
-    def html(self, endline='\n', indent='  ', toptions='border=1'):
-        """Return a HTML table with the options"""
-        html = ["<table{}>".format(' ' + toptions if toptions else '')]
-        # write headers
-        html.append(indent + "<tr>")
-        html.append(indent * 2 + "<td>{0}</td>".format('option'))
-        for col in self.columns:
-            html.append(indent * 2 + "<td>{0}</td>".format(col))
-        html.append(indent + "</tr>")
-        for optname, options in self.options:
-            html.append(indent + "<tr>")
-            html.append(indent * 2 + "<td>{0}</td>".format(optname))
-            for col in self.columns:
-                html.append(indent * 2 +
-                            "<td>{0}</td>".format(options.get(col, '')))
-            html.append(indent + "</tr>")
-        html.append("</table>")
-        return endline.join(html)
-
-    def _repr_html_(self):
-        """Method used by IPython notebook"""
-        return self.html()
-
-
-if __name__ == "__main__":
-    URL = ('https://trac.osgeo.org/grass/browser/grass/'
-           'trunk/lib/gis/parser_standard_options.c?format=txt')
-    parser = argparse.ArgumentParser(description='Extract GRASS default '
-                                                 'options from link.')
-    parser.add_argument('-f', '--format', default='html', dest='format',
-                        choices=['html', 'csv'],
-                        help='Define the output format')
-    parser.add_argument('-l', '--link', default=URL, dest='url', type=str,
-                        help='Provide the url with the file to parse')
-    parser.add_argument('-t', '--text', default='', dest='text',
-                        type=argparse.FileType('r'),
-                        help='Provide the file to parse')
-    parser.add_argument('-o', '--output', default=sys.stdout, dest='output',
-                        type=argparse.FileType('w'),
-                        help='Provide the url with the file to parse')
-    parser.add_argument('-s', '--starts-with', default='Opt',
-                        dest='startswith', type=str,
-                        help='Extract only the options that starts with this')
-    args = parser.parse_args()
-
-    cfile = args.text if args.text else urlopen(args.url, proxies=None)
-
-    options = OptTable(parse_options(cfile.readlines(),
-                                     startswith=args.startswith))
-    print(getattr(options, args.format)(), file=args.output)
-    args.output.close()



More information about the grass-commit mailing list