Example #1
0
    def zaredi_danni( klas, args):
        ''' - прочита всички описи
            - при преводи, обикаля всички директории и запомня кои имат преводи
              - тези от тях които нямат описи, им се правят нови
            - за всички описи
              - ако нямат име, се слага от преводи ако има
              - самопопълва звук/година от името-на-директорията
              - добавя поисканите етикети
        '''
        options = klas.options

        #################
        #зареждане на данни, заявки, и пр. - четене/оправяне на ОПИСИте

        if options.prevodi:
            if options.podrobno: prn( 'prevodi:', options.prevodi)
            for k,(v,o) in prevodi_file2ime( eutf.readlines( options.prevodi)):
                klas._nov_prevod( fname= k, ime= zaglavie(v), original= zaglavie(o), roditel= options.prevodi)
                if options.podrobno: prn( '%-40s = %s' % (k,v) )

        if options.prevodi_meta:
            info.meta_prevodi.update( meta_prevodi( options.prevodi_meta, dict= dict_lower,
                        prn= options.podrobno and prn, zaglavie= 'мета-преводи', razdelitel_v_nachaloto=True
                        ))

        info.fenc = options.filename_enc or (eutf.e_utf_stdout() and 'utf-8' or locale.getpreferredencoding())
        if options.podrobno:
            prn( 'filename_enc:', info.fenc)
            prn( 'stdout.enc:', sys.stdout.encoding, sys.stdout)
            prn( 'stderr.enc:', sys.stderr.encoding, sys.stderr)

        etiketi = {}
        for e in options.etiket or ():
            klas.procheti_etiket( e, etiketi)

        options.dirs = []
        za_pravene = {}
        for path,dirs,files in klas.obikoli( args, klas.e_za_propuskane ):
            if options.prevodi:
                for dname in dirs:
                    pname = join( path, dname)
                    if not options.simvolni and os.path.islink( pname): continue
                    p = klas.vse_prevodi.get( dname)
                    if p:
                        rpname = realpath( pname)
                        za_pravene[ rpname] = p.ime, pname

            pname = realpath( path)
            for fname in files:
                if not e_opis( fname): continue
                i = klas( pname, redove= join( path, fname), origfname= path)
                if options.podrobno: prn( i.fname)
                if options.podrobno>1: prn( i.dump() )

        for path,dirs,files in klas.obikoli( options.papka_s_opisi or () ):
            pname = realpath( path)
            for fname in files:
                if klas.e_za_propuskane( fname): continue
                i = klas( join( pname, fname), redove= join( path, fname), origfname= join( path, fname), isdir=False)
                if options.podrobno: prn( i.fname)

        for pname,(ime,fpath) in za_pravene.items():
            if pname not in info.vse:
                i = klas( pname)
                i.slaga_ime( ime)

        for k,i in sorted( info.vse.items()):
            try:
                i.samopopylva_ot_fname()
                fname = basename( i.fname)
                p = klas.vse_prevodi.get( fname)
                if p:
                    if not i.imeto or options.popravi_opisi:
                        i.slaga_ime( p.ime)
                    if p.original and not i.etiketi.original:
                        i.slaga_etiket( i.stoinosti.original, p.original )

                i.etiketi.update_pre( **etiketi)
                i.samopopylva_etiketi()
                razlika, t = i.zapis( naistina= options.zapis_opisi )
                #if razlika: print '-----------'
            except:
                print( '????', fname)
                raise
Example #2
0
done
'''

import sys,os
from glob import glob
from os.path import join, split, isdir, realpath, exists, lexists, basename
from instr import meta_prevodi
from svd_util.lowercase import dict_lower
from svd_util import optz
optz.help( '%prog [опции] папка-изход  папки-входящи..')
optz.str( 'prevodi_meta',   help= 'файл-речник с преводи на понятия (lat=cyr) - хора..')
optz,args = optz.get()
out = args[0]
all = args[1:]

meta_prevodi = optz.prevodi_meta and meta_prevodi( optz.prevodi_meta, dict= dict_lower, nomer_stoinost=1) or {}

def ignored( f, org):
    if not isdir( f): return True
    if isdir( org): return False
    if glob( f+'/*.mp3'): return False
    return True

count = 0
for f in all:
    f = f.rstrip('/')
    rf = realpath( f)
    ro = realpath( out)
    common = os.path.commonprefix( [rf,ro])
    rf = rf[len(common):]
    ro = ro[len(common):]