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)
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()
def __call__(self,options,dataset,*configs, **kw): kw=udict(kw) needed(kw,'KIND') # Label baselabel = kw.xget('__LABEL') label = kw.xget('LABEL',baselabel) if label is None: raise E4tSystemError(options.job,'EDO:002 No LABEL in output config file') label = label.upper() # Kind kind = kw.xget('KIND').upper() # Frontend frontend_name = options.frontend # Layout layouts = kw.xget_list('LAYOUTS',options.frontend) tparts = Layout(*layouts) ext = tparts.getFrontend(options.frontend).base_ext ext = kw.xget('EXT',ext) setattr(options,'layout_obj',tparts) if ext not in tparts: raise E4tSystemError(options.job, 'EDO:003 No EXTension available: %s', ext) frontend = tparts[ext] if not frontend.manage(kind): raise E4tSystemError(options.job, "EDO:004 Frontend %s does not manage %s", ext,kind) elem_class = frontend.get(kind) fname = "%s.%s" % (options.job,ext) LOGGER.debug('elem_class %s -> %s',elem_class,fname) if exists(fname): os.unlink(fname) defn = [] if not configs: n = 0 label = baselabel spec= kw LOGGER.debug('no config %s |-> %s',label,configs) _accounting['cfgfile.%d.label' % n] = label _accounting['cfgfile.%d.output_with' % n] = str(elem_class) _layout(frontend,fname,elem_class,label,spec,dataset,options,kw) return for n,dr in enumerate(configs): LOGGER.debug("OUTPUT %s", dr) cfgfile = cfgfile_find(dr,options,__file__) proclist = [] if not cfgfile: LOGGER.error('{OUTPUTELEMENT}:E:INIT:001 -- Il file di configurazione %s non esiste', dr) continue _accounting['cfgfile.%d.filename' % n] = cfgfile spec = cfg2hash(dr) _accounting['cfgfile.%d.dict' % n] = spec setattr(options,'input_path',dirname(dr)) lcfg = spec.xget(label) if lcfg is None: LOGGER.error('No LABEL %s in %s',label,cfgfile) if 'macros' in kw: spec['macros']=kw['macros'] spec = mapspec(label,spec,dataset,options, lambda k,v,name,spec,dataset,options: (k, expandfuncs(v,name,spec,dataset,options))) _accounting['cfgfile.%d.label' % n] = label _accounting['cfgfile.%d.output_with' % n] = str(elem_class) t = elem_class(label,spec,dataset,options,**kw) if hasattr(t,'setup_elements'): t.setup_elements() if hasattr(t,'produce'): t.produce() ofile = _writeout(fname,frontend,options,t) outfiles.append(ofile) codecs.open('%s.ou' % label,'w').write(dictview(_accounting).encode('utf-8')) _accounting.clear()