def writeout_processor_file(elem,options=Options()): """Write Processor File :param elem: the processor specification :type elem: a filename or specification line :Example: e4t --request random://uniform/VAR~:2012-12-31~2012-01-01~D \ --processor FORMULA=J;J=VAR*100 """ if not elem: return _dict = udict() for i,e in enumerate(elem): if exists(e): _dict = cfg2hash(e) else: _d = udict({ 'kind':'processor', 'active':'yes' , 'name': 'BASIC', 'operations': 'FORMULA', }) _in=as_dict(e,";") _d.update(_in) if not _d.has_key('FORMULA'): _d['FORMULA']=','.join(sorted([ k for k in _in.keys() if k not in ('DROP',) ])) if len(_d['FORMULA'])==0: del _d['FORMULA'] job = 'PROC%d'%i _dict[job]=_d _dict['PROCESSOR']=udict({ 'processors': ','.join(sorted(_dict.keys()))}) return writeout_file(_dict,header='# processor file')
def writeout_joblist_file(elem,dname,pname,options=Options()): """Write a joblist file from a data-request and processor file :param elem: output specification :kind elem: string or filename :param dname: data-request file name :kind dname: filename :param pname: processor step file name :kind pname: filename if elem is none then set up only dataset (and processor, if any) steps in joblist. """ def _get_elem_kind(conf): if re.match('^T_',conf): return 'table' elif re.match('^F_',conf): return 'figure' return 'composite' print "E=",elem if not elem: # dataset _D = { 'REQ' : { 'active' : 'yes', 'kind' : 'figure', 'panels': 'A11', 'datareq': dname }, } _D['A11'] = { 'SERIES': 'OUTS' } ofile = writeout_file(_D,header='# output file',options=options) _d = { 'dataset': 'output.xls', 'kind': 'figure', 'output': ofile } if pname: _d['processor']=pname _dict={ 'BASE' : { 'jobs': 'JOBS' } , 'JOBS': { 'JOBS':'REQ', 'KIND': 'joblist' }, 'REQ' : _d } setattr(options,'load',True) return writeout_file(_dict,header='# joblist file',options=options) kind = 'figure' # Se esiste un output file _dict = {} for i,e in enumerate(elem): print i,e conf = None if is_dict(e): # l'output file deve essere generato dell'opzione stessa _d = udict(as_dict(e)) if not nested_dict(_d): # opzione semplice (es. series=A,B,C) # Aggiungo _D = { 'REQ' : { 'active' : 'yes', 'kind' : 'figure', 'panels': 'A11' }, } _D['A11'] = _d _d = _D label = 'REQ' _dict.update(_d) else: if ':' in e: if e.count(':')==2: (kind,label,conf) = e.split(':') elif e.count(':')==1: (label,conf) = e.split(':') kind = _get_elem_kind(conf) elif e.count(':')>2: raise ValueError, e if conf: _dict = cfg2hash(conf) options.process_path=dirname(conf) if conf is None: conf = e kind = _get_elem_kind(conf) m = re.search('[TFC]_([a-zA-Z0-9_]+)$',conf) if m: label = m.group(1) else: label = "ELEM" _d = { 'kind' : kind, 'label': label, 'output' : conf, } _dict[label]=_d oname = writeout_file(_dict,header='# output file',options=options) if 'OUT' in options.look: lookout(oname,'Configurazione di output',options=options) _d = udict({ 'dataset': 'output.xls' , 'kind': kind, 'output': '%s' % oname, }) if dname: _d['datareq']=dname if pname: _d['processor']=pname _dict={ 'BASE' : { 'jobs': 'JOBS' } , 'JOBS': { 'JOBS':label, 'KIND': 'joblist', 'files': 'sristat.sty' }, label : _d } return writeout_file(_dict,header='# joblist file',options=options)