Skip to content

Commit

Permalink
bugy#245 bugy#341: added html and html_iframe output types + fixed di…
Browse files Browse the repository at this point in the history
…sabling bash formatting
  • Loading branch information
bugy committed Feb 28, 2021
1 parent 7be6a2a commit 91eb7bb
Show file tree
Hide file tree
Showing 27 changed files with 535 additions and 67 deletions.
3 changes: 2 additions & 1 deletion samples/configs/destroy_world.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "destroy_world",
"script_path": "./samples/scripts/destroy_world.py",
"description": "This is a very dangerous script, please be careful when running. Don't forget your protective helmet.",
"requires_terminal": false
"requires_terminal": false,
"output_format": "text"
}
7 changes: 7 additions & 0 deletions samples/configs/ploty_html_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Ploty HTML output",
"script_path": "./samples/scripts/ploty_html_output.py",
"description": "A sample script which outputs html data from ploty",
"output_format": "html_iframe",
"group": "HTML"
}
7 changes: 7 additions & 0 deletions samples/configs/simple_html_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Simple HTML output",
"script_path": "./samples/scripts/html_output_test.py",
"description": "A sample script which outputs simple html data\nCredits: https://www.smashingmagazine.com/2009/08/designing-a-html-5-layout-from-scratch/",
"group": "HTML",
"output_format": "html"
}
214 changes: 214 additions & 0 deletions samples/scripts/html_output_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env python3

text = '''
<div style="clear: both;margin: 0 auto;width: 800px;color: #000305;">
<header id="banner" class="body" style="margin: 0 auto; padding: 2.5em 0 0 0;">
<h1 style="font-size: 3.571em; line-height: 1.2;">
<a href="https://www.smashingmagazine.com/">Smashing HTML5! <strong>HTML5 in the year <del>2022</del> <ins>2009</ins></strong></a>
</h1>
<nav style="background: #000305; font-size: 1.143em; height: 40px; line-height: 30px; margin: 3em auto 2em auto;
padding: 0; text-align: center; width: 800px; border-radius: 5px;">
<ul style="list-style: none; margin: 0 auto; width: 800px;list-style: outside disc;">
<li style="float: left; display: inline; line-height: 2.7em; margin: 0;background-color:#C74350; width: 80px;
color: #fff;border-top-left-radius: 5px;border-bottom-left-radius: 5px;" class="active" >
<a href="https://www.smashingmagazine.com/" style="outline: 0;color: #fff;">home</a>
</li>
<li style="outline: 0; float: left; display: inline; line-height: 2.7em; margin-left: 1em;">
<a style="color: #fff;" href="https://www.smashingmagazine.com/">portfolio</a>
</li>
<li style="outline: 0; float: left; display: inline; line-height: 2.7em; margin-left: 1em;color: #fff;">
<a style="color: #fff;" href="https://www.smashingmagazine.com/">blog</a>
</li>
<li style="outline: 0; float: left; display: inline; line-height: 2.7em; margin-left: 1em;color: #fff;">
<a style="color: #fff;" href="https://www.smashingmagazine.com/">contact</a>
</li>
</ul>
</nav>
</header><!-- /#banner -->
<aside id="featured" class="body" style="display: block;background: #fff;margin-bottom: 2em;padding: 20px;
width: 760px;border-radius: 10px;"><article style="display:block">
<figure style="display: block; float: right;border: 2px solid #eee;margin: 0.786em 2em 0 5em;">
<img width="248" src="https://europeandesign.s3.amazonaws.com/uploads/2014/02/smashing-1100x616.png" alt="Smashing Magazine" />
</figure>
<hgroup>
<h2 style="color: #C74451; font-size: 1.714em; margin-bottom: 0.333em;">Featured Article</h2>
<h3 style="font-size: 1.429em; margin-bottom: .5em;"><a href="https://www.smashingmagazine.com/">HTML5 in Smashing Magazine!</a></h3>
</hgroup>
<p>Discover how to use Graceful Degradation and Progressive Enhancement techniques to achieve an outstanding,
cross-browser <a href="http://dev.w3.org/html5/spec/Overview.html" rel="external">HTML5</a> and
<a href="http://www.w3.org/TR/css3-roadmap/" rel="external">CSS3</a> website today!
</p>
</article></aside><!-- /#featured -->
<section id="content" class="body" style="background: #fff; margin-bottom: 2em; overflow: hidden; padding: 20px 20px;
width: 760px; border-radius: 10px; -moz-border-radius: 10px;">
<ol id="posts-list" class="hfeed" style="list-style: none; margin: 1em 0 1.5em 1.5em;">
<li><article style="display:block" class="hentry">
<header style="">
<h2 class="entry-title" style="font-size: 1.5em">
<a style="color: #C74350" href="https://www.smashingmagazine.com/" rel="bookmark" title="Permalink to this POST TITLE">This be the title</a>
</h2>
</header>
<footer class="post-info">
<abbr class="published" title="2005-10-10T14:07:00-07:00"><!-- YYYYMMDDThh:mm:ss+ZZZZ -->
10th October 2005
</abbr>
<address class="vcard author">
By <a class="url fn" href="https://www.smashingmagazine.com/">Enrique Ramírez</a>
</address>
</footer><!-- /.post-info -->
<div class="entry-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque venenatis nunc vitae libero iaculis elementum. Nullam et justo <a href="https://www.smashingmagazine.com/">non sapien</a> dapibus blandit nec et leo. Ut ut malesuada tellus.</p>
</div><!-- /.entry-content -->
</article></li>
<li><article style="display:block" class="hentry">
...
</article></li>
<li><article style="display:block" class="hentry">
...
</article></li>
</ol><!-- /#posts-list -->
</section><!-- /#content -->
<section id="extras" class="body" style="margin: 0 auto 3em auto; overflow: hidden;">
<div class="blogroll" style="float: left; width: 615px;">
<h2 style="color: #C74350; font-size: 1.429em; margin-bottom: .25em; padding: 0 3px;">blogroll</h2>
<ul style="list-style: none; margin: 0;">
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none; padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Doctor</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none; padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Spec (working draft)</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Smashing Magazine</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">W3C</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wordpress</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wikipedia</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Doctor</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Spec (working draft)</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Smashing Magazine</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">W3C</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wordpress</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wikipedia</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Doctor</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">HTML5 Spec (working draft)</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Smashing Magazine</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">W3C</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wordpress</a>
</li>
<li style="float: left; margin: 0 20px 0 0; width: 185px;
border-bottom: 1px solid #fff;">
<a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="https://www.smashingmagazine.com/" rel="external">Wikipedia</a>
</li>
</ul>
</div><!-- /.blogroll -->
<div class="social" style="float: right; width: 175px;">
<h2 style="color: #C74350; font-size: 1.429em; margin-bottom: .25em; padding: 0 3px;">social</h2>
<ul style="list-style: none; margin: 0;">
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://delicious.com/enrique_ramirez" rel="me">delicious</a></li>
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://digg.com/users/enriqueramirez" rel="me">digg</a></li>
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://facebook.com/enrique.ramirez.velez" rel="me">facebook</a></li>
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://www.lastfm.es/user/enrique-ramirez" rel="me">last.fm</a></li>
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://website.com/feed/" rel="alternate">rss</a></li>
<li style="border-bottom: 1px solid #fff;"><a style="color: #444; display: block; border-bottom: 1px solid #F4E3E3; text-decoration: none;
padding: .3em .25em;" href="http://twitter.com/enrique_ramirez" rel="me">twitter</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
'''

