how to remove/delete file from 'ramdisks'?


#1
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”?


#2

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

HTH

Greetings
Revington


#3

Thanks, but doesn’t seem to work though:

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:

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?


#4

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:

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()
:movies:ffmpeg(warning): Codec not found

#5

Bump. Anyone?


#6

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


#7

You have a point.

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()
:movies:ffmpeg(warning): Codec not found

uh…


#8

BTW, I also tried loader.unloadSfx() with the same result.