Add argument --open to open the link in a browser

This uses the python package webbrowser[1] to open the generated
link, saving crucial seconds.

[1] https://docs.python.org/3/library/webbrowser.html

Change-Id: I2e8e43df297b3d609af365917fdca620a5cd6c2a
This commit is contained in:
Steve Baker 2020-07-15 14:13:48 +12:00
parent f6d619cac0
commit d11d1b0ae7

View File

@ -93,6 +93,8 @@ def get_options():
help='Directory to scan for template files')
parser.add_argument('--template-file', default=None,
help='Location of a specific template file')
parser.add_argument('--open', action='store_true',
help='Open the link in the default web browser')
return parser.parse_args()
@ -135,7 +137,7 @@ def get_configuration(dashboard):
return result
def generate_dashboard_urls(dashboards, template):
def generate_dashboard_urls(dashboards, template, open_browser=False):
"""Prints the dashboard URLs of a set of dashboards."""
result = 0
@ -155,7 +157,11 @@ def generate_dashboard_urls(dashboards, template):
'description': dashboard.get('dashboard', 'description') or None,
'configuration': get_configuration(dashboard)
}
print(template.render(variables))
url = template.render(variables)
print(url)
if open_browser:
import webbrowser
webbrowser.open(url)
return result
@ -200,7 +206,8 @@ def main():
try:
dashboards = load_dashboards(opts.dashboard_paths)
if not opts.check_only and template:
generate_dashboard_urls(dashboards, template)
generate_dashboard_urls(dashboards, template,
open_browser=opts.open)
elif not opts.check_only and not template:
return 1
except ValueError as e: