def output_prefixdata_code(prefixdata, outfilename, module_prefix, varprefix, per_locale, chunks):
    """Output the per-prefix data in Python form to the given file """
    sorted_keys = sorted(prefixdata.keys())
    total_keys = len(sorted_keys)
    if chunks == -1:
        chunk_size = PREFIXDATA_CHUNK_SIZE
        total_chunks = int(math.ceil(total_keys / float(chunk_size)))
    else:
        chunk_size = int(math.ceil(total_keys / float(chunks)))
        total_chunks = chunks

    outdirname = os.path.dirname(outfilename)
    longest_prefix = 0
    for chunk_num in range(total_chunks):
        chunk_index = chunk_size * chunk_num
        chunk_keys = sorted_keys[chunk_index:chunk_index + chunk_size]
        chunk_data = {}
        for key in chunk_keys:
            chunk_data[key] = prefixdata[key]
        chunk_file = os.path.join(outdirname, 'data%d.py' % chunk_num)
        chunk_longest = output_prefixdata_chunk(
            chunk_data, chunk_file, module_prefix, per_locale)
        if chunk_longest > longest_prefix:
            longest_prefix = chunk_longest

    with open(outfilename, "w") as outfile:
        if per_locale:
            prnt(PREFIXDATA_LOCALE_FILE_PROLOG % {'module': module_prefix}, file=outfile)
        else:
            prnt(PREFIXDATA_FILE_PROLOG % {'module': module_prefix}, file=outfile)
        prnt(COPYRIGHT_NOTICE, file=outfile)
        prnt("%s_DATA = {}" % varprefix, file=outfile)
        for chunk_num in range(total_chunks):
            prnt("from .data%d import data" % chunk_num, file=outfile)
            prnt("%s_DATA.update(data)" % varprefix, file=outfile)
        prnt("del data", file=outfile)
        prnt("%s_LONGEST_PREFIX = %d" % (varprefix, longest_prefix), file=outfile)
def output_prefixdata_code ( prefixdata , outfilename , module_prefix , varprefix , per_locale , chunks ) : sorted_keys = sorted ( prefixdata . keys ( ) ) total_keys = len ( sorted_keys ) if chunks == - 1 : chunk_size = PREFIXDATA_CHUNK_SIZE total_chunks = int ( math . ceil ( total_keys / float ( chunk_size ) ) ) else : chunk_size = int ( math . ceil ( total_keys / float ( chunks ) ) ) total_chunks = chunks outdirname = os . path . dirname ( outfilename ) longest_prefix = 0 for chunk_num in range ( total_chunks ) : chunk_index = chunk_size * chunk_num chunk_keys = sorted_keys [ chunk_index : chunk_index + chunk_size ] chunk_data = { } for key in chunk_keys : chunk_data [ key ] = prefixdata [ key ] chunk_file = os . path . join ( outdirname , 'data%d.py' % chunk_num ) chunk_longest = output_prefixdata_chunk ( chunk_data , chunk_file , module_prefix , per_locale ) if chunk_longest > longest_prefix : longest_prefix = chunk_longest with open ( outfilename , "w" ) as outfile : if per_locale : prnt ( PREFIXDATA_LOCALE_FILE_PROLOG % { 'module' : module_prefix } , file = outfile ) else : prnt ( PREFIXDATA_FILE_PROLOG % { 'module' : module_prefix } , file = outfile ) prnt ( COPYRIGHT_NOTICE , file = outfile ) prnt ( "%s_DATA = {}" % varprefix , file = outfile ) for chunk_num in range ( total_chunks ) : prnt ( "from .data%d import data" % chunk_num , file = outfile ) prnt ( "%s_DATA.update(data)" % varprefix , file = outfile ) prnt ( "del data" , file = outfile ) prnt ( "%s_LONGEST_PREFIX = %d" % ( varprefix , longest_prefix ) , file = outfile )
Output the per-prefix data in Python form to the given file