Exporting Usage Manual

From GNU Radio
Revision as of 22:39, 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 (I've had the best luck with v0.21)
  2. sudo pip install selenium HTMLParser
  3. Make sure the two versions match, see this table
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',
                 '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
# set up web driver
driver = webdriver.Firefox(executable_path='/home/marc/Downloads/geckodriver')
for page_name in pages_to_save:

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

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

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

    # 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")