Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_dashboard(path):
"""Load a ``Dashboard`` from a Python definition.
:param str path: Path to a *.dashboard.py file that defines a variable,
``dashboard``.
:return: A ``Dashboard``
"""
module = imp.load_source("dashboard", path)
marker = object()
dashboard = getattr(module, 'dashboard', marker)
if dashboard is marker:
raise DashboardError(
"Dashboard definition {} does not define 'dashboard'".format(path))
return dashboard
def generate_dashboards(args):
"""Script for generating multiple dashboards at a time."""
parser = argparse.ArgumentParser(prog='generate-dashboards')
parser.add_argument(
'dashboards', metavar='DASHBOARD', type=os.path.abspath,
nargs='+', help='Path to dashboard definition',
)
opts = parser.parse_args(args)
try:
write_dashboards(opts.dashboards)
except DashboardError as e:
sys.stderr.write('ERROR: {}\n'.format(e))
return 1
return 0