print(text)
9 changes: 9 additions & 0 deletions samples/scripts/ploty_html_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3

import plotly.express as px

df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size='petal_length',
hover_data=['petal_width'])
html_output = fig.to_html()
print(html_output) # warning long output (3298755 characters)
7 changes: 2 additions & 5 deletions src/config/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re

from config.exceptions import InvalidConfigException
from model import script_config
from model.model_helper import InvalidFileException
from model.script_config import get_sorted_config
Expand Down Expand Up @@ -196,8 +197,7 @@ def _load_script_config(self, path, content_or_json_dict, user, parameter_values
path,
user.get_username(),
user.get_audit_name(),
pty_enabled_default=os_utils.is_pty_supported(),
ansi_enabled_default=os_utils.is_linux() or os_utils.is_mac())
pty_enabled_default=os_utils.is_pty_supported())

if parameter_values is not None:
config.set_all_param_values(parameter_values, skip_invalid_parameters)
Expand Down Expand Up @@ -225,6 +225,3 @@ def __init__(self, message):
super().__init__(message)


class InvalidConfigException(Exception):
def __init__(self, message):
super().__init__(message)
3 changes: 3 additions & 0 deletions src/config/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class InvalidConfigException(Exception):
def __init__(self, message):
super().__init__(message)
19 changes: 19 additions & 0 deletions src/migrations/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import execution.logging
from execution.logging import ExecutionLoggingService
from model import model_helper
from utils import file_utils
from utils.date_utils import sec_to_datetime, to_millis
from utils.string_utils import is_blank
Expand Down Expand Up @@ -261,6 +262,24 @@ def __migrate_output_files_parameters_substitution(context):
_write_json(conf_file, json_object, content)


# 1.16 -> 1.17 migration
@_migration('migrate_bash_formatting_to_output_format')
def __migrate_bash_formatting_to_output_format(context):
for (conf_file, json_object, content) in _load_runner_files(context.conf_folder):
if 'bash_formatting' not in json_object:
continue

if model_helper.read_bool_from_config('bash_formatting', json_object, default=True) is False:
output_format = 'text'
else:
output_format = 'terminal'

del json_object['bash_formatting']
json_object['output_format'] = output_format

_write_json(conf_file, json_object, content)


def _write_json(file_path, json_object, old_content):
space_matches = re.findall('^\s+', old_content, flags=re.MULTILINE)
if space_matches:
Expand Down
3 changes: 2 additions & 1 deletion src/model/external_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def config_to_external(config, id, external_id=None):
'name': config.name,
'description': config.description,
'schedulable': config.schedulable,
'parameters': parameters
'parameters': parameters,
'outputFormat': config.output_format
}


Expand Down
Loading

0 comments on commit 91eb7bb

Please sign in to comment.