how to remove/delete file from 'ramdisks'?

Return to Scripting Issues

how to remove/delete file from 'ramdisks'?

Postby preusser » Sun Mar 11, 2012 5:04 am

Code: Select all
from panda3d.core import *
import direct.directbase.DirectStart
from direct.stdpy.file import open # Python's own "open" won't work with ramdisks

vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(VirtualFileMountRamdisk(), "/ramdisk", 0)

realfile = open("test.bin", "rb").read()

ramfile = open("/ramdisk/" + "test.bin", "wb")
ramfile.write(realfile)
ramfile.close()


Now how to delete "test.bin" in "/ramdisk"?
Last edited by preusser on Mon Mar 12, 2012 8:58 am, edited 1 time in total.
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am

Re: how to remove/delete file from 'ramdisks'?

Postby Revington » Sun Mar 11, 2012 10:37 pm

preusser wrote:
Code: Select all
from panda3d.core import

vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(VirtualFileMountRamdisk(), "/ramdisk", 0)

realfile = open("test.bin", "rb").read()

ramfile = open("/ramdisk/" + "test.bin", "wb")
ramfile.write(realfile)
ramfile.close()


Now how to delete "test.bin" in "/ramdisk"?


Should be:
vfs.deleteFile("/ramdisk/" + "test.bin")

HTH

Greetings
Revington
Revington
 
Posts: 22
Joined: Thu Nov 18, 2010 10:45 am

Postby preusser » Mon Mar 12, 2012 8:59 am

Thanks, but doesn't seem to work though:
Code: Select all
from panda3d.core import *
import direct.directbase.DirectStart
from direct.stdpy.file import open # Python's own "open" won't work with ramdisks

vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(VirtualFileMountRamdisk(), "/ramdisk", 0)


# a file
realfile = open("test.ogg", "rb").read()

ramfile = open("/ramdisk/a.ogg", "wb")
ramfile.write(realfile)
ramfile.close()

sound = loader.loadSfx("/ramdisk/a.ogg")
sound = None

vfs.deleteFile("/ramdisk/a.ogg")

# another file, but when I play I hear the same sound
realfile2 = open("test2.ogg", "rb").read()

ramfile2 = open("/ramdisk/a.ogg", "wb")
ramfile2.write(realfile2)
ramfile2.close()

sound2 = loader.loadSfx("/ramdisk/a.ogg")

sound2.play()

run()

?

EDIT:
Maybe I need to do this before loading another sound with the same name:
Code: Select all
base.sfxManagerList[0].uncacheSound("/ramdisk/a.ogg")


Can you guys confirm that this is right way to do it?
is there a need to do "vfs.deleteFile()" in this example?
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am

Postby preusser » Sat Mar 31, 2012 9:45 am

I am still not able to delete an audio file from ramdisk, then store and load another one from ramdisk which has the same name:

Code: Select all
from panda3d.core import *
# change default audio engine
loadPrcFileData('', 'audio-library-name p3openal_audio')
import direct.directbase.DirectStart
# Python's own "open" won't work with ramdisks
from direct.stdpy.file import open
# read and write files with RAM like with disk
vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(VirtualFileMountRamdisk(), '/ramdisk', 0)

# get a file to RAM
data = open('musicbox.ogg', 'rb').read() # actually read from another source
file = open('/ramdisk/music.ogg', 'wb')
file.write(data)
file.close()

# now load from RAM
music = loader.loadMusic('/ramdisk/music.ogg')
music.play()

def loadAnother():
   global music
   
   # remove existing from RAM
   music.stop()
   vfs.deleteFile('/ramdisk/music.ogg')
   base.musicManager.uncacheSound('/ramdisk/music.ogg')
   
   # get a file to RAM
   data = open('openclose.ogg', 'rb').read() # actually read from another source
   file = open('/ramdisk/music.ogg', 'wb')
   file.write(data)
   file.close()
   
   # now load from RAM, FAILS
   music = loader.loadMusic('/ramdisk/music.ogg')
   music.play()

base.accept('enter', loadAnother)

run()


Code: Select all
:movies:ffmpeg(warning): Codec not found
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am

Postby preusser » Fri Apr 20, 2012 10:29 am

Bump. Anyone?
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am

Postby drwr » Tue Apr 24, 2012 1:57 pm

Seems like that should work. I'm not 100% sure that the MusicManager.uncacheSound() function works as advertised, though; I've never used it before.

Why don't you try to isolate whether the problem you're experiencing is due to the use of the ramdisk or due to the use of the music manager caching behavior?

David
drwr
 
Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby preusser » Tue Apr 24, 2012 2:10 pm

You have a point.
Code: Select all
from panda3d.core import *
# change default audio engine
loadPrcFileData('', 'audio-library-name p3openal_audio')
import direct.directbase.DirectStart

import os
if os.path.isdir('ramdisk') == False: os.mkdir('ramdisk')

# get a file to -RAM- folder
data = open('musicbox.ogg', 'rb').read() # actually read from another source
file = open('ramdisk/music.ogg', 'wb')
file.write(data)
file.close()

# now load from -RAM- folder
music = loader.loadMusic('ramdisk/music.ogg')
music.play()

def loadAnother():
   global music
   
   # remove existing from -RAM- folder
   music.stop()
   base.musicManager.uncacheSound('ramdisk/music.ogg')
   
   # get a file to -RAM- folder
   data = open('openclose.ogg', 'rb').read() # actually read from another source
   file = open('ramdisk/music.ogg', 'wb')
   file.write(data)
   file.close()
   
   # now load from -RAM- folder, FAILS
   music = loader.loadMusic('ramdisk/music.ogg')
   music.play()

base.accept('enter', loadAnother)

run()


Code: Select all
:movies:ffmpeg(warning): Codec not found

uh...
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am

Postby preusser » Wed Apr 25, 2012 12:47 am

BTW, I also tried loader.unloadSfx() with the same result.
preusser
 
Posts: 516
Joined: Sun Mar 27, 2011 10:07 am


Return to Scripting Issues

Who is online

Users browsing this forum: wezu and 2 guests