예제 #1
0
    def zapis( klas, az, d =None, naistina =False ):
        d = d or az.danni()

        dd = dictOrder()
        def slozhi( k):
            v = getattr( d, k)
            if isinstance( v, str) and v.isdigit(): v = int(v)
            if v or v==0: dd[ az.stoinosti[k] ] = v

        slozhi( 'ime')
        slozhi( 'imena')

        for (obhvat, e_simvol), stoinosti in sorted( d.etiketi.items(), key= lambda kv: (kv[0][0],not kv[0][1]) ):
            if not stoinosti: continue
            if obhvat:
                r = dd.setdefault( az.stoinosti[ obhvat], dictOrder() )
            else: r = dd
            if e_simvol:
                r[ az.stoinosti.simvoli ] = ' '.join( sorted( stoinosti))
            else:
                for k,vv in stoinosti:
                    if k[0]=='_': continue      #_vytr
                    if not isinstance( vv, (tuple, list)): vv = [vv]
                    #vv = [ v.strip() if isinstance( v, str) else v for v in vv ]
                    vv = [ int(v) if isinstance( v, str) and v.strip().isdigit() else v
                            for v in vv ]
                    if len(vv)==1: vv = vv[0]
                    r[ k] = vv

        kv4prev = [ az.stoinosti.ime, az.stoinosti.simvoli ] + [ az.stoinosti.get( k,k) for k in az.Prevod._vytr_svoistva]
        def prev( p):
            r = [ (az.stoinosti.ime, p.ime) ]
            if p.etiketi:
                r += [ ( az.stoinosti.simvoli, ' '.join( sorted( p.etiketi))) ]
            r += [ #(az.stoinosti[k],v)
                    (k,v)
                    for k,v in sorted( p.items())
                    if k[0]!='_' and v and k not in kv4prev ]
            return ( p.fname, len(r) > 1 and dictOrder( r) or p.ime)
        def prevodi2zapis( pr):
            return dictOrder( prev(p) for p in pr)

        if d.prevodi:
            dd[ az.stoinosti.prevodi] = prevodi2zapis( d.prevodi)
        if d.grupi:
            gg = [ dict( (k,v) for k,v in {
                     az.stoinosti.grupa: g.kyso,
                     az.stoinosti.ime:   g.dop and klas.PFX_GRUPA_DOP + g.dop or g.ime != g.kyso and g.ime or '',
                     az.stoinosti.prevodi: prevodi2zapis( g.elementi)
                    }.items() if v )
                    for g in d.grupi ]
            dd[ az.stoinosti.grupi] = gg

        r = dump( dd)
        VIMtail = '# v' + 'im:ts=4:sw=4:expandtab:ft=yaml' #separated!
        if d.komentari:
            r += '\n'+'\n'.join( d.komentari)
            if d.komentari[-1].lstrip('# ').startswith('vim:'): VIMtail= None
        if VIMtail: r += '\n'+VIMtail
        return az._zapis( r, az.redove, naistina= naistina, ext= '.yaml')
예제 #2
0
 def prev( p):
     r = [ (az.stoinosti.ime, p.ime) ]
     if p.etiketi:
         r += [ ( az.stoinosti.simvoli, ' '.join( sorted( p.etiketi))) ]
     r += [ #(az.stoinosti[k],v)
             (k,v)
             for k,v in sorted( p.items())
             if k[0]!='_' and v and k not in kv4prev ]
     return ( p.fname, len(r) > 1 and dictOrder( r) or p.ime)
예제 #3
0
 def prevodi2zapis( pr):
     return dictOrder( prev(p) for p in pr)