Beispiel #1
0
def view_simhome(xtor, name):
    # check that the sim exists
    selected_file = request.query.selected

    try:
        executor = Manager.executor(xtor)
        fileloc = os.path.join(executor.homedir, name)
        job = Manager.get_job_by_fileloc(fileloc)
        if job is None:
            raise KeyError("No such job:", xtor, name)
    except:
        logging.info("Cannot find simulation", exc_info=True)
        abort(400, "Cannot find simulation.")

    job_status = job.status + (
        ("[%s]" % job.last_status) if job.status == 'ABORTED' else "")
    job_created = job.tscreated.strftime("%y/%m/%d %H:%M:%S")
    job_runtime = str(job.tsinstatus - job.tscreated)

    basic_url = "/admin/simhomes/%s/%s" % (xtor, name)
    repo_simoutput = repo_url(SIM, Manager.get_simid(xtor, name))

    def myurl(sel=selected_file):
        if sel is None:
            return basic_url
        else:
            return "%s?selected=%s" % (basic_url, sel)

    # create homedir file list
    files = []
    viewer_type = None
    for f in os.listdir(fileloc):
        fpath = os.path.join(fileloc, f)
        if os.path.isfile(fpath):
            files.append(f)
        if f == selected_file:
            if any(f.endswith(s) for s in ('.txt', '.ini')):
                viewer_type = 'text'
                with open(fpath, 'r') as fs:
                    viewer_content = fs.read()
            elif any(f.endswith(s) for s in ('.jpg', '.png')):
                viewer_type = 'image'
            elif f.endswith('.json'):
                viewer_type = 'text'
                with open(fpath, 'r') as fs:
                    unformatted = fs.read()
                    try:
                        viewer_content = json.dumps(json.loads(unformatted),
                                                    indent=4,
                                                    sort_keys=True)
                    except:
                        viewer_content = unformatted
            else:
                viewer_type = 'binary'
    files.sort()

    # return view
    refresh_page = job.state != 'PASSIVE'
    thispage = myurl()
    return locals()
Beispiel #2
0
def get_simfile(xtor, name, fname):
    try:
        executor = Manager.executor(xtor)
        fileloc = os.path.join(executor.homedir, name)
        return static_file(fname, root=fileloc)
    except:
        logging.info("Cannot find simulation", exc_info=True)
        abort(400, "Cannot find simulation.")
Beispiel #3
0
def create_simulation(nsdid, xtorname=None):
    '''
    Create a simulation in the project repository and start a job for it.
    nsdid - the id of the NSD for the new simulation
    Return the new sim object created.
    Raises ValueError if nsdid is not in database PR.SIM
    '''

    # Get the executor
    xtor = Manager.executor(xtorname)

    # create the simoutput object
    sim, url, simhome = create_simoutput(xtor, repo(), nsdid)

    logfile = create_logstatistics(simhome)

    # create the job
    Manager.create_job(xtor, url, simhome)
    return sim