Changeset 66517
- Timestamp:
- Oct 16, 2015, 8:44:52 AM (9 years ago)
- Location:
- grass-addons/tools/addons
- Files:
-
- 7 added
- 1 edited
- 1 moved
-
get_page_description.py (moved) (moved from grass-addons/tools/addons/get_page_description.sh ) (1 diff)
-
grass-addons-index.sh (modified) (1 diff)
-
test (added)
-
test/data (added)
-
test/data/g.broken.example.html (added)
-
test/data/r.group.page.html (added)
-
test/data/r.standard.example.html (added)
-
test/data/wxGUI.example.html (added)
-
test/test_description_extraction.sh (added)
Legend:
- Unmodified
- Added
- Removed
-
grass-addons/tools/addons/get_page_description.py
r66516 r66517 1 #!/ bin/sh1 #!/usr/bin/env python 2 2 3 3 # PURPOSE: Extracts page one line descriptions for index.html of GRASS GIS Addons 4 4 5 # AUTHORS: Martin Landa 5 # AUTHORS: Martin Landa (Bash version) 6 # Vaclav Petras (Python version) 6 7 7 if [ $# -ne 1 ]; then 8 echo "$(basename $0) takes exactly one argument (HTML manual page name)" 9 exit 1 10 fi 8 import os 9 import sys 10 import re 11 11 12 TMP=$$13 12 14 currfile=$1 13 def get_desc_from_manual_page_line(text): 14 """ 15 >>> get_desc_from_manual_page_line("r.example - This is a description<br>") 16 'This is a description' 17 """ 18 # this matches the dash at the beginning 19 text = text.split(" - ", 1)[1] 20 # this matches a tag at the end 21 # (supposing no tags in the description and < represented as < 22 text = text.split("<", 1)[0] 23 return text 15 24 16 grep 'KEYWORDS' $currfile 2> /dev/null > /dev/null 17 if [ $? -eq 0 ] ; then 18 # keywords found, so go ahead with extraction of one-line description 19 cat $currfile | awk '/NAME/,/KEYWORDS/' | grep ' - ' | cut -d'-' -f2- | cut -d'<' -f1 | sed 's+>$+></li>+g' >> /tmp/d.$TMP 20 # argh, fake keyword line found (broken manual page or missing g.parser usage) 21 if [ ! -s /tmp/d.$TMP ] ; then 22 echo "(incomplete manual page, please fix; name part not found)" > /tmp/d.$TMP 23 fi 24 cat /tmp/d.$TMP 25 rm -f /tmp/d.$TMP 26 else 27 # let's try to be more robust against missing keywords in a few HTML pages 28 # argh, no keywords found (broken manual page or missing g.parser usage) 29 echo "(incomplete manual page, please fix; keyword part not found)" 30 fi 25 26 def main(filename): 27 with open(filename) as page_file: 28 desc = None 29 in_desc_block = False 30 desc_block_start = re.compile(r'NAME') 31 desc_block_end = re.compile(r'KEYWORDS') 32 desc_line = re.compile(r' - ') 33 for line in page_file: 34 line = line.rstrip() # remove '\n' at end of line 35 if desc_block_start.search(line): 36 in_desc_block = True 37 elif desc_block_end.search(line): 38 in_desc_block = False 39 if in_desc_block: 40 if desc_line.search(line): 41 desc = get_desc_from_manual_page_line(line) 42 if not desc: 43 desc = "(incomplete manual page, please fix)" 44 # the original script attempted to add also </li> but it as not working 45 # now we leave up to the caller as well as whitespace around 46 print desc 47 48 49 if __name__ == "__main__": 50 if len(sys.argv) != 2: 51 sys.exit("{name} takes exactly one argument (HTML manual page name)." 52 " {argc} parameters were given." 53 .format(name=os.path.basename(sys.argv[0]), 54 argc=len(sys.argv) - 1)) 55 sys.exit(main(sys.argv[1])) -
grass-addons/tools/addons/grass-addons-index.sh
r66516 r66517 123 123 124 124 module=`echo $currfile | sed 's+\.html$++g'` 125 echo "<li style=\"margin-left: 20px\"><a href=\"$currfile\">$module</a>: " >> index.html126 ${SRC}grass-addons/tools/addons/get_page_description. sh$currfile >> index.html125 echo "<li style=\"margin-left: 20px\"><a href=\"$currfile\">$module</a>: " >> index.html 126 ${SRC}grass-addons/tools/addons/get_page_description.py $currfile >> index.html 127 127 done 128 128
Note:
See TracChangeset
for help on using the changeset viewer.
