Example #1
0
def app_python_source(simulation_type, simulation_id, model):
    data = simulation_db.read_simulation_json(simulation_type, sid=simulation_id)
    template = sirepo.template.import_module(data)
    return _as_attachment(
        flask.make_response(template.python_source_for_model(data, model)),
        'text/x-python',
        '{}.py'.format(data['models']['simulation']['name']),
    )
Example #2
0
def app_python_source(simulation_type, simulation_id, model):
    data = simulation_db.read_simulation_json(simulation_type, sid=simulation_id)
    template = sirepo.template.import_module(data)
    return _as_attachment(
        flask.make_response(template.python_source_for_model(data, model)),
        'text/x-python',
        '{}.py'.format(data['models']['simulation']['name']),
    )
Example #3
0
def api_pythonSource(simulation_type, simulation_id, model=None, report=None):
    import string
    data = simulation_db.read_simulation_json(simulation_type, sid=simulation_id)
    template = sirepo.template.import_module(data)
    sim_name = data.models.simulation.name.lower()
    report_rider = '' if report is None else '-' + report.lower()
    py_name = sim_name + report_rider
    py_name = re.sub(r'[\"&\'()+,/:<>?\[\]\\`{}|]', '', py_name)
    py_name = re.sub(r'\s', '-', py_name)
    return _as_attachment(
        flask.make_response(template.python_source_for_model(data, model)),
        'text/x-python',
        '{}.py'.format(py_name),
    )
Example #4
0
def _python(data):
    """Generate python in current directory

    Args:
        data (dict): simulation

    Returns:
        py.path.Local: file to append
    """
    import sirepo.template
    import copy

    template = sirepo.template.import_module(data)
    res = py.path.local('run.py')
    res.write(template.python_source_for_model(copy.deepcopy(data), None))
    return res
Example #5
0
def _python(data):
    """Generate python in current directory

    Args:
        data (dict): simulation

    Returns:
        py.path.Local: file to append
    """
    import sirepo.template
    import copy

    template = sirepo.template.import_module(data)
    res = py.path.local('run.py')
    res.write(template.python_source_for_model(copy.deepcopy(data), None))
    return res