-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9511da8
commit f99ed11
Showing
7 changed files
with
98 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,32 @@ | ||
import tmt | ||
from pathlib import Path | ||
|
||
from celery.result import AsyncResult | ||
from jinja2 import Environment, FileSystemLoader | ||
from tmt import Logger, Plan, Test | ||
|
||
templ_dir = Path(__file__).resolve().parent / 'templates' | ||
|
||
def generate_status_callback(r: AsyncResult, status_callback_url: str) -> str: # type: ignore [type-arg] | ||
""" | ||
This function generates the status callback for the HTML file | ||
:param r: AsyncResult object | ||
:param status_callback_url: URL for the status callback | ||
:return: | ||
""" | ||
if r.status == "PENDING": | ||
return (f'''<html> | ||
<head> | ||
<title>HTML File</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
Processing... Try this clicking this url in a few seconds: <a href="{status_callback_url}">{status_callback_url} | ||
</a> </body>''') | ||
else: | ||
return (f'''<html> | ||
<head> | ||
<title>HTML File</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
Status: {r.status}<br> | ||
The result is: <br>{r.result} | ||
</body>''') | ||
|
||
env = Environment(loader=FileSystemLoader(str(templ_dir)), autoescape=True) | ||
|
||
def generate_test_html_page(test: Test, logger: Logger) -> str: | ||
""" | ||
This function generates an HTML file with the input data for a test | ||
:param test: Test object | ||
:param logger: tmt.Logger instance | ||
:return: | ||
""" | ||
logger.print("Generating the HTML file...") | ||
full_url = test.web_link() | ||
# Adding the input data to the HTML file | ||
file_html = (f'''<html> | ||
<head> | ||
<title>HTML File</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
name: {test.name}<br> | ||
summary: {test.summary}<br> | ||
description: {test.description}<br> | ||
url: <a href=\"{full_url}\" target=\"_blank\">{full_url}</a><br> | ||
ref: {test.fmf_id.ref}<br> | ||
contact: {test.contact}<br> | ||
tag: {test.tag}<br> | ||
tier: {test.tier}<br> | ||
id: {test.id}<br> | ||
fmf-id:<br> | ||
<ul> | ||
<li>url: {test.fmf_id.url}</li> | ||
<li>path: {test.fmf_id.path.as_posix() if test.fmf_id.path is not None else None}</li> | ||
<li>name: {test.fmf_id.name}</li> | ||
<li>ref: {test.fmf_id.ref}</li> | ||
</ul> | ||
</body> | ||
</html>''') | ||
logger.print("HTML file generated successfully!", color="green") | ||
return file_html | ||
def render_template(template_name: str, **kwargs) -> str: | ||
template = env.get_template(template_name) | ||
return template.render(**kwargs) | ||
|
||
def generate_status_callback(r: AsyncResult, status_callback_url: str) -> str: | ||
data = { | ||
"status": r.status, | ||
"status_callback_url": status_callback_url, | ||
"result": r.result | ||
} | ||
return render_template("status_callback.html.j2", **data) | ||
|
||
def generate_plan_html_page(plan: Plan, logger: Logger) -> str: | ||
""" | ||
This function generates an HTML file with the input data for a plan | ||
:param plan: Plan object | ||
:param logger: tmt.Logger instance | ||
:return: | ||
""" | ||
def generate_html_page(obj: Test | Plan, logger: Logger) -> str: | ||
logger.print("Generating the HTML file...") | ||
full_url = plan.web_link() | ||
# Adding the input data to the HTML file | ||
file_html = (f'''<html> | ||
<head> | ||
<title>HTML File</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
name: {plan.name}<br> | ||
summary: {plan.summary}<br> | ||
description: {plan.description}<br> | ||
url: <a href=\"{full_url}\" target=\"_blank\">{full_url}</a><br> | ||
ref: {plan.fmf_id.ref}<br> | ||
contact: {plan.contact}<br> | ||
tag: {plan.tag}<br> | ||
tier: {plan.tier}<br> | ||
id: {plan.id}<br> | ||
fmf-id:<br> | ||
<ul> | ||
<li>url: {plan.fmf_id.url}</li> | ||
<li>path: {plan.fmf_id.path.as_posix() if plan.fmf_id.path is not None else None}</li> | ||
<li>name: {plan.fmf_id.name}</li> | ||
<li>ref: {plan.fmf_id.ref}</li> | ||
</ul> | ||
</body> | ||
</html>''') | ||
logger.print("HTML file generated successfully!", color="green") | ||
return file_html | ||
return render_template('testorplan.html.j2', testorplan=obj) | ||
|
||
|
||
def generate_testplan_html_page(test: tmt.Test, plan: tmt.Plan, logger: Logger) -> str: | ||
""" | ||
This function generates an HTML file with the input data for a test and a plan | ||
:param test: Test object | ||
:param plan: Plan object | ||
:param logger: tmt.Logger instance | ||
:return: | ||
""" | ||
def generate_testplan_html_page(test: Test, plan: Plan, logger: Logger) -> str: | ||
logger.print("Generating the HTML file...") | ||
full_url_test = test.web_link() | ||
full_url_plan = plan.web_link() | ||
# Adding the input data to the HTML file | ||
file_html = (f'''<html> | ||
<head> | ||
<title>HTML File</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
Test metadata<br> | ||
name: {test.name}<br> | ||
summary: {test.summary}<br> | ||
description: {test.description}<br> | ||
url: <a href=\"{full_url_test}\" target=\"_blank\">{full_url_test}</a><br> | ||
ref: {test.fmf_id.ref}<br> | ||
contact: {test.contact}<br> | ||
tag: {test.tag}<br> | ||
tier: {test.tier}<br> | ||
id: {test.id}<br> | ||
fmf-id:<br> | ||
<ul> | ||
<li>url: {test.fmf_id.url}</li> | ||
<li>path: {test.fmf_id.path.as_posix() if test.fmf_id.path is not None else None}</li> | ||
<li>name: {test.fmf_id.name}</li> | ||
<li>ref: {test.fmf_id.ref}</li> | ||
</ul> | ||
<br> | ||
Plan metadata<br> | ||
name: {plan.name}<br> | ||
summary: {plan.summary}<br> | ||
description: {plan.description}<br> | ||
url: <a href=\"{full_url_plan}\" target=\"_blank\">{full_url_plan}</a><br> | ||
ref: {plan.fmf_id.ref}<br> | ||
contact: {plan.contact}<br> | ||
tag: {plan.tag}<br> | ||
tier: {plan.tier}<br> | ||
id: {plan.id}<br> | ||
fmf-id:<br> | ||
<ul> | ||
<li>url: {plan.fmf_id.url}</li> | ||
<li>path: {plan.fmf_id.path.as_posix() if plan.fmf_id.path is not None else None}</li> | ||
<li>name: {plan.fmf_id.name}</li> | ||
<li>ref: {plan.fmf_id.ref}</li> | ||
</ul> | ||
</body> | ||
</html>''') | ||
logger.print("HTML file generated successfully!", color="green") | ||
return file_html | ||
|
||
return render_template('testandplan.html.j2', test=test, plan=plan) | ||
|
||
if __name__ == "__main__": | ||
print("This is not executable file!") | ||
print("This is not an executable file!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- _base.html.j2 --> | ||
<html> | ||
<head> | ||
<title>{{ title | default('HTML File') }}</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
{%- block content %}{% endblock %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends '_base.html.j2' %} | ||
{% set title = "Status" %} | ||
|
||
{% block content %} | ||
{% if status == "PENDING" %} | ||
Processing... Try this clicking this url in a few seconds: <a href="{{ status_callback_url }}">{{ status_callback_url }}</a> | ||
{%- elif status == "RETRYING" %} | ||
Task is retrying... Please wait for a few seconds and try again: <a href="{{ status_callback_url }}">{{ status_callback_url }}</a> | ||
{%- else %} | ||
Status: {{ status }}<br> | ||
The result is: <br>{{ result }} | ||
{%- endif %} | ||
{%- endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- test_and_plan.html.j2 --> | ||
{% extends '_base.html.j2' %} | ||
{% set title = "Test and Plan Information" %} | ||
|
||
{% block content %} | ||
<h1>Test Information</h1> | ||
<p>name: {{ test.name }}</p> | ||
<p>summary: {{ test.summary }}</p> | ||
<p>description: {{ test.description }}</p> | ||
<p>url: <a href="{{ test.web_link() }}" target="_blank">{{ test.web_link() }}</a></p> | ||
<p>ref: {{ test.fmf_id.ref }}</p> | ||
<p>contact: {{ test.contact }}</p> | ||
<p>tag: {{ test.tag }}</p> | ||
<p>tier: {{ test.tier }}</p> | ||
<p>id: {{ test.id }}</p> | ||
|
||
<h1>Plan Information</h1> | ||
<p>name: {{ plan.name }}</p> | ||
<p>summary: {{ plan.summary }}</p> | ||
<p>description: {{ plan.description }}</p> | ||
<p>url: <a href="{{ plan.web_link() }}" target="_blank">{{ plan.web_link() }}</a></p> | ||
<p>ref: {{ plan.fmf_id.ref }}</p> | ||
<p>contact: {{ plan.contact }}</p> | ||
<p>tag: {{ plan.tag }}</p> | ||
<p>tier: {{ plan.tier }}</p> | ||
<p>id: {{ plan.id }}</p> | ||
{%- endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- test_page.html.j2 --> | ||
{% extends '_base.html.j2' %} | ||
{% set title = testorplan.name %} | ||
|
||
{% block content %} | ||
<p>name: {{ testorplan.name }}</p> | ||
<p>summary: {{ testorplan.summary }}</p> | ||
<p>description: {{ testorplan.description }}</p> | ||
<p>url: <a href="{{ testorplan.web_link() }}" target="_blank">{{ testorplan.web_link() }}</a></p> | ||
<p>ref: {{ testorplan.fmf_id.ref }}</p> | ||
<p>contact: {{ testorplan.contact }}</p> | ||
<p>tag: {{ testorplan.tag }}</p> | ||
<p>tier: {{ testorplan.tier }}</p> | ||
<p>id: {{ testorplan.id }}</p> | ||
fmf-id:<br> | ||
<ul> | ||
<li>url: {{ testorplan.fmf_id.url }}</li> | ||
{%- if testorplan.fmf_id.path %} | ||
<li>path: {{ testorplan.fmf_id.path.as_posix() }}</li> | ||
{%- else %} | ||
<li>path: None</li> | ||
{%- endif %} | ||
</ul> | ||
{%- endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters