diff --git a/setup.py b/setup.py index 66d0818..935a123 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,9 @@ setup( ], }, include_package_data = True, + data_files = [ + ( "vasl-templates", ["LICENSE.txt"] ), + ], entry_points = { "console_scripts": "vasl-templates = vasl_templates.main:main", } diff --git a/vasl_templates/webapp/main.py b/vasl_templates/webapp/main.py index 109e2ab..3f6e496 100644 --- a/vasl_templates/webapp/main.py +++ b/vasl_templates/webapp/main.py @@ -3,7 +3,7 @@ import os import json -from flask import request, render_template, jsonify, redirect, url_for +from flask import request, render_template, jsonify, send_file, redirect, url_for, abort from vasl_templates.webapp import app from vasl_templates.webapp.config.constants import DATA_DIR @@ -31,6 +31,35 @@ def show_help(): # --------------------------------------------------------------------- +@app.route( "/license" ) +def get_license(): + """Get the license.""" + + # locate the license file + dname = os.path.split( __file__ )[0] + fname = os.path.join( dname, "../../LICENSE.txt" ) # nb: if we're running from source + if not os.path.isfile( fname ): + fname = os.path.join( dname, "../../../LICENSE.txt" ) # nb: if we're running as a compiled binary + if not os.path.isfile( fname ): + # FUDGE! If we've been pip install'ed walk up the directory tree, looking for the license file :-/ + dname = os.path.split( fname )[0] + while True: + # go up a directory + prev_dname = dname + dname = os.path.split( dname )[0] + if dname == prev_dname: + break + # check if we can find the license file + fname = os.path.join( dname, "vasl-templates/LICENSE.txt" ) + if os.path.isfile( fname ): + break + if not os.path.isfile( fname ): + abort( 404 ) + + return send_file( fname, "text/plain" ) + +# --------------------------------------------------------------------- + default_scenario = None @app.route( "/default-scenario" ) diff --git a/vasl_templates/webapp/static/help/index.html b/vasl_templates/webapp/static/help/index.html index b8c290e..7bdd0b3 100644 --- a/vasl_templates/webapp/static/help/index.html +++ b/vasl_templates/webapp/static/help/index.html @@ -26,6 +26,7 @@
  • User Guide
  • Template packs
  • For developers +
  • License
    @@ -290,6 +291,14 @@ The script will compile the program, then package it all up with the necessary s
    + + +
    + +
    + +
    + diff --git a/vasl_templates/webapp/static/help/main.css b/vasl_templates/webapp/static/help/main.css index 1d221b2..0daa2ba 100644 --- a/vasl_templates/webapp/static/help/main.css +++ b/vasl_templates/webapp/static/help/main.css @@ -22,3 +22,7 @@ p { margin-top: 0.5em ; } #helptabs .ui-tabs-active a { color: #444 ; } #helptabs .ui-tabs-panel { padding: 0.5em 1em 0.5em 1em ; } + +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + +#helptabs-license .content { white-space: pre ; font-family: monospace ; } diff --git a/vasl_templates/webapp/static/help/main.js b/vasl_templates/webapp/static/help/main.js index 7886d6d..80a0cd9 100644 --- a/vasl_templates/webapp/static/help/main.js +++ b/vasl_templates/webapp/static/help/main.js @@ -33,9 +33,26 @@ $(document).ready( function() { $(this).wrap( "" ).imageZoom( $ ) ; } ) ; + // load the license + if ( window.parent.location.protocol !== "file:" ) { + var url = window.parent.location.protocol + "//" + window.parent.location.hostname ; + if ( window.parent.location.port ) + url += ":" + window.parent.location.port ; + url += "/license" ; + $.get( url, function(data) { + $( "#helptabs-license .content" ).text( data ) ; + } ).fail( function( xhr, status, errorMsg ) { + $( "#helptabs-license .content" ).text( "Couldn't get the license: " + errorMsg ) ; + } ) ; + } else { + $( "#helptabs li:contains('License')" ).hide() ; + $( "#helptabs-license" ).hide() ; + } + // initialize the tabs if ( getUrlParam( "embedded" ) ) { - $( "#helptabs li:eq(0)" ).remove() ; + // update the UI + $( "#helptabs li:contains('Installation')" ).remove() ; $( "#helptabs-installation" ).remove() ; } $("#loader").fadeOut( 500 ) ; diff --git a/vasl_templates/webapp/tests/test_help.py b/vasl_templates/webapp/tests/test_help.py index f78c1a0..b11239d 100644 --- a/vasl_templates/webapp/tests/test_help.py +++ b/vasl_templates/webapp/tests/test_help.py @@ -1,7 +1,7 @@ """ Test the help page. """ from vasl_templates.webapp.tests.utils import \ - init_webapp, select_menu_option, find_child, find_children + init_webapp, select_menu_option, find_child, find_children, wait_for, wait_for_elem # --------------------------------------------------------------------- @@ -23,9 +23,26 @@ def test_help( webapp, webdriver ): # show the help select_menu_option( "show_help" ) - webdriver.switch_to.frame( find_child( "#tabs-help iframe" ) ) - assert "everyone's favorite scenario" in webdriver.page_source - webdriver.switch_to.default_content() # make sure that the HELP tab is now visible assert "tabs-help" in get_tabs() + + # check what's in the help iframe + try: + + # switch to the frame + webdriver.switch_to.frame( find_child( "#tabs-help iframe" ) ) + + # check that the content loaded OK + assert "everyone's favorite scenario" in webdriver.page_source + + # check that the license loaded OK + elem = wait_for_elem( 2, "a.ui-tabs-anchor[href='#helptabs-license']" ) + assert elem.is_displayed() + wait_for( 2, lambda: "GNU AFFERO GENERAL PUBLIC LICENSE" in webdriver.page_source ) + assert "Version 3" in webdriver.page_source + + finally: + + # switch back to the main window + webdriver.switch_to.default_content()