示例#1
0
文件: jobs.py 项目: exedre/e4t
def output_dataset(options,_dataset,outputs,*args,**kw):
    kw = udict(kw)
    label = kw.xget('LABEL').upper()
    kind = kw.xget('KIND').upper()

    parts = udict({ 'page'    : LaTeXPage,
                    'addtotoc': LaTeXAddToToc,
                    'part'    : LaTeXPart,
                    'chapter' : LaTeXChapter,
                    'toc'     : LaTeXTOC,
                    'cover'   : LaTeXCover,
                    'empty'   : LaTeXEmpty,
                    'table'   : OutputTable,
                    'figure'  : OutputFigure,              
                    'dataset' : None,
                    'multiple' : OutputMultiple})

    if kind not in parts.keys():
        raise ValueError, "Document part %s not found" % kind

    fname = "%s.tex" % options.job

    for ou in outputs:
        if not exists(ou):
            ou = join(options.process_path,ou)
            if not exists(ou):
                logger.error('E01#001: Il file di specifica del processore %s non esiste',pr)
                raise ValueError, 'E:MKEL:001'
        wcfg = udict(cfg2hash(ou))
        lcfg = wcfg.xget(label)
        with Timer() as t:
            _output_element(options,label,ou,_dataset,parts[kind],fname,**kw)
        _accounting["OUT.TIME.%s"%ou] = t.msecs

    xfname = "%s.e4t" % options.job
    logger.debug('Write out %s',xfname)
    save_dict(xfname,_accounting,options.switch_debug)
    _accounting.clear()

    if 'OUTPUT' in kw:
        return

    # NON-OUTPUT ELEMENTS
    if parts[kind] is None:
        logger.error('Output error for %s',kind)
        return

    t = parts[kind](kw)
    l = LaTeX(options)
    if hasattr(t,'setup_elements'):
        t.setup_elements()
    if hasattr(t,'produce'):
        t.produce()

    ofile = fname
    f = open(ofile, 'w')
    f.write(l.layout(t,False))
    f.close()
    outfiles.append(ofile)
示例#2
0
文件: __init__.py 项目: exedre/e4t
def save_accounting(name):
    save_dict(name,_accounting)
    _accounting.clear()
示例#3
0
文件: jobs.py 项目: exedre/e4t
def tsload(options, datareq, dataset):
    """Load data from cache or external sources

    Args:
      datareq (string): datarequest file name
      dataset (DataSet): previous dataset if any

    Returns:
      A DataSet containing requested series or a missing field
      
    """
    # base dir for configuration files
    base = "."
    if datareq and exists(datareq):
        base = dirname(datareq)
    _accounting["load.base"] = base

    results = []

    ### Get cached results if any
    cache = options.cache
    if cache:
        _accounting["load.cache"] = True
        with Timer() as t:
            results = cache.load(datareq, inacc)

        _accounting["load.time.cache.load"] = t.msecs
        if results:
            _accounting["load.time.cache.len"] = len(results)

    only_options = True
    pickled = results

    if results is None:  # Non cached results...
        only_options = False

    if datareq:

        _accounting["load.request.profile"] = options.profile
        _accounting["load.request.dataset"] = ",".join(dataset.keys())
        _accounting["load.request.datareq"] = datareq
        _accounting["load.request.only_options"] = only_options

        with Timer() as t:
            tsQuery = TimeseriesRequestSet(
                datareq, profile=options.profile, dataset=dataset, options=options, only_options=only_options
            )
            res = tsQuery.execute()

            _a = tsQuery.report()
            if _a:
                _accounting.update(_a)

            results = res.results

        if hasattr(results, "missing"):
            if results.missing:
                _accounting["load.request.results.missing"] = ",".join(results.missing)

        _accounting["load.request.results"] = ",".join(results.keys())
        _accounting["load.time.query"] = t.msecs

        # Save cache
        if not only_options and results:
            with Timer() as t:
                ret = cache.save(datareq, results, inacc)
            _accounting["load.time.cache.save"] = t.msecs
            _accounting["load.time.cache.save.ret"] = ",".join(ret.keys())

    else:
        results = DataSet()

    if only_options:
        results = pickled

    if hasattr(results, "missing"):
        if results.missing:
            _accounting["load.missing"] = ",".join(results.missing)
            logger.warn("IS-MISSING-SERIES: %s", ",".join(results.missing))

    fname = "%s.load" % options.job
    logger.debug("CACHE save %s", fname)
    save_dict(fname, _accounting, options.switch_debug)
    return results
示例#4
0
文件: jobs.py 项目: exedre/e4t
def _output_element(options,name,specs,_dataset,elem_class,fname,**kw):
    """Crea il file tex per l'output del dataset a partire dal file conf"""

    _accounting['output.name'] = name
    _accounting['output.class'] = elem_class
    _accounting['output.datalen'] = len(_dataset) if _dataset else 0

    logger.debug('Esportazione documento %s con classe %s (Dlen=%s)',name,elem_class,_dataset)

    if elem_class is None:
        return

    ## Lettura del file di specifica
    #
    for spec in specs.split(','):
        if re.search('\.req$',spec):
            continue
        if not exists(spec):
            spec = join(options.process_path,spec)
            if not exists(spec):
                logger.error('E01#001: Il file di specifica dell\'elemento %s non esiste (%s)',name,spec)
                raise ValueError, 'E:MKEL:001'


        if exists(spec):
            spec = cfg2hash(spec)
            kw=udict(kw)
            if 'macros' in kw:
                spec['macros']=kw['macros']
        else:
            logger.error('{OUTPUTELEMENT}:E:INIT:001 -- Il file di configurazione %s non esiste', spec)
            raise ValueError, "E:OUTPUTELEMENT:INIT:001"
        try:
            spec = mapspec(name,spec,_dataset,options, 
                           lambda k,v,name,spec,_dataset,options: 
                           (k, expandfuncs(v,name,spec,_dataset,options)))
        except IndexError, exc:
            logger.error('{OUTPUTELEMENT}:E:MAPSPEC:001 -- non posso espandere le funzioni')
            raise
            


        # test = expandfuncs('%TEST()',name,spec,_dataset,options)
        with Timer() as T:
            t = elem_class(name,spec,_dataset,options)
        _accounting['output.time.setup']=T.msecs


        if hasattr(t,'produce'):
            with Timer() as T:
                t.produce()
            _accounting['output.time.produce']=T.msecs

        l = LaTeX(options)

        # if False and hasattr(options,'switch_components') and options.switch_components:
        #     try:
        #         output = join(options.output_path,fname.replace('.tex','.pdf'))
        #         logger.debug('Compilazione componente %s',fname)
        #         with Timer() as T:
        #             l.compile(name,t,fname=output)
        #         _accounting['output.time.latex.compile']=T.msecs
        #         _accounting['output.time.latex.output']=output
        #         outfiles.append(output)
        #     except IOError, exc:
        #         logger.error('Non posso scrivere il file %s',output)

        _accounting['output.outfile']=fname

        with Timer() as T:
            ofile = fname
            f = open(ofile, 'w')
            f.write(l.layout(t,False))
            f.close()
            outfiles.append(ofile)
        _accounting.update(l.report())
        _accounting['output.time.write.layout']=T.msecs

        if options.switch_debug:
            # Write the report file
            codecs.open("%s.rep"%name,'w','utf-8').write(t.report())

        fname = "%s.out" % name
        logger.debug('Write out %s',fname)
        save_dict(fname,_accounting,options.switch_debug)
        _accounting.clear()