Esempio n. 1
0
def select_jobs_from_joblist(names,job_specfile,options,macros):
    jjobs = udict()
    order = list()
    jjspec = list()
    
    for name in names:
        
        name = name.upper()
        
        if name not in job_specfile:
            logger.warn('No job %s in specfile',name)
            continue
        
        jspec        = options.define_set.expand(job_specfile.xget_dict(name))
        
        #if options.switch_debug:
        #    logger.debug('[%s] on %s',name,dictview(jspec))
        
        needed(jspec,'JOBS','KIND')

        if not re.match('^joblist$',jspec.xget('KIND'),re.I):
            logger.warn('Section "%s" kind not JOBLIST (kind!=joblist)',name)
            continue

        jjspec.append(jspec)

        if 'DEFINES' in jspec:
            defname = jspec.xget('DEFINES')
            defines = job_specfile.xget_dict(defname)
            J_defines = options.define_set.expand(defines)
            J_defines.remove('__.*')
            options.define_set.update(J_defines)

        # Jobs management in joblist
        jobs         = jspec.xget_list('JOBS')
        only         = options.only if options.only else list()
        exclude      = options.exclude if options.exclude else list()

        excluding = jspec.xget_list('EXCLUDE')
        onlying = jspec.xget_list('ONLY')
        if excluding:
            exclude.extend(excluding)
        if onlying:
            only.extend(onlying)

        if only:
            jobs = only

        if exclude:
            for j in exclude:
                if j in only:
                    continue
                if j in jobs:
                    jobs.remove(j)

        # Take only existing jobs
        jobs = [ j for j in jobs if j in job_specfile ]
        
        # if options.switch_debug:
        #    logger.debug('From %s executing%s: %s' % (name," only" if options.only or options.exclude else "",','.join(jobs)))

        # Gestione della keyword --selectjobs
        # handle requests as --select 'kind=figure|table'
        for j in jobs:
            cfg = options.define_set.expand(job_specfile.xget_dict(j))
            kj = cfg.xget('KIND',None)
            
            if re.match('^joblist$',kj,re.I):
                knames = cfg.xget_list('JOBS')
                kjjobs,korder,kjjspec = select_jobs_from_joblist(knames,job_specfile,options,macros)
                jjobs.update(kjjobs)
                order.extend(korder)
                jjspec.extend(kjjspec)
                continue
            
            if macros:
                cfg['macros']=macros
                logger.debug('Adding MACROS to element (%s)',cfg['__LABEL'])
            bpass = True
            for k,v in options.selectjobs.items():
                if isinstance(v,list):
                    vk = v[0]
                    if not re.match(vk,cfg[k],re.I):
                        bpass = False
                        break
                else:
                    if k not in cfg:
                        bpass = False
                        break
            if bpass:
                if name not in jjobs:
                    jjobs[name]=[]
                jjobs[name].append((j,cfg))
                order.append(name)
    #--------
    return jjobs,order,jjspec
Esempio n. 2
0
File: LaTeX.py Progetto: exedre/e4t
 def __init__(self,spec,*args):
     udict.__init__(self)
     self.update(spec)
     needed(self,'TITLE')
Esempio n. 3
0
File: LaTeX.py Progetto: exedre/e4t
 def __init__(self,spec):
     udict.__init__(self)
     self.update(spec)
     needed(self,'PAGES')
Esempio n. 4
0
File: MAP.py Progetto: exedre/e4t
    def produce(self,f1):
        """Produci una mappa"""

        ### Non posso produrre una mappa se non è indicata
        ### un'immagine sottostante e se non ci sono 
        ### le BARMAPS
        needed(self._spec,'IMAGE','SERIES','ITERATOR')

        args = {}

        ### Gestione dello sfondo
        f1.hold(True)
        self.insert_background(f1)

        ### Gestione della LEGENDA
        #
        f1.hold(True)
