예제 #1
0
    def convert( self, db, cdb ):
        c = db.curnew()
        c.first()

        while True:
            try:
                #print c.key(), c.val()
                cdb.add( c.key(), c.val() )
                self.index_file.write( c.key() )
                self.index_file.write( '\n' )
                c.next()
            except KeyError:
                break
예제 #2
0
파일: Util.py 프로젝트: pjz/TMDAng
def build_cdb(filename):
    """Build a cdb file from a text file."""
    import cdb
    try:
        cdbname = filename + '.cdb'
        tempfile.tempdir = os.path.dirname(filename)
        tmpname = os.path.split(tempfile.mktemp())[1]
        cdb = cdb.cdbmake(cdbname, cdbname + '.' + tmpname)
        for line in file_to_list(filename):
            key, value = (line.split() + [''])[:1]
            cdb.add(key.lower(), value)
        cdb.finish()
    except:
        return False
    return True
예제 #3
0
def build_cdb(filename):
    """Build a cdb file from a text file."""
    import cdb
    try:
        cdbname = filename + '.cdb'
        tempfile.tempdir = os.path.dirname(filename)
        tmpname = os.path.split(tempfile.mktemp())[1]
        cdb = cdb.cdbmake(cdbname, cdbname + '.' + tmpname)
        for line in file_to_list(filename):
            linef = line.split()
            key = linef[0].lower()
            try:
                value = linef[1]
            except IndexError:
                value = ''
            cdb.add(key, value)
        cdb.finish()
    except:
        return 0
    else:
        return 1