Exporting Usage Manual

From GNU Radio
Revision as of 22:30, 12 March 2019 by 777arc (talk | contribs)
Jump to: navigation, search

One of the issues people raised with moving the non-block/function/class specific documentation from Doxygen to this 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).

To use this script, you will have to download geckodriver and change the line that points to where it is located. After running it there should be a new directory called "Usage Manual" created in whatever directory you ran the script from, containing a bunch of text files.

1. Download latest version of geckodriver from here and extract it to a known location, then modify the line `driver = webdriver.Firefox(`... below

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 Manual'
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()