#       if self._spec.has_key('MAPLEGEND'):
#           legend = self._spec['MAPLEGEND']
#           if self._genspec.has_key(legend):
#               leg_spec = udict(self._genspec[legend])
#               n = len(leg_spec)
#               a = plt.axes([.15,.77,.30,.015*n])
#               a.set_xticks([])
#               a.set_yticks([])
#               l = 0
#               for k,v in leg_spec.items():
#                   ## Escludi le chiavi che iniziano per _
#                   if k[0]=='_': continue
#                   a.text(.05,l*.3+.15,"%s=%s"%(k.capitalize(),v),fontsize=6)
#                   l += 1
#               f1.add_artist(a)
# #                           xticks=[], 
# #                           yticks=[])


        unplotted = []
        countries  = get_list(self._spec['ITERATOR'])
        series     = self._spec['SERIES']
        
        if len(countries)==0:
            err="L'elenco dei countries è vuoto"
            logger.error(err)
            raise ValueError, err
        
        _h = {}

        _s = explode_list(series,countries)
        _v = [ self[_n] if self.has_key(_n) else None for _n in _s ]
        _C = dict([ (_c,_m) for _c,_n,_m in zip(countries,_s,_v) if _m is not None ])
            # unplotted.extend( [ _n for _n,_m in zip(_s,_v) if _m is None ])


        def hist(a,val,displ,color):    
            Y   = displ
            X_m = val*0.0
            X_M = val
            a.hlines(Y,X_m,X_M,lw=4,color=color)

        def _mk_hist(f1,_k,_v1,_v0,label,m,M):
            xx = _Values[_k][0][0] 
            yy = _Values[_k][0][1]
            # M = 13 # max(g,i)*1.3
            a   = plt.axes([xx, yy, .10, .05])
            a.patch.set(color='white')
            a.patch.set_facecolor('#0000CD')
            a.patch.set_edgecolor('red')
            a.patch.set_alpha(0.7)
            plt.axis('off');plt.plot([0, 0],[0.1, .6],color='#0000CD',lw=.1)
            _fnt = 7
            F=-2.5
            a.set_xlim(xmin=F+m,xmax=M*8/7)
            a.set_ylim(ymin=0,ymax=1)
            l=F+(-.5 if min(_v0,_v1)<0 else .0)+(.2 if max(_v0,_v1)<10 else -.5) # take in account two figures numbers
            hist(a,_v0,.15,(.0,.0,.805))
            a.text(l,.05,str("%.1f"%_v0),fontsize=_fnt,color="#0000CD") # ,backgroundcolor='w')
            hist(a,_v1,.52,(.99,.2,.2)) 
            a.text(l,.40,str("%.1f"%_v1),fontsize=_fnt,color="#0000CD") #,backgroundcolor='w')
            a.text(l+1.0,.80,label,fontsize=10,color="#0000CD") #,backgroundcolor='w')
            a.set_xticks([])
            a.set_yticks([])
            f1.add_artist(a)
            
        M=0.0
        m=0.0
        for _k,_v in _C.items():
            _w = _v['DATA']
            _v0 = _w._data[-1]
            _v1 = _w._data[-2]
            M=max(M,_v0,_v1)
            m=min(m,_v0,_v1)

        for _k,_v in _C.items():
            _w = _v['DATA']
            _spec = udict(_v['SPEC'])
            try:
                label = _spec['label']
            except KeyError:
                label = _k
            _v0 = _w._data[-1]
            _v1 = _w._data[-2]
            _mk_hist(f1,_k,_v1,_v0,label,m,M)
        return unplotted
Esempio n. 5
0
def select_jobs_from_joblist(names, job_specfile, options, macros):
    """
    Select job in a joblist

    :param names: name to select
    :param job_specfile: specfile
    :param options: options
    :param macros: macros

    """

    jjobs = udict()
    order = list()
    jjspec = list()

    for name in names:
        name = name.upper()
        if name not in job_specfile:
            LOGGER.warn('No job %s in specfile', name)
            continue

        jspec = options.define_set.expand(job_specfile.xget_dict(name))

        # if OPTIONS.switch_debug:
        #    LOGGER.debug('[%s] on %s',name,dictview(jspec))

        needed(jspec, 'JOBS', 'KIND')

        kind = jspec.xget('KIND')
        if not re.match('^joblist$', kind, re.I):
            if not re.match('^table|figure|cover|page|empty|multiple$',
                            kind, re.I):
                LOGGER.warn('Section "%s" kind not JOBLIST (kind==%s)',
                            name, kind)
            continue

        jjspec.append(jspec)

        if 'DEFINES' in jspec:
            defname = jspec.xget('DEFINES')
            defines = job_specfile.xget_dict(defname)
            j_defines = options.define_set.expand(defines)
            j_defines.remove('__.*')
            options.define_set.update(j_defines)

        # Jobs management in joblist

        jobs = jspec.xget_list('JOBS')
        only = (options.only if options.only else list())
        exclude = (options.exclude if options.exclude else list())

        excluding = jspec.xget_list('EXCLUDE')
        onlying = jspec.xget_list('ONLY')
        if excluding:
            exclude.extend(excluding)
        if onlying:
            only.extend(onlying)

        if only:
            jobs = only

        if exclude:
            for j in exclude:
                if j in only:
                    continue
                if j in jobs:
                    jobs.remove(j)

        # Take only existing jobs

        jobs = [j for j in jobs if j in job_specfile]

        # if OPTIONS.switch_debug:
        #    LOGGER.debug('From %s executing%s: %s' %  \
        #         (name," only" if OPTIONS.only or OPTIONS.exclude \
        #         else "",','.join(jobs)))

        # Gestione della keyword --selectjobs
        # handle requests as --select 'kind = figure|table'

        macros_added = []
        for j in jobs:
            cfg = options.define_set.expand(job_specfile.xget_dict(j))

            if re.match('^joblist$', cfg.xget('KIND'), re.I):
                knames = cfg.xget_list('JOBS')
                (kjjobs, korder, kjjspec) = \
                    select_jobs_from_joblist((j, ), job_specfile,
                        options, macros)
                jjobs.update(kjjobs)
                order.extend(korder)
                jjspec.extend(kjjspec)
                continue

            if macros:
                cfg['macros'] = macros

                # LOGGER.debug('Adding MACROS to element (%s)',cfg['__LABEL'])

                macros_added.append(cfg['__LABEL'])

            bpass = True
            for (k, val) in options.selectjobs.items():
                if isinstance(val, list):
                    valk = val[0]
                    if not re.match(valk, cfg[k], re.I):
                        bpass = False
                        break
                else:
                    if k not in cfg:
                        bpass = False
                        break
            if bpass:
                if name not in jjobs:
                    jjobs[name] = []
                jjobs[name].append((j, cfg))
                order.append(name)

        if macros_added:
            ACCOUNTING['macros.added'] = ','.join(macros_added)

    # --------

    return (jjobs, order, jjspec)
Esempio n. 6
0
 def __init__(self,label,spec,dataset,options,**kw):
     FrontendElement.__init__(self,label,spec,dataset,options)
     needed(self,'PAGES')