Ejemplo n.º 1
0
Archivo: jobs.py Proyecto: exedre/e4t
def save_definition(options,formats,_dataset,outputs,_cfgs,extn,*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

    elem_class = parts[kind]
    fname = "%s.tex" % options.job

    defn = []
    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)
        if exists(ou):
            spec = cfg2hash(ou)
            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', ou)
            raise ValueError, "E:OUTPUTELEMENT:INIT:001"
        spec = mapspec(label,spec,_dataset,options, 
                       lambda k,v,name,spec,_dataset,options: 
                       (k, expandfuncs(v,name,spec,_dataset,options)))

        t = elem_class(label,spec,_dataset,options)
        xml = t.to_xml()
        defn.append( xml )
        xmls = dom.parseString(xml) # or xml.dom.minidom.parseString(xml_string)

        pp = Postprocessor(options=options)
        pp.output(False,xmls.toprettyxml(),'%s.xml'% options.job)
Ejemplo n.º 2
0
Archivo: jobs.py Proyecto: 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()