def do_form(form): """Self-extracting archive post Args: form (flask.request.Form): what to import Returns: dict: data """ from sirepo import uri_router from sirepo import simulation_db import base64 import StringIO if not 'zip' in form: raise uri_router.NotFound('missing zip in form') data = read_zip(StringIO.StringIO(base64.decodestring(form['zip']))) data.models.simulation.folder = '/Import' return simulation_db.save_new_simulation(data)
def create_archive(sim_type, sim_id, filename): """Zip up the json file and its dependencies Args: sim_type (str): simulation type sim_id (str): simulation id filename (str): for file type Returns: py.path.Local: zip file name """ from pykern import pkio from sirepo import uri_router if not pkio.has_file_extension(filename, ('zip', 'html')): raise uri_router.NotFound( '{}: unknown file type; expecting html or zip', filename, ) want_zip = filename.endswith('zip') fp, data = _create_zip(sim_type, sim_id, want_python=want_zip) if want_zip: return fp, 'application/zip' return _create_html(fp, data)