示例#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
文件: jobs.py 项目: exedre/e4t
def save_latex(options,label,goutput):
    if isinstance(label,(list,tuple)):
        t = LaTeXJob(label)
    else:
        t = LaTeXJob((label,))
    latex = LaTeX(options)
    make_dir_of_file(goutput)
    latex.compile(goutput,t,multiple=1,notemp=True)
    logger.debug('output %s is in %s',label,goutput)
示例#3
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()