PEATDB/zodbtest.py
def testBlob():
    """write a file as binary data to blob and read back"""
    from ZODB.PersistentMapping import PersistentMapping
    import mimetypes
    from PILView import PILViewer

    DB = PDatabase(server='localhost',port=8090,
              username='farrell',
              password='123')


    def addfile(fname):
        myblob = Blob()
        b=myblob.open('w')
        o=open(fname)
        data = o.read()
        b.write(data)
        print b.name
        b.close()
        return myblob

    dirlist=os.listdir(os.getcwd())

    for f in dirlist:
        m = mimetypes.guess_type(f)[0]
        if m != None and 'image' in m:
            print f
            b=addfile(f)
            DB.add(f)
            DB.data[f]['testfile']=FileRecord(name=f,blob=b)
    DB.commit()
    for k in DB.data:
        if not DB.data[k].has_key('testfile'):
            continue
        rec = DB.data[k]['testfile']
        myblob = rec.blob
        f = myblob.open("r")
        print f.name

    #app = PILViewer(imgfile=f.name)
    #app.mainloop()
    DB.close()
    return
write a file as binary data to blob and read back
write a file as binary data to blob and read back
write a file as binary data to blob and read back
def testBlob():
    from ZODB.PersistentMapping import PersistentMapping
    import mimetypes
    from PILView import PILViewer
    DB = PDatabase(server='localhost',port=8090,
              username='farrell',
              password='123')
    def addfile(fname):
        myblob = Blob()
        b=myblob.open('w')
        o=open(fname)
        data = o.read()
        b.write(data)
        print b.name
        b.close()
        return myblob
    dirlist=os.listdir(os.getcwd())
    for f in dirlist:
        m = mimetypes.guess_type(f)[0]
        if m != None and 'image' in m:
            print f
            b=addfile(f)
            DB.add(f)
            DB.data[f]['testfile']=FileRecord(name=f,blob=b)
    DB.commit()
    for k in DB.data:
        if not DB.data[k].has_key('testfile'):
            continue
        rec = DB.data[k]['testfile']
        myblob = rec.blob
        f = myblob.open("r")
        print f.name
    DB.close()
    return
def testBlob ( ) : from ZODB . PersistentMapping import PersistentMapping import mimetypes from PILView import PILViewer DB = PDatabase ( server = 'localhost' , port = 8090 , username = 'farrell' , password = '123' ) def addfile ( fname ) : myblob = Blob ( ) b = myblob . open ( 'w' ) o = open ( fname ) data = o . read ( ) b . write ( data ) print b . name b . close ( ) return myblob dirlist = os . listdir ( os . getcwd ( ) ) for f in dirlist : m = mimetypes . guess_type ( f ) [ 0 ] if m != None and 'image' in m : print f b = addfile ( f ) DB . add ( f ) DB . data [ f ] [ 'testfile' ] = FileRecord ( name = f , blob = b ) DB . commit ( ) for k in DB . data : if not DB . data [ k ] . has_key ( 'testfile' ) : continue rec = DB . data [ k ] [ 'testfile' ] myblob = rec . blob f = myblob . open ( "r" ) print f . name DB . close ( ) return
write a file as binary data to blob and read back
write a file as binary data to blob and read back
"""write a file as binary data to blob and read back""" #app = PILViewer(imgfile=f.name) #app.mainloop()