Changeset 66518
- Timestamp:
- Oct 16, 2015, 12:14:06 PM (9 years ago)
- Location:
- grass-addons/tools/addons
- Files:
-
- 4 edited
- 1 copied
-
get_page_description.py (modified) (2 diffs)
-
test/data/g.broken.example.html (modified) (1 diff)
-
test/data/g.no.keywords.html (copied) (copied from grass-addons/tools/addons/test/data/g.broken.example.html ) (1 diff)
-
test/data/wxGUI.example.html (modified) (1 diff)
-
test/test_description_extraction.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
grass-addons/tools/addons/get_page_description.py
r66517 r66518 24 24 25 25 26 def get_desc_from_comment_meta_line(text): 27 """ 28 >>> get_desc_from_comment_meta_line("<!-- meta page description: Abc abc-->") 29 'Abc abc' 30 """ 31 text = text.split("<!-- meta page description:", 1)[1] 32 text = text.split("-->", 1)[0] 33 return text.strip() 34 35 36 def get_desc_from_desc_text(text): 37 r"""Get description defined as first sentence in the given text. 38 39 Sentence is defined as text which ends with dot and space. 40 The string is expected to contain this. The other case not handled. 41 42 >>> get_desc_from_desc_text("Abc abc.abc abc.") 43 'Abc abc.abc abc.' 44 >>> get_desc_from_desc_text("Abc abc.abc abc. ") 45 'Abc abc.abc abc.' 46 >>> get_desc_from_desc_text("Abc abc.abc\n abc.\n") 47 'Abc abc.abc\n abc.' 48 """ 49 # this matches the sentence but gives also whole string even if it 50 # is not the sentence 51 text = re.split(r"\.(\s|$)", text, 1)[0] 52 # strip spaces at the beginning and add the tripped dot back 53 return text.lstrip() + '.' 54 55 26 56 def main(filename): 27 57 with open(filename) as page_file: 28 58 desc = None 29 59 in_desc_block = False 60 in_desc_section = False 61 desc_section = '' 62 desc_section_num_lines = 0 30 63 desc_block_start = re.compile(r'NAME') 31 desc_block_end = re.compile(r'KEYWORDS') 64 # the incomplete manual pages have NAME followed by DESCRIPTION 65 desc_block_end = re.compile(r'KEYWORDS|DESCRIPTION') 66 desc_section_start = re.compile(r'DESCRIPTION') 32 67 desc_line = re.compile(r' - ') 68 comment_meta_desc_line = re.compile(r'<!-- meta page description:.*-->') 33 69 for line in page_file: 34 70 line = line.rstrip() # remove '\n' at end of line … … 40 76 if desc_line.search(line): 41 77 desc = get_desc_from_manual_page_line(line) 78 # if there was nothing in the generated section of the page 79 # try find manually added meta comments which are placed 80 # at the beginning of the manually edited part of the page 81 if not desc and comment_meta_desc_line.search(line): 82 desc = get_desc_from_comment_meta_line(line) 83 # if there was nothing else, last thing to try is get the first 84 # sentence from the description section (which is also last 85 # item in the file from all things we are trying 86 if in_desc_section: 87 desc_section += line + "\n" 88 desc_section_num_lines += 1 89 if desc_section_num_lines > 4: 90 in_desc_section = False 91 if not desc and desc_section_start.search(line): 92 in_desc_section = True 93 if not desc and desc_section: 94 desc = get_desc_from_desc_text(desc_section) 42 95 if not desc: 43 96 desc = "(incomplete manual page, please fix)" -
grass-addons/tools/addons/test/data/g.broken.example.html
r66517 r66518 14 14 <h2>DESCRIPTION</h2> 15 15 16 This is a test page which should beemulate a broken manual page.16 This is a test page which should emulate a broken manual page. 17 17 This can happen for example, when module cannot generate a proper 18 18 description (broken imports, not using parser, etc.). 19 20 19 21 20 <h2>SEE ALSO</h2> -
grass-addons/tools/addons/test/data/g.no.keywords.html
r66517 r66518 10 10 11 11 <h2>NAME</h2> 12 <em><b>r.broken.example</b></em> <h2>KEYWORDS</h2>12 <em><b>r.broken.example</b></em> 13 13 14 14 <h2>DESCRIPTION</h2> 15 15 16 This is a test page which should be emulate a broken manual page. 16 This is a test page which should emulate a broken manual page 17 without keywords section. 17 18 This can happen for example, when module cannot generate a proper 18 19 description (broken imports, not using parser, etc.). 19 20 21 - This line is supposed to look like description line but it is in a wrong place. 20 22 21 23 <h2>SEE ALSO</h2> -
grass-addons/tools/addons/test/data/wxGUI.example.html
r66517 r66518 15 15 <h2>DESCRIPTION</h2> 16 16 17 This is a test page which should be similar to awxGUI manual pages.17 This is a test page which should be similar to wxGUI manual pages. 18 18 19 19 -
grass-addons/tools/addons/test/test_description_extraction.sh
r66517 r66518 9 9 ../get_page_description.py data/wxGUI.example.html 10 10 ../get_page_description.py data/g.broken.example.html 11 ../get_page_description.py data/g.no.keywords.html
Note:
See TracChangeset
for help on using the changeset viewer.
