Exporting Usage Manual

From GNU Radio
Revision as of 17:57, 31 May 2018 by 777arc (talk | contribs) (Created page with "One of the issues people raised with moving the non-block/function/class specific documentation from Doxygen to wiki is that people won't have a local copy of the Usage Manual...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

One of the issues people raised with moving the non-block/function/class specific documentation from Doxygen to wiki is that people won't have a local copy of the Usage Manual anymore. To solve this I put together a little script that exports a list of pages on this wiki to the raw source which looks almost exactly the same as the doxygen source. This script just has to be run a few times a year and then the resulting files committed to gnuradio git (the location of these files within the git repo has yet to be determined).

from selenium import webdriver from selenium.webdriver.common.keys import Keys

import time
import HTMLParser
import os

# Settings
pages_to_save = ['Polymorphic Types (PMTs)',
                 'Message Passing',
                 'QT GUI',
                 'Logging',
                 'Performance Counters',
                 'Tagged Stream Blocks',]

# make directory if it doesn't exist
directory_name = 'Usage Manaul'
if not os.path.exists(directory_name): # will be in the same location as this script
    os.makedirs(directory_name)
# set up web driver
driver = webdriver.Firefox(executable_path='/home/marc/Downloads/geckodriver')
for page_name in pages_to_save:
    driver.get("https://wiki.gnuradio.org/index.php/Special:Export")

    # fill in text box
    text_area = driver.find_element_by_xpath("//*[@name='pages']")
    text_area.send_keys(page_name)

    # uncheck "save as file" box
    check_box = driver.find_element_by_xpath("//*[@name='wpDownload']")
    check_box.click()

    # hit Export
    submit_button = driver.find_element_by_xpath("//*[@value='Export']")
    submit_button.click() 

    # get HTML of new page
    raw_html = driver.page_source
    start_index = raw_html.find('<page>')
    cropped_html = raw_html[start_index:]

    # save text to file
    h = HTMLParser.HTMLParser()
    cropped_html_text = h.unescape(cropped_html) # makes it so stuff like &gt shows up as a greater than sign
    file_name = "Usage Manual- " + page_name + ".txt"
    text_file = open(directory_name + '/' + file_name, "w")
    text_file.write(cropped_html_text)
    text_file.close()

driver.close()