コード例 #1
0
ファイル: populate_db.py プロジェクト: jkrueger1/McCode
def info(bin):
    # Insert new simulation
    sim_name = basename(bin)[:-1*len('.out')]
    sim_group = basename(dirname(bin))
    Group.objects.get_or_create(name=sim_group)
    full_sim_name = sim_group+'/'+sim_name
    sim = None
    if exist(Simulation, name=sim_name, simgroup=sim_group, displayname=sim_name):
        print 'Updating existing simulation: ' + sim_name
        sim = fetch(Simulation, name=sim_name)[0]
    else:
        # Create new simulation
        sim = Simulation(name=sim_name, simgroup=sim_group, displayname=sim_name)
        sim.save()

    # Delete old params
    print sim.id, sim_name

    # Get info from executable
    status, out = getstatusoutput('%s --info' % bin)
    if status != 0:
        raise RuntimeWarning('Could not get info from %s' % bin)
    lines = out.split('\n')

    # Extract types and defaults
    types    = dict(RE_types.findall(filter(lambda x: 'Parameters:' in x, lines)[0]))
    defaults = {}
    map(lambda s: defaults.update(dict([RE_default.match(s).groups()])),
        filter(lambda x: 'Param:' in x, lines))

    # Extract priority, unit information and description messages
    infos = read_params('%s.instr' % bin[:-1*len('.out')])

    # Insert param default
    convertfns = {'string' : lambda x: x,
                  'double' : float,
                  'int'    : int
                  }

    # Insert new params
    for param in sorted(types.keys()):
        if not exist(Param, sim_id=sim.id, name=param):
            print 'new param: ', param
            p = Param(sim=sim, name=param)
        else:
            p = fetch(Param, sim_id=sim.id, name=param)[0]

        if param.lower() in infos:
            priority, unit, msg = infos[param.lower()]
        else:
            priority = 100000
            unit = DEFAULT_UNIT
            msg  = DEFAULT_MSG

        p.priority = priority
        p.unit = unit
        p.msg = msg

        p.default_value = convertfns[types[param]](defaults[param])
        p.save()
コード例 #2
0
ファイル: populate_db.py プロジェクト: jkrueger1/McCode
def info(bin):
    # Insert new simulation
    sim_name = basename(bin)[:-1*len('.out')]
    sim_group = basename(dirname(bin))
    Group.objects.get_or_create(name=sim_group)
    sim_id = sim_group+'_'+sim_name
    sim = None

    if exist(Simulation, name=sim_id, simgroup=sim_group, displayname=sim_name):
        print 'Updating existing simulation: ' + sim_name
        sim = fetch(Simulation, name=sim_id)[0]
    else:
        print "Inserting new simulation: %s"%sim_name
        sim = Simulation(name=sim_id, simgroup=sim_group, displayname=sim_name,
                         params=build_params(bin))
        sim.save()
    print "db_id: %s\n sim_id: %s\n simulalation: %s "%(sim.id, sim_id, sim_name)