示例#1
0
文件: plot.py 项目: AndreaCensi/mcdp
def dp_repr_long_labeled(data):
    ndp = get_ndp(data)
    ndp = get_labelled_version(ndp)
    try:
        dp = ndp.get_dp()
    except DPSemanticError:
        logger.warn('Could not draw dp_graph_tree_compact_labeled_')
        return []
    res1 = ('txt', 'dp_repr_long_labeled', dp.repr_long())
    return [res1]
示例#2
0
文件: plot.py 项目: AndreaCensi/mcdp
def dp_graph_tree_compact_labeled_(data):
    ndp = get_ndp(data)
    ndp = get_labelled_version(ndp)
    try:
        dp = ndp.get_dp()
    except DPSemanticError:
        logger.warn('Could not draw dp_graph_tree_compact_labeled_')
        return []
    
    gg = dp_graph_tree(dp, compact=True)
    return return_formats2(gg, 'dp_graph_tree_compact_labeled')
示例#3
0
文件: plot.py 项目: AndreaCensi/mcdp
def do_plots(logger, model_name, plots, outdir, extra_params, 
             maindir, extra_dirs, use_cache):
    data = {}

    if '.mcdp' in model_name:
        model_name2 = model_name.replace('.mcdp', '')
        msg = 'Arguments should be model names, not file names.'
        msg += ' Interpreting %r as %r.' % (model_name, model_name2)
        logger.warn(msg)
        model_name = model_name2

    data['model_name'] = model_name

    if use_cache:
        cache_dir = os.path.join(outdir, '_cached/mcdp_plot_cache')
        logger.info('using cache %s' % cache_dir)
    else:
        cache_dir = None

    librarian = Librarian()
    for e in extra_dirs:
        librarian.find_libraries(e)

    library = librarian.get_library_by_dir(maindir)
    if cache_dir is not None:
        library.use_cache_dir(cache_dir)

    assert library.library_name is not None

    filename = model_name + '.mcdp'
    x = library._get_file_data(filename)
    data['s'] = x['data']
    data['filename'] = x['realpath']
    data['params'] = parse_params(extra_params)
    data['library'] = library

    d = dict(allplots)
    results = []
    for p in plots:    
        # print('plotting %r ' % p)
        try:
            if p in d:
                res = d[p](data)
            else:
                msg = 'Unknown plot.'
                raise_desc(ValueError, msg, plot=p, available=sorted(d.keys()))
        except CmdException as e:
            mcdp_dev_warning('Add better checks of error.')
            logger.error(e)
            continue
        except Exception as e:
            logger.error('While creating %r' % p)
            raise
        assert isinstance(res, list), res
        for r in res:
            assert isinstance(r, tuple), r
            mime, name, x = r
            assert isinstance(x, str), x
            ext = mime

            base = model_name + '-%s.%s' % (name, ext)

            out = os.path.join(outdir, base)
            logger.info('Writing to %s' % out)
            with open(out, 'w') as f:
                f.write(x)

            results.append(r)

    return results