(job)
return json_data, script
Generates a script from a job.
Generates a script from a job.
Generates a script from a job .
def generate_script(job):
    """
    Generates a script from a job.
    """
    work_dir = job.path
    json_data = hjson.loads(job.json_text)

    # The base url to the site.
    url_base = f'{settings.PROTOCOL}://{settings.SITE_DOMAIN}{settings.HTTP_PORT}'

    # Extra context added to the script.
    runtime = dict(
        media_root=settings.MEDIA_ROOT,
        media_url=settings.MEDIA_URL,
        work_dir=work_dir, local_root=settings.LOCAL_ROOT,
        user_id=job.owner.id, user_email=job.owner.email,
        job_id=job.id, job_name=job.name,
        job_url=f'{url_base}{settings.MEDIA_URL}{job.get_url()}'.rstrip("/"),
        project_id=job.project.id, project_name=job.project.name,
        analyis_name=job.analysis.name,
        analysis_id=job.analysis.id,
        domain=settings.SITE_DOMAIN, protocol=settings.PROTOCOL,
    )

    # Add the runtime context to the data.
    json_data['runtime'] = runtime
    try:
        # Generate the script.
        template = Template(job.template)
    except Exception as exc:
        template = Template(f"Error loading script template : \n{exc}.")

    context = Context(json_data)
    script = template.render(context)

    return json_data, script
def generate_script ( job ) : work_dir = job . path json_data = hjson . loads ( job . json_text ) # The base url to the site. url_base = f'{settings.PROTOCOL}://{settings.SITE_DOMAIN}{settings.HTTP_PORT}' # Extra context added to the script. runtime = dict ( media_root = settings . MEDIA_ROOT , media_url = settings . MEDIA_URL , work_dir = work_dir , local_root = settings . LOCAL_ROOT , user_id = job . owner . id , user_email = job . owner . email , job_id = job . id , job_name = job . name , job_url = f'{url_base}{settings.MEDIA_URL}{job.get_url()}' . rstrip ( "/" ) , project_id = job . project . id , project_name = job . project . name , analyis_name = job . analysis . name , analysis_id = job . analysis . id , domain = settings . SITE_DOMAIN , protocol = settings . PROTOCOL , ) # Add the runtime context to the data. json_data [ 'runtime' ] = runtime try : # Generate the script. template = Template ( job . template ) except Exception as exc : template = Template ( f"Error loading script template : \n{exc}." ) context = Context ( json_data ) script = template . render ( context ) return json_data , script