Пример #1
0
def convert_luai(luai, outDir, outEncoding):
    '''提取一个Luai文件的内容
    luai:   luai文件的路径
    outDir: 输出的目录
    outEncoding:    字符串,输出文件的编码
    '''
    print 'converting: %s' % (luai, )
    luaiBaseName = os.path.basename(luai)
    luaiBaseName = os.path.splitext(luaiBaseName)[0]
    fo = codecs.open(luai, u"r", u"utf8")
    parser = LuaiParser(fo)
    header = parser.get_headerBlock()
    outName = make_outfile_name(header["obj"], luaiBaseName)
    outName = os.path.join(outDir, outName)
    outfo = codecs.open(outName, u'w', outEncoding)
    write_title(outfo)
    obj = header[u'obj']
    blk = parser.get_bodyBlock()
    while blk != None:
        if blk[u'type'] == u'function':
            write_function(obj, blk, outfo)
        elif blk[u'type'] == u'property':
            write_property(obj, blk, outfo)
        blk = parser.get_bodyBlock()
    fo.close()
    outfo.close()
Пример #2
0
def convert_luai(luai, outDir, outEncoding):
    '''提取一个Luai文件的内容
    luai:   luai文件的路径
    outDir: 输出的目录
    outEncoding:    字符串,输出文件的编码
    '''
    print 'converting: %s' % (luai, )
    luaiBaseName = os.path.basename(luai)
    luaiBaseName = os.path.splitext(luaiBaseName)[0];
    fo = codecs.open(luai, u"r", u"utf8")
    parser = LuaiParser(fo)
    header = parser.get_headerBlock()
    outName = make_outfile_name(header["obj"], luaiBaseName)
    outName = os.path.join(outDir, outName)
    outfo = codecs.open(outName, u'w', outEncoding)
    write_title(outfo)
    obj = header[u'obj']
    blk = parser.get_bodyBlock()
    while blk != None:
        if blk[u'type'] == u'function':
            write_function(obj, blk, outfo)
        elif blk[u'type'] == u'property':
            write_property(obj, blk, outfo)
        blk = parser.get_bodyBlock()
    fo.close()
    outfo.close()
Пример #3
0
def preprocess_luai(filename):
    global SEE_DB
    global GET_DB
    fileBaseName = os.path.basename(filename)
    fileBaseName = fileBaseName.split(u'.')[0]
    fo = open_utf8(filename)
    print fileBaseName
    luaip = LuaiParser(fo)
    blocks = []
    blocks.append(luaip.get_headerBlock())
    obj = blocks[0][u'obj']
    # file link
    if obj:
        SEE_DB[obj.encode(u'utf-8')] = u'index.html'
        chmIdxKey = obj
        chmIdx = [[], []]
    else:
        SEE_DB[fileBaseName.encode(u'utf-8')] = make_fileName(fileBaseName,\
                                    fileType=u'index')
        chmIdxKey = fileBaseName
        chmIdx = []
    
    block = luaip.get_bodyBlock()
    
    while block:
        blocks.append(block)
        link = make_linkFullName(fileBaseName, block[u'name'], \
                                 obj, block[u'type'])
        if obj:
            key = u'%s.%s' % (obj, block[u'name'])
            shortKey = block[u'name']
            if block[u'type'] == u'property':
                chmIdx[0].append((shortKey, link))
            else:
                chmIdx[1].append((shortKey, link))
        else:
            key = block[u'name']
            chmIdx.append((key, link))
        # print block
        SEE_DB[key.encode('utf-8')] = link
        
        
        # print CHM_IDX_DB[chmIdxKey.encode('utf-8')]
        if block[u'type'] in [u'enum', u'table']:
            GET_DB.insert(block)
        block = luaip.get_bodyBlock()
    CHM_IDX_DB[chmIdxKey.encode('utf-8')] = chmIdx
    fo.close()
Пример #4
0
def process_luai(filename):
    fileBaseName = os.path.basename(filename)
    fileBaseName = fileBaseName.split(u'.')[0]
    
    fo = open_utf8(filename)
    br = BlockResolver()
    luaip = LuaiParser(fo)
    blocks = []
    blocks.append(luaip.get_headerBlock())
    blocks[0] = br.resolve(blocks[0])
    obj = blocks[0][u'obj']
    block = luaip.get_bodyBlock()
    while block:
        block = br.resolve(block)
        blocks.append(block)
        block = luaip.get_bodyBlock()
    add_toc(fileBaseName, blocks[0])
    indexMaker = IndexMaker(fileBaseName, blocks)
    indexMaker.make_index(DST_DIR_GB2312, u'gb18030')
    cm = ContentMaker(fileBaseName, blocks)
    cm.make_content(DST_DIR_GB2312, u'gb18030')
    fo.close()
    
    fo = open_utf8(filename)
    br = BlockResolver()
    luaip = LuaiParser(fo)
    blocks = []
    blocks.append(luaip.get_headerBlock())
    blocks[0] = br.resolve(blocks[0])
    obj = blocks[0][u'obj']
    block = luaip.get_bodyBlock()
    while block:
        block = br.resolve(block)
        blocks.append(block)
        block = luaip.get_bodyBlock()
    indexMaker = IndexMaker(fileBaseName, blocks)
    indexMaker.make_index(DST_DIR_UTF8, u'utf_8')
    cm = ContentMaker(fileBaseName, blocks)
    cm.make_content(DST_DIR_UTF8, u'utf_8')
    fo.close()